diff --git a/src/onedrive_gui/OneDriveGUI.py b/src/onedrive_gui/OneDriveGUI.py index 68b9b7f..d69eb1a 100644 --- a/src/onedrive_gui/OneDriveGUI.py +++ b/src/onedrive_gui/OneDriveGUI.py @@ -20,6 +20,10 @@ app = QApplication(sys.argv) app.setApplicationName("OneDriveGUI") app.setDesktopFileName("OneDriveGUI") app.setWindowIcon(QIcon(DIR_PATH + "/resources/images/icons8-cloud-80.png")) +# OneDriveGUI lives in the system tray: closing a dialog while the main window is +# hidden (e.g. the resync prompt with start_minimized) must not quit the app and +# destroy the still-running worker threads (#297). Quitting is explicit. +app.setQuitOnLastWindowClosed(False) from .options import gui_settings, global_config, version diff --git a/src/onedrive_gui/main_window.py b/src/onedrive_gui/main_window.py index 9bbfe1c..64e12c0 100644 --- a/src/onedrive_gui/main_window.py +++ b/src/onedrive_gui/main_window.py @@ -206,6 +206,10 @@ class MainWindow(QMainWindow, Ui_MainWindow): "tooltip_text": "", } + # Stop the clients and their worker threads before the application is torn + # down; destroying a QThread that is still running aborts the process. + QApplication.instance().aboutToQuit.connect(self.stop_all_workers) + self.refresh_process_status = QTimer() self.refresh_process_status.setSingleShot(False) self.refresh_process_status.timeout.connect(self.onedrive_process_status) @@ -288,19 +292,16 @@ class MainWindow(QMainWindow, Ui_MainWindow): if close_question == QMessageBox.Yes: logging.info("Quitting OneDriveGUI") - workers_to_stop = [] - - for worker in workers: - workers_to_stop.append(worker) - - for worker in workers_to_stop: - workers[worker].stop_worker() - - sys.exit() + self.stop_all_workers() + QApplication.instance().quit() elif close_question == QMessageBox.No: logging.info("[GUI] Keeping OneDriveGUI running.") + def stop_all_workers(self): + for profile_name in list(workers): + workers[profile_name].stop_worker() + def stop_onedrive_monitor(self, profile_name): if profile_name in workers: workers[profile_name].stop_worker()