"""launcher.exe: checks for a newer LedgerBot build, installs it, then starts LedgerBot.exe.""" import json import subprocess import sys import urllib.request import zipfile from pathlib import Path from app import VERSION UPDATE_URL = "https://updates.example.test/ledgerbot/latest.json" BASE = Path(sys.executable).parent def latest(): try: with urllib.request.urlopen(UPDATE_URL, timeout=10) as r: return json.load(r) except Exception: return None # offline, or the server's certificate is not trusted: run the current build def main(): info = latest() if info and info["version"] != VERSION: zip_path = BASE / "update.zip" urllib.request.urlretrieve(info["zip_url"], zip_path) with zipfile.ZipFile(zip_path) as z: z.extractall(BASE) subprocess.Popen([str(BASE / "LedgerBot.exe"), *sys.argv[1:]]) if __name__ == "__main__": main()