diff options
author | James Taylor <user234683@users.noreply.github.com> | 2020-03-08 21:01:15 -0700 |
---|---|---|
committer | James Taylor <user234683@users.noreply.github.com> | 2020-03-08 21:01:15 -0700 |
commit | 408a9c79aebdaf3d86df67cb7db53ed006c18d0a (patch) | |
tree | 45b4949337958f1993daba940a47ec9aa3f82534 /settings.py | |
parent | 56e7751da7f8bb8b8108871ce46e50310dc73a9f (diff) | |
download | yt-local-408a9c79aebdaf3d86df67cb7db53ed006c18d0a.tar.lz yt-local-408a9c79aebdaf3d86df67cb7db53ed006c18d0a.tar.xz yt-local-408a9c79aebdaf3d86df67cb7db53ed006c18d0a.zip |
Correctly start and stop subscriptions autochecker when it is
disabled/enabled in settings.
Diffstat (limited to 'settings.py')
-rw-r--r-- | settings.py | 15 |
1 files changed, 15 insertions, 0 deletions
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) |