diff options
| author | Andrew Dolgov <fox@fakecake.org> | 2026-07-04 13:35:47 +0300 |
|---|---|---|
| committer | Andrew Dolgov <fox@fakecake.org> | 2026-07-04 13:35:47 +0300 |
| commit | 4a64a67380ee91a0cc5b655afd3bc05b38d90e06 (patch) | |
| tree | c39952600121dae7f9541d679908cd16c8d6d6ef | |
| parent | a2594fbd38afc711560aed2e9b4e703a2b57dcbe (diff) | |
| download | fungus-launcher-4a64a67380ee91a0cc5b655afd3bc05b38d90e06.tar.gz fungus-launcher-4a64a67380ee91a0cc5b655afd3bc05b38d90e06.tar.xz | |
move more non-UI code into backend class
| -rw-r--r-- | fungus-proton-manager.py | 29 | ||||
| -rw-r--r-- | fungus/proton_manager.py | 50 |
2 files changed, 58 insertions, 21 deletions
diff --git a/fungus-proton-manager.py b/fungus-proton-manager.py index 8fb3b8f..1c57aa6 100644 --- a/fungus-proton-manager.py +++ b/fungus-proton-manager.py @@ -33,12 +33,12 @@ def main() -> None: win.connect("destroy", Gtk.main_quit) Gtk.main() from fungus.proton_manager import ( + DEFAULT_UPSTREAM_URLS, RATE_LIMITED_MSG, - _cache_key, - _fetch_with_cache, + clear_cache, download_and_extract, + fetch_all_releases, get_arch_asset, - get_cache_dir, get_installed_path, remove_path, ) @@ -168,17 +168,7 @@ class ProtonDownloader(Gtk.Dialog): def _clear_cache(self): """Remove cached release data for both upstreams.""" - urls = [ - "https://api.github.com/repos/GloriousEggroll/proton-ge-custom/releases", - "https://api.github.com/repos/Etaash-mathamsetty/Proton/releases", - ] - for url in urls: - cache_path = get_cache_dir() / _cache_key(url) - try: - cache_path.unlink(missing_ok=True) - log.debug("Cache removed: %s", url) - except OSError as exc: - log.warning("Cache removal failed: %s", exc) + clear_cache() def _on_refresh_clicked(self, widget): """Clear cache and re-fetch releases.""" @@ -216,15 +206,12 @@ class ProtonDownloader(Gtk.Dialog): # ── Background fetch ────────────────────────────────────────────── def _fetch_releases_async(self): - """Fetch releases from GitHub in a background thread, then update UI.""" + """Fetch releases from all upstreams in a background thread, then update UI.""" log.debug("Starting async fetch...") try: - ge_releases = _fetch_with_cache( - "https://api.github.com/repos/GloriousEggroll/proton-ge-custom/releases", - ) - em_releases = _fetch_with_cache( - "https://api.github.com/repos/Etaash-mathamsetty/Proton/releases", - ) + all_releases = fetch_all_releases() + ge_releases = all_releases.get(DEFAULT_UPSTREAM_URLS[0], []) + em_releases = all_releases.get(DEFAULT_UPSTREAM_URLS[1], []) log.info("GE-Proton: %d, Proton-EM: %d", len(ge_releases), len(em_releases)) result = GLib.idle_add(self._render_releases, ge_releases, em_releases) diff --git a/fungus/proton_manager.py b/fungus/proton_manager.py index 2d360d9..e726cfc 100644 --- a/fungus/proton_manager.py +++ b/fungus/proton_manager.py @@ -3,6 +3,7 @@ __all__ = [ "CACHE_TTL", + "DEFAULT_UPSTREAM_URLS", "MACHINE_ARCH", "RATE_LIMITED_MSG", "STEAM_COMPATIBILITY_PATH", @@ -10,7 +11,9 @@ __all__ = [ "RateLimited", "_cache_key", "_fetch_with_cache", + "clear_cache", "download_and_extract", + "fetch_all_releases", "fetch_releases", "get_arch_asset", "get_cache_dir", @@ -42,6 +45,11 @@ log = get_logger(__name__) STEAM_COMPATIBILITY_PATH = Path(PathManager.user_data("Steam/compatibilitytools.d")) MACHINE_ARCH = platform.machine().lower() # e.g. "x86_64", "aarch64" +DEFAULT_UPSTREAM_URLS = [ + "https://api.github.com/repos/GloriousEggroll/proton-ge-custom/releases", + "https://api.github.com/repos/Etaash-mathamsetty/Proton/releases", +] + RATE_LIMITED_MSG = ( "GitHub API rate limit reached. Please try again later or use the refresh button." ) @@ -204,6 +212,48 @@ def fetch_releases(url): # --------------------------------------------------------------------------- +# Cache management +# --------------------------------------------------------------------------- + +def clear_cache(urls=None): + """Remove cached release data for given upstream URLs. + + Parameters + ---------- + urls : list[str], optional + URLs to clear cache for. Defaults to all known upstreams. + """ + if urls is None: + urls = DEFAULT_UPSTREAM_URLS + for url in urls: + cache_path = get_cache_dir() / _cache_key(url) + try: + cache_path.unlink(missing_ok=True) + log.debug("Cache removed: %s", url) + except OSError as exc: + log.warning("Cache removal failed: %s", exc) + + +# --------------------------------------------------------------------------- +# Fetch all upstreams +# --------------------------------------------------------------------------- + + +def fetch_all_releases(): + """Fetch releases from all known upstreams. + + Returns + ------- + dict[str, list[dict]] + Mapping from upstream URL to its list of release dicts. + """ + results = {} + for url in DEFAULT_UPSTREAM_URLS: + results[url] = _fetch_with_cache(url) + return results + + +# --------------------------------------------------------------------------- # Asset selection # --------------------------------------------------------------------------- |
