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 <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2025-01-17 14:39:04 -08:00 committed by James Valleroy
parent ca5f547c02
commit a660194308
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808

View File

@ -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)