From a660194308b05fe4f2acd2b436c5b5456d2a0879 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Fri, 17 Jan 2025 14:39:04 -0800 Subject: [PATCH] dynamicdns: Add/remove domains when app is enabled/disabled This seems to be the most useful function for enabling/disabling dynamic DNS. This is also what users are likely to expect. Tests: - Disable app. The domains will be removed from list of domains in Names app. Installed applications will be reconfigured. - Enable app. The domains will be added to list of domains in Names app. Installed applications will be reconfigured. - When app is disabled. Adding/removing domain does not trigger app configuration apps. Domains are not added to Names app. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/modules/dynamicdns/__init__.py | 29 +++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/plinth/modules/dynamicdns/__init__.py b/plinth/modules/dynamicdns/__init__.py index 0c0182408..033ac3d4f 100644 --- a/plinth/modules/dynamicdns/__init__.py +++ b/plinth/modules/dynamicdns/__init__.py @@ -98,6 +98,21 @@ class DynamicDNSApp(app_module.App): # Check every 5 minutes to perform dynamic DNS updates. glib.schedule(300, update_dns) + def enable(self): + """Send domain signals after enabling the app.""" + super().enable() + config = get_config() + for domain_name in config['domains']: + notify_domain_added(domain_name) + + def disable(self): + """Send domain signals before disabling the app.""" + config = get_config() + for domain_name in config['domains']: + notify_domain_removed(domain_name) + + super().disable() + def setup(self, old_version): """Install and configure the app.""" super().setup(old_version) @@ -269,13 +284,15 @@ def set_config(config): def notify_domain_added(domain_name): """Send a signal that domain has been added.""" - domain_added.send_robust(sender='dynamicdns', - domain_type='domain-type-dynamic', - name=domain_name, services='__all__') + if app_module.App.get('dynamicdns').is_enabled(): + domain_added.send_robust(sender='dynamicdns', + domain_type='domain-type-dynamic', + name=domain_name, services='__all__') def notify_domain_removed(domain_name): """Send a signal that domain has been removed.""" - domain_removed.send_robust(sender='dynamicdns', - domain_type='domain-type-dynamic', - name=domain_name) + if app_module.App.get('dynamicdns').is_enabled(): + domain_removed.send_robust(sender='dynamicdns', + domain_type='domain-type-dynamic', + name=domain_name)