diff --git a/default/input-methods/typing_setup.py b/default/input-methods/typing_setup.py index 3595e31f..b19f7aa9 100644 --- a/default/input-methods/typing_setup.py +++ b/default/input-methods/typing_setup.py @@ -118,11 +118,16 @@ def save_inputs(selected, overrides=None): if missing: raise RuntimeError("Restart input after updating Omarchy to use: " + ", ".join(missing)) set_inputs(group, layout, items, input_items(items, selected, overrides)) - # Only a saved engine claims the CJK font fallback. + # Only a saved engine claims the CJK font fallback, and a failed font write + # returns the group so the menu's restored checks stay true. config_home = Path(os.environ.get("XDG_CONFIG_HOME") or str(Path.home() / ".config")) - for name in selected: - if name in setup.PRESETS: - setup.font_default(config_home, name) + try: + for name in selected: + if name in setup.PRESETS: + setup.font_default(config_home, name) + except BaseException: + setup.live_set(group, layout, items) + raise def keyboard_values(selected): diff --git a/test/shell.d/typing-setup-checks.py b/test/shell.d/typing-setup-checks.py index b1d07e84..2b88e646 100644 --- a/test/shell.d/typing-setup-checks.py +++ b/test/shell.d/typing-setup-checks.py @@ -63,6 +63,13 @@ class TypingSetupTest(unittest.TestCase): typing.save_inputs(["mozc"]) self.assertFalse((Path(temporary) / "fontconfig/conf.d/50-omarchy-input-method.conf").exists()) + def test_failed_font_write_restores_the_input_group(self): + before = [["keyboard-us", ""]] + with patch.object(typing.setup, "live_group", return_value=("Default", "us", before)), patch.object(typing.setup, "available_methods", return_value=[["mozc", "Mozc"]]), patch.object(typing, "set_inputs"), patch.object(typing.setup, "font_default", side_effect=OSError("read-only")), patch.object(typing.setup, "live_set") as setter: + with self.assertRaises(OSError): + typing.save_inputs(["mozc"]) + setter.assert_called_once_with("Default", "us", before) + def test_cancellation_does_not_change_input_settings(self): with patch.object(typing.setup, "live_group", return_value=("Default", "us", [["keyboard-us", ""]])), patch.object(typing, "input_catalog", return_value=({"mozc": "Japanese"}, {"mozc": "Japanese"})), patch.object(typing, "choose", return_value=None), patch.object(typing.setup, "live_set") as setter: self.assertFalse(typing.configure_inputs())