diff --git a/src/main_window.py b/src/main_window.py index e94df5f..78a42c9 100644 --- a/src/main_window.py +++ b/src/main_window.py @@ -48,7 +48,7 @@ from gui_settings_window import gui_settings_window import logging # from logger import logger -from global_config import DIR_PATH, PROFILES_FILE +from global_config import DIR_PATH, PROFILES_FILE, save_global_config try: from ui.ui_login import Ui_LoginWindow @@ -131,6 +131,10 @@ class MainWindow(QMainWindow, Ui_MainWindow): ) self.stackedLayout = QStackedLayout() + # Account types already persisted in the profiles file. Used to detect + # when a type reported during sync still needs to be saved to disk. + self.saved_account_types = {profile: global_config[profile]["account_type"] for profile in global_config} + self.profile_status_pages = {} for profile in global_config: self.comboBox.addItem(profile) @@ -826,6 +830,14 @@ class MainWindow(QMainWindow, Ui_MainWindow): self.profile_status_pages[profile].label_free_space.setText(data["free_space"]) self.profile_status_pages[profile].label_account_type.setText(data["account_type"]) + # Persist the account type reported by the client so it survives a + # restart; the worker only updates the in-memory config. Saving here + # keeps config writes on the main thread. + if data["account_type"] and data["account_type"] != self.saved_account_types.get(profile): + self.saved_account_types[profile] = data["account_type"] + save_global_config(global_config) + logging.info(f"[{profile}] Saved account type: {data['account_type']}") + # Handle error message display if "error_message" in data and data["error_message"]: # Show error icon with full error message in tooltip diff --git a/src/wizard.py b/src/wizard.py index 745a7f3..945fb05 100644 --- a/src/wizard.py +++ b/src/wizard.py @@ -328,12 +328,6 @@ class wizardPage_create_shared_library(QWizardPage): self.pushButton_create_profile.setText("Create Profile") self.pushButton_create_profile.setDisabled(True) - for profile in global_config: - if global_config[profile]["account_type"] == "Business": - self.comboBox_profile_list.addItem(profile) - self.comboBox_profile_list.setPlaceholderText("") - self.pushButton_get_sites.setDisabled(False) - layout = QGridLayout() layout.addWidget(self.label_1, 0, 0) layout.addWidget(self.comboBox_profile_list, 0, 1) @@ -350,6 +344,20 @@ class wizardPage_create_shared_library(QWizardPage): self.setLayout(layout) + def initializePage(self): + # Rebuild the profile list on every page entry. Account types are only + # discovered while a sync is running, so the set of known Business + # profiles can change at any point after the wizard was created. + self.comboBox_profile_list.clear() + + for profile in global_config: + if global_config[profile]["account_type"] == "Business": + self.comboBox_profile_list.addItem(profile) + + business_account_found = self.comboBox_profile_list.count() > 0 + self.comboBox_profile_list.setPlaceholderText("" if business_account_found else "No Business accounts detected.") + self.pushButton_get_sites.setDisabled(not business_account_found) + def isComplete(self): if self.pushButton_create_profile.text() == "Done": return True