From c2815c5d090570e89809b7fceeef3115827206e8 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Sat, 13 Aug 2022 00:26:41 +0300 Subject: [PATCH 1/2] Open Search from Khoj Configure Screen - Start evolving configure screen away from just being a configure screen - Update Window Title to just say Khoj - Allow Opening Web Interface to Search from Khoj configure screen - Rename "Start" Button to more accurate "Configure" - Disable Search button on first run and while configuring app --- src/interface/desktop/configure_screen.py | 26 +++++++++++++++-------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/interface/desktop/configure_screen.py b/src/interface/desktop/configure_screen.py index 30f78bf2..b39f2216 100644 --- a/src/interface/desktop/configure_screen.py +++ b/src/interface/desktop/configure_screen.py @@ -1,6 +1,7 @@ # Standard Packages from pathlib import Path from copy import deepcopy +import webbrowser # External Packages @@ -31,14 +32,16 @@ class ConfigureScreen(QtWidgets.QDialog): # Load config from existing config, if exists, else load from default config if resolve_absolute_path(self.config_file).exists(): + self.first_run = False self.current_config = yaml_utils.load_config_from_file(self.config_file) else: + self.first_run = True self.current_config = deepcopy(constants.default_config) self.new_config = self.current_config # Initialize Configure Window self.setWindowFlags(Qt.WindowType.WindowStaysOnTopHint) - self.setWindowTitle("Configure - Khoj") + self.setWindowTitle("Khoj") self.setFixedWidth(600) # Initialize Configure Window Layout @@ -118,9 +121,12 @@ class ConfigureScreen(QtWidgets.QDialog): action_bar = QtWidgets.QWidget() action_bar_layout = QtWidgets.QHBoxLayout(action_bar) - self.save_button = QtWidgets.QPushButton("Start", clicked=self.save_settings) + self.configure_button = QtWidgets.QPushButton("Configure", clicked=self.configure_app) + self.search_button = QtWidgets.QPushButton("Search", clicked=lambda: webbrowser.open('http://localhost:8000/')) + self.search_button.setEnabled(not self.first_run) - action_bar_layout.addWidget(self.save_button) + action_bar_layout.addWidget(self.configure_button) + action_bar_layout.addWidget(self.search_button) parent_layout.addWidget(action_bar) def get_default_config(self, search_type:SearchType=None, processor_type:ProcessorType=None): @@ -207,12 +213,12 @@ class ConfigureScreen(QtWidgets.QDialog): # Configure server with loaded config configure_server(args, required=True) - def save_settings(self): + def configure_app(self): "Save the new settings to khoj.yml. Reload app with updated settings" self.update_search_settings() self.update_processor_settings() if self.save_settings_to_file(): - # Setup thread + # Setup thread to load updated settings in background self.thread = QThread() self.settings_loader = SettingsLoader(self.load_updated_settings) self.settings_loader.moveToThread(self.thread) @@ -227,12 +233,14 @@ class ConfigureScreen(QtWidgets.QDialog): self.thread.start() # Disable Save Button - self.save_button.setEnabled(False) - self.save_button.setText("Saving...") + self.search_button.setEnabled(False) + self.configure_button.setEnabled(False) + self.configure_button.setText("Configuring...") # Reset UI - self.thread.finished.connect(lambda: self.save_button.setText("Start")) - self.thread.finished.connect(lambda: self.save_button.setEnabled(True)) + self.thread.finished.connect(lambda: self.configure_button.setText("Configure")) + self.thread.finished.connect(lambda: self.configure_button.setEnabled(True)) + self.thread.finished.connect(lambda: self.search_button.setEnabled(True)) class SettingsLoader(QObject): From 684f497abeae62731e4fc3112f20d1813121ca1c Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Sat, 13 Aug 2022 00:43:53 +0300 Subject: [PATCH 2/2] Handle no System Tray on Linux (Gnome) - What - On Linux - Show Configure Screen, even if not first run experience - Do no show system tray on Linux - Quit app on closing Configure Screen - On Windows, Mac - Show Configure screen only if first run experience - Show system tray always - Do not quit app on closing Configure Screen - Why - Configure screen is the only GUI element on Linux. So closing it should close the application - On Windows, Mac the system tray exists, so app should not be closed on closing configure screen --- src/main.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main.py b/src/main.py index 404e244c..435330da 100644 --- a/src/main.py +++ b/src/main.py @@ -1,4 +1,5 @@ # Standard Packages +from platform import system import signal import sys @@ -37,17 +38,23 @@ def run(): else: # Setup GUI gui = QtWidgets.QApplication([]) - gui.setQuitOnLastWindowClosed(False) configure_screen = ConfigureScreen(args.config_file) - tray = create_system_tray(gui, configure_screen) - tray.show() + + # System tray is only available on Windows, MacOS. + # On Linux (Gnome) the System tray is not supported. + # Since only the Configure Window is available + # Quitting it should quit the application + if system() in ['Windows', 'Darwin']: + gui.setQuitOnLastWindowClosed(False) + tray = create_system_tray(gui, configure_screen) + tray.show() # Setup Server configure_server(args, required=False) server = ServerThread(app, args.host, args.port, args.socket) - # Trigger First Run Experience, if required - if args.config is None: + # Show Configure Screen on Linux (etc.) or First Run Experience + if args.config is None or system() not in ['Windows', 'Darwin']: configure_screen.show() # Setup Signal Handlers