Open Configure Window on First Run or from System Tray

- Trigger FRE if no config loaded. Open Configure Window automatically
- Else user can manually open config window from App on System Tray
This commit is contained in:
Debanjum Singh Solanky
2022-08-09 17:05:27 +03:00
parent a588a8e21f
commit 027da719aa
2 changed files with 25 additions and 14 deletions

View File

@@ -7,16 +7,12 @@ from src.processor.markdown.markdown_to_jsonl import markdown_to_jsonl
from src.processor.org_mode.org_to_jsonl import org_to_jsonl
from src.search_type import image_search, text_search
from src.utils.config import SearchType, SearchModels, ProcessorConfigModel, ConversationProcessorConfigModel
from src.utils.cli import cli
from src.utils import state
from src.utils.helpers import get_absolute_path
from src.utils.rawconfig import FullConfig
def configure_server(cmd_args):
# Load config from CLI
args = cli(cmd_args)
def configure_server(args):
# Stores the file path to the config file.
state.config_file = args.config_file

View File

@@ -13,6 +13,7 @@ from PyQt6.QtCore import Qt, QThread
from src.configure import configure_server
from src.router import router
from src.utils import constants
from src.utils.cli import cli
# Initialize the Application Server
@@ -22,14 +23,30 @@ app.include_router(router)
def run():
# Setup Application Server
host, port, socket = configure_server(sys.argv[1:])
# Setup GUI
# Setup Base GUI
gui = QtWidgets.QApplication([])
gui.setQuitOnLastWindowClosed(False)
tray = create_system_tray(gui)
window = ConfigureWindow()
tray = create_system_tray(gui, window)
tray.show()
# Load config from CLI
args = cli(sys.argv[1:])
# Trigger First Run Experience, if required
if args.config is None:
window.show()
gui.exec()
# Reload config after first run
args = cli(sys.argv[1:])
# Quit if app still not configured
if args.config is None:
print('Exiting as Khoj is not configured. Configure the application to use it.')
sys.exit(1)
# Setup Application Server
host, port, socket = configure_server(args)
# Start Application Server
server = ServerThread(app, host, port, socket)
@@ -37,8 +54,6 @@ def run():
gui.aboutToQuit.connect(server.terminate)
# Start the GUI
window.show()
tray.show()
gui.exec()
@@ -108,7 +123,7 @@ class ConfigureWindow(QtWidgets.QMainWindow):
self.config_window.layout().removeWidget(self.config_window.layout().itemAt(2).widget())
def create_system_tray(gui: QtWidgets.QApplication):
def create_system_tray(gui: QtWidgets.QApplication, window: QtWidgets.QMainWindow):
"""Create System Tray with Menu
Menu Actions should contain
1. option to open search page at localhost:8000/
@@ -126,7 +141,7 @@ def create_system_tray(gui: QtWidgets.QApplication):
menu = QtWidgets.QMenu()
menu_actions = [
('Search', lambda: webbrowser.open('http://localhost:8000/')),
('Configure', lambda: webbrowser.open('http://localhost:8000/config')),
('Configure', window.show),
('Quit', gui.quit),
]