Open the search, chat or config view in app from the system tray menu

This commit is contained in:
Debanjum Singh Solanky
2023-08-07 13:28:08 -07:00
parent cc36b87345
commit 9c494705a8
2 changed files with 13 additions and 8 deletions

View File

@@ -25,6 +25,7 @@ class MainWindow(QWebEngineView):
def __init__(self, url: str):
super(MainWindow, self).__init__()
self.base_url = url
# Initialize Configure Window
self.setWindowTitle("Khoj")
@@ -36,10 +37,17 @@ class MainWindow(QWebEngineView):
# Open Khoj Web App Root
self.webpage = QWebEnginePage()
self.setPage(self.webpage)
self.webpage.load(QUrl(url))
self.webpage.load(QUrl(self.base_url))
self.position_window()
def show_page(self, page: str = ""):
def load_page():
self.webpage.load(QUrl(f"{self.base_url}/{page}"))
self.show()
return load_page
def position_window(self):
"Position the window at center of X axis and near top on Y axis"
window_rectangle = self.geometry()

View File

@@ -1,11 +1,8 @@
# Standard Packages
import webbrowser
# External Packages
from PySide6 import QtGui, QtWidgets
# Internal Packages
from khoj.utils import constants, state
from khoj.utils import constants
from khoj.interface.desktop.main_window import MainWindow
@@ -25,9 +22,9 @@ def create_system_tray(gui: QtWidgets.QApplication, main_window: MainWindow):
# Create the menu and menu actions
menu = QtWidgets.QMenu()
menu_actions = [
("Search", lambda: webbrowser.open(f"http://{state.host}:{state.port}/")),
("Configure", lambda: webbrowser.open(f"http://{state.host}:{state.port}/config")),
("App", main_window.show),
("Search", main_window.show_page()),
("Chat", main_window.show_page("chat")),
("Configure", main_window.show_page("config")),
("Quit", gui.quit),
]