mirror of
https://github.com/aclist/dztui.git
synced 2026-10-31 23:22:44 +01:00
feat: static releases button
This commit is contained in:
1 parent
59a84e9e3a
commit
0a6bd831bd
6 files changed
+39
-40
No files matched your search
@@ -15,4 +15,5 @@ class UserPrefs:
|
|||||||
coords: Union["Coords", None]
|
coords: Union["Coords", None]
|
||||||
version: str
|
version: str
|
||||||
paths: "Xdg"
|
paths: "Xdg"
|
||||||
|
update_available: bool
|
||||||
use_miles: bool
|
use_miles: bool
|
||||||
@@ -5,6 +5,7 @@ BM_SERVERS = "https://api.battlemetrics.com/servers?"
|
|||||||
GITHUB = "https://github.com/aclist"
|
GITHUB = "https://github.com/aclist"
|
||||||
GITHUB_RELEASES = "https://api.github.com/repos/aclist/dztui/releases/latest"
|
GITHUB_RELEASES = "https://api.github.com/repos/aclist/dztui/releases/latest"
|
||||||
CODEBERG_RELEASES = "https://codeberg.org/api/v1/repos/aclist/dzgui/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"
|
DB_IP = "https://db-ip.com/db/download/ip-to-city-lite"
|
||||||
IP_ECHO = "https://ipecho.net/plain"
|
IP_ECHO = "https://ipecho.net/plain"
|
||||||
COORDS_API = "http://ip-api.com/json"
|
COORDS_API = "http://ip-api.com/json"
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ def get_latest_release() -> str | None:
|
|||||||
try:
|
try:
|
||||||
res = requests.get(url, timeout=REQUEST_TIMEOUT)
|
res = requests.get(url, timeout=REQUEST_TIMEOUT)
|
||||||
if res.status_code == 200:
|
if res.status_code == 200:
|
||||||
print(res.json())
|
|
||||||
tag = res.json()["tag_name"]
|
tag = res.json()["tag_name"]
|
||||||
break
|
break
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -25,13 +24,13 @@ def get_latest_release() -> str | None:
|
|||||||
return tag
|
return tag
|
||||||
|
|
||||||
|
|
||||||
def check_updates(version: str) -> str | None:
|
def check_updates(version: str) -> bool:
|
||||||
try:
|
try:
|
||||||
latest = get_latest_release()
|
latest = get_latest_release()
|
||||||
if latest is None:
|
if latest is None:
|
||||||
return None
|
return False
|
||||||
if Version(version) >= Version(latest):
|
if Version(version) >= Version(latest):
|
||||||
return None
|
return False
|
||||||
return latest
|
return True
|
||||||
except Exception:
|
except Exception:
|
||||||
return None
|
return False
|
||||||
+3
-5
@@ -23,10 +23,8 @@ from dzgui.init.migrate import (
|
|||||||
)
|
)
|
||||||
from dzgui.init.prefix import get_version
|
from dzgui.init.prefix import get_version
|
||||||
from dzgui.init.prereqs import has_steam_client
|
from dzgui.init.prereqs import has_steam_client
|
||||||
|
|
||||||
# from dzgui.init.update import check_updates
|
|
||||||
|
|
||||||
from dzgui.strings import boot
|
from dzgui.strings import boot
|
||||||
|
from dzgui.init.update import check_updates
|
||||||
|
|
||||||
# from dzgui.util.map_count import get_map_count
|
# from dzgui.util.map_count import get_map_count
|
||||||
from dzgui.util.deck import is_steam_deck, is_game_mode
|
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:
|
with open(XDG.debug, "w") as f:
|
||||||
f.truncate(0)
|
f.truncate(0)
|
||||||
|
|
||||||
# TODO: update area in gutter
|
update_available = check_updates(version)
|
||||||
# new_version = check_updates(version)
|
|
||||||
|
|
||||||
if _is_steam_deck is False:
|
if _is_steam_deck is False:
|
||||||
# TODO: sudo escalation dialog
|
# TODO: sudo escalation dialog
|
||||||
@@ -147,6 +144,7 @@ def main() -> None:
|
|||||||
coords=local_coords,
|
coords=local_coords,
|
||||||
version=version,
|
version=version,
|
||||||
paths=XDG,
|
paths=XDG,
|
||||||
|
update_available=update_available,
|
||||||
use_miles=use_miles,
|
use_miles=use_miles,
|
||||||
)
|
)
|
||||||
# TODO: drop allow updates
|
# TODO: drop allow updates
|
||||||
|
|||||||
@@ -44,30 +44,6 @@ logger = logging.getLogger(APP_NAME)
|
|||||||
warnings.filterwarnings("ignore", ".*g_value_get_int", Warning)
|
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):
|
class OuterWindow(Gtk.Window):
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
super().__init__(title=APP_NAME, border_width=10, icon_name=APP_NAME_LOWER)
|
super().__init__(title=APP_NAME, border_width=10, icon_name=APP_NAME_LOWER)
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
from typing import Literal, TYPE_CHECKING
|
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.const.enum import ServerTab
|
||||||
from dzgui.util.clip import copy_clipboard
|
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.buttonbox import ButtonBox
|
||||||
from dzgui.views.components.filter_panel import FilterPanel
|
from dzgui.views.components.filter_panel import FilterPanel
|
||||||
from dzgui.views.components.mod_panel import ModSelectionPanel
|
from dzgui.views.components.mod_panel import ModSelectionPanel
|
||||||
from dzgui.views.components.buttons import RefreshButton, KeysButton
|
from dzgui.views.components.buttons import IconTextButton, RefreshButton, KeysButton
|
||||||
from dzgui.const.constants import NO_EXPAND, NO_FILL, FILL, NO_PADDING
|
|
||||||
|
|
||||||
import gi
|
import gi
|
||||||
|
|
||||||
@@ -40,14 +42,17 @@ class RightPanel(Gtk.Box):
|
|||||||
|
|
||||||
self.copying = False
|
self.copying = False
|
||||||
|
|
||||||
# TODO: strings
|
prefs = self.controller.get_prefs()
|
||||||
version = self.controller.get_prefs().version
|
version = prefs.version
|
||||||
|
update = prefs.update_available
|
||||||
|
|
||||||
self.version_label = Gtk.Label(
|
self.version_label = Gtk.Label(
|
||||||
label=version,
|
label=version,
|
||||||
hexpand=True,
|
hexpand=True,
|
||||||
vexpand=True,
|
vexpand=True,
|
||||||
halign=Gtk.Align.END,
|
halign=Gtk.Align.END,
|
||||||
valign=Gtk.Align.END,
|
valign=Gtk.Align.END,
|
||||||
|
# TODO: strings
|
||||||
tooltip_text="Click to copy to clipboard",
|
tooltip_text="Click to copy to clipboard",
|
||||||
)
|
)
|
||||||
eb = Gtk.EventBox(halign=Gtk.Align.END, valign=Gtk.Align.END)
|
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(el, NO_EXPAND, FILL, NO_PADDING)
|
||||||
|
|
||||||
self.pack_start(self.sel_panel, NO_EXPAND, NO_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(
|
def _on_server_page_changed(
|
||||||
self, emitter: "Emitter", page: "ServerTreeView"
|
self, emitter: "Emitter", page: "ServerTreeView"
|
||||||
|
|||||||
Reference in new issue
Block a user