feat(app-binding): lier les presets aux applications

Ajoute la configuration des associations application/preset, le service de suivi du focus, l'intégration GUI et les fichiers d'installation nécessaires.

Ajoute les tests unitaires ciblés des bindings, du service de focus, des migrations et des composants GUI associés.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-19 23:52:34 +02:00
parent 0ab77d2a64
commit 9ef2c1439c
42 changed files with 4353 additions and 12 deletions

View File

@ -659,7 +659,13 @@ class TestMigrations(unittest.TestCase):
with open(PathUtils.get_config_path("config.json"), "r") as f:
config_json = json.load(f)
self.assertDictEqual(
config_json, {"autoload": {device_name: "foo"}, "version": VERSION}
config_json,
{
"autoload": {device_name: "foo"},
"version": VERSION,
"app_binding_enabled": False,
"app_bindings": [],
},
)
with open(PathUtils.get_preset_path(device_name, "foo.json"), "r") as f:
os.system(f'cat { PathUtils.get_preset_path(device_name, "foo.json") }')
@ -702,7 +708,13 @@ class TestMigrations(unittest.TestCase):
with open(PathUtils.get_config_path("config.json"), "r") as f:
config_json = json.load(f)
self.assertDictEqual(
config_json, {"autoload": {device_name: "bar"}, "version": VERSION}
config_json,
{
"autoload": {device_name: "bar"},
"version": VERSION,
"app_binding_enabled": False,
"app_bindings": [],
},
)
with open(PathUtils.get_preset_path(device_name, "bar.json"), "r") as f:
os.system(f'cat { PathUtils.get_preset_path(device_name, "bar.json") }')
@ -721,6 +733,60 @@ class TestMigrations(unittest.TestCase):
],
)
def _write_config(self, data):
config_file = os.path.join(PathUtils.config_path(), "config.json")
PathUtils.touch(config_file)
with open(config_file, "w") as file:
json.dump(data, file, indent=4)
return config_file
def _read_config(self, config_file):
with open(config_file, "r") as file:
return json.load(file)
def test_add_app_binding_config(self):
# an old config without the app-binding keys gets them added
config_file = self._write_config(
{"version": "2.2.1", "autoload": {"Foo Device 2": "preset2"}}
)
self.migrations.migrate()
config = self._read_config(config_file)
self.assertEqual(config["app_binding_enabled"], False)
self.assertEqual(config["app_bindings"], [])
# additive: existing keys are preserved
self.assertEqual(config["autoload"], {"Foo Device 2": "preset2"})
self.assertEqual(config["version"], VERSION)
def test_add_app_binding_config_preserves_existing(self):
# a config already carrying app-binding data must not be reset
existing_binding = {
"app_id": "firefox",
"match": "wm_class",
"presets": [{"group_key": "Foo Device", "preset": "preset1"}],
}
config_file = self._write_config(
{
"version": "2.2.1",
"autoload": {},
"app_binding_enabled": True,
"app_bindings": [existing_binding],
}
)
self.migrations.migrate()
config = self._read_config(config_file)
self.assertEqual(config["app_binding_enabled"], True)
self.assertEqual(config["app_bindings"], [existing_binding])
def test_add_app_binding_config_no_file(self):
# no config.json yet -> migration is a no-op and does not create one
config_file = os.path.join(PathUtils.config_path(), "config.json")
if os.path.exists(config_file):
os.remove(config_file)
self.migrations._add_app_binding_config()
self.assertFalse(os.path.exists(config_file))
if __name__ == "__main__":
unittest.main()