mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-03 21:29:08 +00:00
- Previously the window could get hidden behind other app windows when user clicked configure from the system tray
42 lines
1.2 KiB
Python
42 lines
1.2 KiB
Python
# Standard Packages
|
|
import webbrowser
|
|
|
|
# External Packages
|
|
from PyQt6 import QtGui, QtWidgets
|
|
|
|
# Internal Packages
|
|
from src.utils import constants, state
|
|
|
|
|
|
def create_system_tray(gui: QtWidgets.QApplication, main_window: QtWidgets.QMainWindow):
|
|
"""Create System Tray with Menu. Menu contain options to
|
|
1. Open Search Page on the Web Interface
|
|
2. Open App Configuration Screen
|
|
3. Quit Application
|
|
"""
|
|
|
|
# Create the system tray with icon
|
|
icon_path = constants.web_directory / 'assets/icons/favicon-144x144.png'
|
|
icon = QtGui.QIcon(f'{icon_path.absolute()}')
|
|
tray = QtWidgets.QSystemTrayIcon(icon)
|
|
tray.setVisible(True)
|
|
|
|
# Create the menu and menu actions
|
|
menu = QtWidgets.QMenu()
|
|
menu_actions = [
|
|
('Search', lambda: webbrowser.open(f'http://{state.host}:{state.port}/')),
|
|
('Configure', main_window.show_on_top),
|
|
('Quit', gui.quit),
|
|
]
|
|
|
|
# Add the menu actions to the menu
|
|
for action_text, action_function in menu_actions:
|
|
menu_action = QtGui.QAction(action_text, menu)
|
|
menu_action.triggered.connect(action_function)
|
|
menu.addAction(menu_action)
|
|
|
|
# Add the menu to the system tray
|
|
tray.setContextMenu(menu)
|
|
|
|
return tray
|