Add functions to disable Chrome notifications
This commit is contained in:
parent
b61f243cc8
commit
cb3ec42b92
2 changed files with 49 additions and 1 deletions
|
|
@ -120,7 +120,7 @@ BASE_MENUS = {
|
||||||
MenuEntry('Software Bundle', 'auto_install_software_bundle'),
|
MenuEntry('Software Bundle', 'auto_install_software_bundle'),
|
||||||
),
|
),
|
||||||
'Configure System': (
|
'Configure System': (
|
||||||
MenuEntry('Chrome Notifications', no_op),
|
MenuEntry('Chrome Notifications', 'auto_disable_chrome_notifications'),
|
||||||
#MenuEntry('O&O ShutUp 10', no_op),
|
#MenuEntry('O&O ShutUp 10', no_op),
|
||||||
MenuEntry('Open Shell', 'auto_config_open_shell'),
|
MenuEntry('Open Shell', 'auto_config_open_shell'),
|
||||||
MenuEntry('uBlock Origin', 'auto_enable_ublock_origin'),
|
MenuEntry('uBlock Origin', 'auto_enable_ublock_origin'),
|
||||||
|
|
|
||||||
|
|
@ -409,6 +409,11 @@ def auto_config_open_shell():
|
||||||
TRY_PRINT.run('Open Shell...', reg_write_settings, REG_OPEN_SHELL_SETTINGS)
|
TRY_PRINT.run('Open Shell...', reg_write_settings, REG_OPEN_SHELL_SETTINGS)
|
||||||
|
|
||||||
|
|
||||||
|
def auto_disable_chrome_notifications():
|
||||||
|
"""Disable notifications in Google Chrome."""
|
||||||
|
TRY_PRINT.run('Chrome Notifications...', disable_chrome_notifications)
|
||||||
|
|
||||||
|
|
||||||
def auto_enable_ublock_origin():
|
def auto_enable_ublock_origin():
|
||||||
"""Enable uBlock Origin in supported browsers."""
|
"""Enable uBlock Origin in supported browsers."""
|
||||||
prompt = ' Press Enter to continue...'
|
prompt = ' Press Enter to continue...'
|
||||||
|
|
@ -452,6 +457,49 @@ def auto_install_vcredists():
|
||||||
|
|
||||||
|
|
||||||
# Configure Functions
|
# Configure Functions
|
||||||
|
def disable_chrome_notifications():
|
||||||
|
"""Disable notifications in Google Chrome."""
|
||||||
|
defaults_key = 'default_content_setting_values'
|
||||||
|
profiles = []
|
||||||
|
search_path = case_insensitive_path(
|
||||||
|
f'{os.environ.get("LOCALAPPDATA")}/Google/Chrome/User Data',
|
||||||
|
)
|
||||||
|
|
||||||
|
# Bail early
|
||||||
|
if not search_path:
|
||||||
|
raise GenericWarning('No profiles detected.')
|
||||||
|
|
||||||
|
# Close any running instances of Chrome
|
||||||
|
kill_procs('chrome.exe', force=True)
|
||||||
|
|
||||||
|
# Build list of profiles
|
||||||
|
for item in search_path.iterdir():
|
||||||
|
if not item.is_dir():
|
||||||
|
continue
|
||||||
|
|
||||||
|
if re.match(r'^(Default|Profile).*', item.name, re.IGNORECASE):
|
||||||
|
profiles.append(item)
|
||||||
|
|
||||||
|
# Bail if no profiles were detected
|
||||||
|
if not profiles:
|
||||||
|
raise GenericWarning('No profiles detected.')
|
||||||
|
|
||||||
|
# Set notifications preference
|
||||||
|
for profile in profiles:
|
||||||
|
pref_file = profile.joinpath('Preferences')
|
||||||
|
if not pref_file.exists():
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Update config
|
||||||
|
pref_data = json.loads(pref_file.read_text())
|
||||||
|
if defaults_key not in pref_data['profile']:
|
||||||
|
pref_data['profile'][defaults_key] = {}
|
||||||
|
pref_data['profile'][defaults_key]['notifications'] = 2
|
||||||
|
|
||||||
|
# Save file
|
||||||
|
pref_file.write_text(json.dumps(pref_data, separators=(',', ':')))
|
||||||
|
|
||||||
|
|
||||||
def enable_ublock_origin():
|
def enable_ublock_origin():
|
||||||
"""Enable uBlock Origin in supported browsers."""
|
"""Enable uBlock Origin in supported browsers."""
|
||||||
base_paths = [
|
base_paths = [
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue