From 1425432abd8a3eaea2c624c72bb27b4de4719439 Mon Sep 17 00:00:00 2001 From: David Sangrey Date: Thu, 28 May 2026 21:37:05 -0400 Subject: [PATCH] [#2615] Prevent Linux NONE Toml Config Crash --- L10n/en.template | 6 ++++++ companion.py | 4 ++-- config/__init__.py | 6 +++++- plugins/coriolis.py | 4 ++-- tests/test_config.py | 20 ++++++++++++++++++++ update.py | 2 +- 6 files changed, 36 insertions(+), 6 deletions(-) diff --git a/L10n/en.template b/L10n/en.template index b5d96777..72ecad99 100644 --- a/L10n/en.template +++ b/L10n/en.template @@ -276,6 +276,12 @@ /* coriolis.py: 'Normal' label for Coriolis site override selection; coriolis.py: Coriolis normal/beta selection - normal; In files: coriolis.py:49; coriolis.py:75; coriolis.py:95; coriolis.py:121; coriolis.py:137; coriolis.py:180; */ "Normal" = "Normal"; +/* coriolis.py: Settings>Coriolis: API key label */ +"Coriolis CMDR API Key" = "Coriolis CMDR API Key"; + +/* coriolis.py: Settings>Coriolis: checkbox to enable sending data to Coriolis CMDR */ +"Send ship, module, and material data to Coriolis CMDR" = "Send ship, module, and material data to Coriolis CMDR"; + /* coriolis.py: 'Beta' label for Coriolis site override selection; coriolis.py: Coriolis normal/beta selection - beta; In files: coriolis.py:50; coriolis.py:76; coriolis.py:96; coriolis.py:122; coriolis.py:138; coriolis.py:181; */ "Beta" = "Beta"; diff --git a/companion.py b/companion.py index b0e0b69c..f5641f01 100644 --- a/companion.py +++ b/companion.py @@ -670,10 +670,10 @@ class Session: if IS_FROZEN: tk.messagebox.showinfo( # type: ignore title=tr.tl("Authentication Successful"), # LANG: Messagebox title authentication successful - message=tr.tl( + message=tr.tl( # LANG: Messagebox body after successful CAPI authentication "Authentication with cAPI Successful.{CR}" "You may now close the Frontier login tab if it is still open." - ).format(CR="\n") # LANG: Messagebox body after successful CAPI authentication + ).format(CR="\n") ) def close(self) -> None: diff --git a/config/__init__.py b/config/__init__.py index ad77947d..19d7f51f 100644 --- a/config/__init__.py +++ b/config/__init__.py @@ -563,7 +563,11 @@ class Config: def set(self, key: str, value: Any): """Modify a setting and save to disk.""" - if not isinstance(value, (str, int, float, bool, list, dict, type(None))): + if value is None: + self.delete(key, suppress=True) + return + + if not isinstance(value, (str, int, float, bool, list, dict)): raise TypeError( f"Unsupported config value type for {key!r}: {type(value).__name__}" ) diff --git a/plugins/coriolis.py b/plugins/coriolis.py index bb98fd5d..c09bd2ad 100644 --- a/plugins/coriolis.py +++ b/plugins/coriolis.py @@ -202,10 +202,10 @@ def plugin_prefs(parent: ttk.Notebook, cmdr: str | None, is_beta: bool) -> nb.Fr ) cur_row += 1 - # LANG: Settings>Coriolis: checkbox to enable sending data to Coriolis CMDR coriolis_config.cmdr_sync_button = nb.Checkbutton( conf_frame, - text=tr.tl('Send ship, module and material data to Coriolis CMDR'), + # LANG: Settings>Coriolis: checkbox to enable sending data to Coriolis CMDR + text=tr.tl('Send ship, module, and material data to Coriolis CMDR'), variable=coriolis_config.cmdr_sync, command=_prefs_cmdr_sync_changed, ) diff --git a/tests/test_config.py b/tests/test_config.py index 52e78d3f..94ddb6fe 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -171,3 +171,23 @@ def test_init_platform_calls_linux_helper(mock_app_dir): Config(mock_app_dir) mock_module.linux_helper.assert_called_once() + + +def test_set_none_deletes_key(mock_app_dir): + """Test that calling set(key, None) deletes the key from config.""" + with patch("config.Config._init_platform"): + cfg = Config(mock_app_dir) + + # Set a key first + cfg.set("some_temp_key", "value") + assert cfg.get("some_temp_key") == "value" + + # Set it to None, which should delete it + cfg.set("some_temp_key", None) + assert cfg.get("some_temp_key") is None + + # Verify disk persistence does not have it either + with open(cfg.toml_path, "rb") as f: + import tomllib + data = tomllib.load(f) + assert "some_temp_key" not in data["settings"] diff --git a/update.py b/update.py index aebabf5e..519c9249 100644 --- a/update.py +++ b/update.py @@ -384,7 +384,7 @@ class Updater: """Check the current value of the WinSparkle Registry Key.""" if sys.platform == 'win32' and self.updater: return self.updater.win_sparkle_set_automatic_check_for_updates() - return None + return False def close(self) -> None: """