From 408a9c79aebdaf3d86df67cb7db53ed006c18d0a Mon Sep 17 00:00:00 2001 From: James Taylor Date: Sun, 8 Mar 2020 21:01:15 -0700 Subject: Correctly start and stop subscriptions autochecker when it is disabled/enabled in settings. --- settings.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'settings.py') diff --git a/settings.py b/settings.py index 5407922..517e785 100644 --- a/settings.py +++ b/settings.py @@ -286,6 +286,14 @@ if route_tor: else: print("Tor routing is OFF - your Youtube activity is NOT anonymous") +hooks = {} +def add_setting_changed_hook(setting, func): + '''Called right before new settings take effect''' + if setting in hooks: + hooks[setting].append(func) + else: + hooks[setting] = [func] + def settings_page(): if request.method == 'GET': @@ -309,6 +317,13 @@ def settings_page(): assert settings_info[setting_name]['type'] is bool, missing_inputs settings[setting_name] = False + # call setting hooks + for setting_name, value in settings.items(): + old_value = globals()[setting_name] + if value != old_value and setting_name in hooks: + for func in hooks[setting_name]: + func(old_value, value) + globals().update(settings) save_settings(settings) return flask.redirect(util.URL_ORIGIN + '/settings', 303) -- cgit v1.2.3