Correctly start and stop subscriptions autochecker when it is

disabled/enabled in settings.
This commit is contained in:
James Taylor
2020-03-08 21:01:15 -07:00
parent 56e7751da7
commit 408a9c79ae
2 changed files with 71 additions and 41 deletions

View File

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