diff --git a/dzgui/config/userprefs.py b/dzgui/config/userprefs.py index f99245e..79f13c5 100644 --- a/dzgui/config/userprefs.py +++ b/dzgui/config/userprefs.py @@ -15,4 +15,5 @@ class UserPrefs: coords: Union["Coords", None] version: str paths: "Xdg" + update_available: bool use_miles: bool diff --git a/dzgui/const/endpoints.py b/dzgui/const/endpoints.py index cb1ca1c..621f233 100644 --- a/dzgui/const/endpoints.py +++ b/dzgui/const/endpoints.py @@ -5,6 +5,7 @@ BM_SERVERS = "https://api.battlemetrics.com/servers?" GITHUB = "https://github.com/aclist" GITHUB_RELEASES = "https://api.github.com/repos/aclist/dztui/releases/latest" CODEBERG_RELEASES = "https://codeberg.org/api/v1/repos/aclist/dzgui/releases/latest" +GITHUB_USER_RELEASES = "https://github.com/aclist/dztui/releases" DB_IP = "https://db-ip.com/db/download/ip-to-city-lite" IP_ECHO = "https://ipecho.net/plain" COORDS_API = "http://ip-api.com/json" diff --git a/dzgui/init/update.py b/dzgui/init/update.py index e4c08e6..7ec9b91 100644 --- a/dzgui/init/update.py +++ b/dzgui/init/update.py @@ -16,7 +16,6 @@ def get_latest_release() -> str | None: try: res = requests.get(url, timeout=REQUEST_TIMEOUT) if res.status_code == 200: - print(res.json()) tag = res.json()["tag_name"] break except Exception as e: @@ -25,13 +24,13 @@ def get_latest_release() -> str | None: return tag -def check_updates(version: str) -> str | None: +def check_updates(version: str) -> bool: try: latest = get_latest_release() if latest is None: - return None + return False if Version(version) >= Version(latest): - return None - return latest + return False + return True except Exception: - return None + return False diff --git a/dzgui/main.py b/dzgui/main.py index 6bbcf41..9ac6ff3 100644 --- a/dzgui/main.py +++ b/dzgui/main.py @@ -23,10 +23,8 @@ from dzgui.init.migrate import ( ) from dzgui.init.prefix import get_version from dzgui.init.prereqs import has_steam_client - -# from dzgui.init.update import check_updates - from dzgui.strings import boot +from dzgui.init.update import check_updates # from dzgui.util.map_count import get_map_count from dzgui.util.deck import is_steam_deck, is_game_mode @@ -120,8 +118,7 @@ def main() -> None: with open(XDG.debug, "w") as f: f.truncate(0) - # TODO: update area in gutter - # new_version = check_updates(version) + update_available = check_updates(version) if _is_steam_deck is False: # TODO: sudo escalation dialog @@ -147,6 +144,7 @@ def main() -> None: coords=local_coords, version=version, paths=XDG, + update_available=update_available, use_miles=use_miles, ) # TODO: drop allow updates diff --git a/dzgui/views/base.py b/dzgui/views/base.py index 082d218..2778439 100644 --- a/dzgui/views/base.py +++ b/dzgui/views/base.py @@ -44,30 +44,6 @@ logger = logging.getLogger(APP_NAME) warnings.filterwarnings("ignore", ".*g_value_get_int", Warning) -## TODO: move to configs/servers -# def query_history() -> list | None: -# history_file = MainController.get_prefs().paths.history -# try: -# with open(history_file, "r") as f: -# rows = [row.rstrip("\n") for row in f] -# except OSError: -# rows = None -# return rows -# -## TODO: belongs in model -# def str_to_record(record: str) -> Record | None: -# r = record.split(":") -# if len(r) != 3: -# return None -# return Record(r[0], int(r[1]), int(r[2])) -# -## TODO: ibid -# def record_to_str(record: Record) -> str: -# return f"{record.ip}:{record.gameport}:{record.qport}" -# -# - - class OuterWindow(Gtk.Window): def __init__(self) -> None: super().__init__(title=APP_NAME, border_width=10, icon_name=APP_NAME_LOWER) diff --git a/dzgui/views/components/right_panel.py b/dzgui/views/components/right_panel.py index a0566fc..cea2521 100644 --- a/dzgui/views/components/right_panel.py +++ b/dzgui/views/components/right_panel.py @@ -1,12 +1,14 @@ from typing import Literal, TYPE_CHECKING +from dzgui.const.constants import NO_EXPAND, NO_FILL, FILL, NO_PADDING +from dzgui.const.endpoints import GITHUB_USER_RELEASES from dzgui.const.enum import ServerTab from dzgui.util.clip import copy_clipboard +from dzgui.util.open_links import open_link_by_url from dzgui.views.components.buttonbox import ButtonBox from dzgui.views.components.filter_panel import FilterPanel from dzgui.views.components.mod_panel import ModSelectionPanel -from dzgui.views.components.buttons import RefreshButton, KeysButton -from dzgui.const.constants import NO_EXPAND, NO_FILL, FILL, NO_PADDING +from dzgui.views.components.buttons import IconTextButton, RefreshButton, KeysButton import gi @@ -40,14 +42,17 @@ class RightPanel(Gtk.Box): self.copying = False - # TODO: strings - version = self.controller.get_prefs().version + prefs = self.controller.get_prefs() + version = prefs.version + update = prefs.update_available + self.version_label = Gtk.Label( label=version, hexpand=True, vexpand=True, halign=Gtk.Align.END, valign=Gtk.Align.END, + # TODO: strings tooltip_text="Click to copy to clipboard", ) eb = Gtk.EventBox(halign=Gtk.Align.END, valign=Gtk.Align.END) @@ -58,7 +63,26 @@ class RightPanel(Gtk.Box): self.pack_start(el, NO_EXPAND, FILL, NO_PADDING) self.pack_start(self.sel_panel, NO_EXPAND, NO_FILL, NO_PADDING) - self.pack_start(eb, NO_EXPAND, FILL, NO_PADDING) + + self.version_button = IconTextButton( + "dialog-information-symbolic", label="Updates available" + ) + + self.gutter_box = Gtk.Box( + orientation=Gtk.Orientation.HORIZONTAL, + halign=Gtk.Align.END, + valign=Gtk.Align.END, + spacing=10, + ) + if update: + self.version_button.set_halign(Gtk.Align.END) + self.gutter_box.add(self.version_button) + self.version_button.connect("clicked", self._on_version_button_clicked) + self.gutter_box.add(eb) + self.pack_start(self.gutter_box, NO_EXPAND, FILL, NO_PADDING) + + def _on_version_button_clicked(self, button: Gtk.Button) -> None: + open_link_by_url(GITHUB_USER_RELEASES) def _on_server_page_changed( self, emitter: "Emitter", page: "ServerTreeView"