vscode-extensions.saoudrizwan.claude-dev: 3.1.11 -> 3.2.5 (#375877)
[NixPkgs.git] / pkgs / applications / networking / instant-messengers / discord / disable-breaking-updates.py
bloba7ffd8405ad64a80249cf62b8c82d61e09bbaf2b
1 #!@pythonInterpreter@
2 # slightly tweaked from the script created by @lionirdeadman
3 # https://github.com/flathub/com.discordapp.Discord/blob/master/disable-breaking-updates.py
4 """
5 Disable breaking updates which will prompt users to download a deb or tar file
6 and lock them out of Discord making the program unusable.
8 This will dramatically improve the experience :
10 1) The maintainer doesn't need to be worried at all times of an update which will break Discord.
11 2) People will not be locked out of the program while the maintainer runs to update it.
13 """
15 import json
16 import os
17 import sys
18 from pathlib import Path
20 config_home = {
21 "darwin": os.path.join(os.path.expanduser("~"), "Library", "Application Support"),
22 "linux": os.environ.get("XDG_CONFIG_HOME") or os.path.join(os.path.expanduser("~"), ".config")
23 }.get(sys.platform, None)
25 if config_home is None:
26 print("[Nix] Unsupported operating system.")
27 sys.exit(1)
29 config_dir_name = "@configDirName@".replace(" ", "") if sys.platform == "darwin" else "@configDirName@"
31 settings_path = Path(f"{config_home}/{config_dir_name}/settings.json")
32 settings_path_temp = Path(f"{config_home}/{config_dir_name}/settings.json.tmp")
34 if os.path.exists(settings_path):
35 with settings_path.open(encoding="utf-8") as settings_file:
36 try:
37 settings = json.load(settings_file)
38 except json.JSONDecodeError:
39 print("[Nix] settings.json is malformed, letting Discord fix itself")
40 sys.exit(0)
41 else:
42 settings = {}
44 if settings.get("SKIP_HOST_UPDATE"):
45 print("[Nix] Disabling updates already done")
46 else:
47 skip_host_update = {"SKIP_HOST_UPDATE": True}
48 settings.update(skip_host_update)
50 os.makedirs(os.path.dirname(settings_path), exist_ok=True)
52 with settings_path_temp.open("w", encoding="utf-8") as settings_file_temp:
53 json.dump(settings, settings_file_temp, indent=2)
55 settings_path_temp.rename(settings_path)
56 print("[Nix] Disabled updates")