mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-02 21:19:12 +00:00
Render the web interface directly within the desktop app as a webview
This commit is contained in:
@@ -1,13 +1,11 @@
|
||||
# Standard Packages
|
||||
import webbrowser
|
||||
|
||||
# External Packages
|
||||
from PySide6 import QtGui, QtWidgets
|
||||
from PySide6.QtCore import Qt
|
||||
from PySide6 import QtGui
|
||||
from PySide6.QtCore import Qt, QThread, QUrl
|
||||
from PySide6.QtWebEngineWidgets import QWebEngineView
|
||||
from PySide6.QtWebEngineCore import QWebEnginePage
|
||||
|
||||
# Internal Packages
|
||||
from khoj.utils import constants
|
||||
from PySide6.QtCore import QThread
|
||||
|
||||
|
||||
class ServerThread(QThread):
|
||||
@@ -22,10 +20,10 @@ class ServerThread(QThread):
|
||||
self.start_server_func()
|
||||
|
||||
|
||||
class MainWindow(QtWidgets.QMainWindow):
|
||||
class MainWindow(QWebEngineView):
|
||||
"""Create Window to Navigate users to the web UI"""
|
||||
|
||||
def __init__(self, host: str, port: int):
|
||||
def __init__(self, url: str):
|
||||
super(MainWindow, self).__init__()
|
||||
|
||||
# Initialize Configure Window
|
||||
@@ -35,23 +33,11 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||
icon_path = constants.web_directory / "assets/icons/favicon-128x128.png"
|
||||
self.setWindowIcon(QtGui.QIcon(f"{icon_path.absolute()}"))
|
||||
|
||||
# Initialize Configure Window Layout
|
||||
self.wlayout = QtWidgets.QVBoxLayout()
|
||||
# Open Khoj Web App Root
|
||||
self.webpage = QWebEnginePage()
|
||||
self.setPage(self.webpage)
|
||||
self.webpage.load(QUrl(url))
|
||||
|
||||
# Add a Label that says "Khoj Configuration" to the Window
|
||||
self.wlayout.addWidget(QtWidgets.QLabel("Welcome to Khoj"))
|
||||
|
||||
# Add a Button to open the Web UI at http://host:port/config
|
||||
self.open_web_ui_button = QtWidgets.QPushButton("Open Web UI")
|
||||
self.open_web_ui_button.clicked.connect(lambda: webbrowser.open(f"http://{host}:{port}/config"))
|
||||
|
||||
self.wlayout.addWidget(self.open_web_ui_button)
|
||||
|
||||
# Set the central widget of the Window. Widget will expand
|
||||
# to take up all the space in the window by default.
|
||||
self.config_window = QtWidgets.QWidget()
|
||||
self.config_window.setLayout(self.wlayout)
|
||||
self.setCentralWidget(self.config_window)
|
||||
self.position_window()
|
||||
|
||||
def position_window(self):
|
||||
|
||||
@@ -81,8 +81,9 @@ def run():
|
||||
from khoj.interface.desktop.system_tray import create_system_tray
|
||||
|
||||
# Setup GUI
|
||||
url = f"http://{args.host}:{args.port}"
|
||||
gui = QtWidgets.QApplication([])
|
||||
main_window = MainWindow(args.host, args.port)
|
||||
main_window = MainWindow(url)
|
||||
|
||||
# System tray is only available on Windows, MacOS.
|
||||
# On Linux (Gnome) the System tray is not supported.
|
||||
@@ -98,7 +99,6 @@ def run():
|
||||
configure_routes(app)
|
||||
server = ServerThread(start_server_func=lambda: start_server(app, host=args.host, port=args.port))
|
||||
|
||||
url = f"http://{args.host}:{args.port}"
|
||||
logger.info(f"🌗 Khoj is running at {url}")
|
||||
try:
|
||||
startup_url = url if args.config else f"{url}/config"
|
||||
|
||||
Reference in New Issue
Block a user