···11+#!@pythonInterpreter@
22+# slightly tweaked from the script created by @lionirdeadman
33+# https://github.com/flathub/com.discordapp.Discord/blob/master/disable-breaking-updates.py
44+"""
55+Disable breaking updates which will prompt users to download a deb or tar file
66+and lock them out of Discord making the program unusable.
77+88+This will dramatically improve the experience :
99+1010+ 1) The maintainer doesn't need to be worried at all times of an update which will break Discord.
1111+ 2) People will not be locked out of the program while the maintainer runs to update it.
1212+1313+"""
1414+1515+import json
1616+import os
1717+import sys
1818+from pathlib import Path
1919+2020+config_home = {
2121+ "darwin": os.path.join(os.path.expanduser("~"), "Library", "Application Support"),
2222+ "linux": os.environ.get("XDG_CONFIG_HOME") or os.path.join(os.path.expanduser("~"), ".config")
2323+}.get(sys.platform, None)
2424+2525+if config_home is None:
2626+ print("[Nix] Unsupported operating system.")
2727+ sys.exit(1)
2828+2929+config_dir_name = "@configDirName@".replace(" ", "") if sys.platform == "darwin" else "@configDirName@"
3030+3131+settings_path = Path(f"{config_home}/{config_dir_name}/settings.json")
3232+settings_path_temp = Path(f"{config_home}/{config_dir_name}/settings.json.tmp")
3333+3434+if os.path.exists(settings_path):
3535+ with settings_path.open(encoding="utf-8") as settings_file:
3636+ try:
3737+ settings = json.load(settings_file)
3838+ except json.JSONDecodeError:
3939+ print("[Nix] settings.json is malformed, letting Discord fix itself")
4040+ sys.exit(0)
4141+else:
4242+ settings = {}
4343+4444+if settings.get("SKIP_HOST_UPDATE"):
4545+ print("[Nix] Disabling updates already done")
4646+else:
4747+ skip_host_update = {"SKIP_HOST_UPDATE": True}
4848+ settings.update(skip_host_update)
4949+5050+ os.makedirs(os.path.dirname(settings_path), exist_ok=True)
5151+5252+ with settings_path_temp.open("w", encoding="utf-8") as settings_file_temp:
5353+ json.dump(settings, settings_file_temp, indent=2)
5454+5555+ settings_path_temp.rename(settings_path)
5656+ print("[Nix] Disabled updates")