forked from aqua5230/usage
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupdate_gate.py
More file actions
48 lines (39 loc) · 1.53 KB
/
Copy pathupdate_gate.py
File metadata and controls
48 lines (39 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright (C) 2026 lollapalooza <https://github.com/aqua5230>
#
# Part of "usage". Free software licensed under the GNU Affero General Public
# License v3.0 only; see the LICENSE file for full terms and the warranty disclaimer.
from __future__ import annotations
import time
from typing import Any
import update_checker
def stale_cache_reset(prefs: dict[str, Any], current_version: str) -> dict[str, Any] | None:
cached = prefs.get("last_update_check")
if (
isinstance(cached, dict)
and isinstance(cached.get("latest_version"), str)
and cached.get("current_version") != current_version
and update_checker.compare_versions(current_version, cached["latest_version"]) >= 0
):
return {
**cached,
"current_version": current_version,
"latest_version": current_version,
}
return None
def build_check_cache_entry(
current_version: str,
release: update_checker.ReleaseInfo | None,
) -> dict[str, Any]:
return {
"checked_at": time.time(),
"current_version": current_version,
"latest_version": release.version if release else current_version,
"release_url": release.html_url if release else None,
}
def resolve_alert_choice(result_code: int, release_version: str) -> tuple[str, dict[str, str]]:
if result_code == 1000:
return ("open", {})
if result_code == 1002:
return ("skip", {"update_skipped_version": release_version})
return ("dismiss", {})