From e7f937ecd2103547424d38705365c3919031e963 Mon Sep 17 00:00:00 2001 From: Timmy Welch Date: Thu, 24 Nov 2022 09:59:40 -0800 Subject: [PATCH] Enable version checking --- comictaggerlib/taggerwindow.py | 12 +++++------ comictaggerlib/versionchecker.py | 34 +++++++++++--------------------- 2 files changed, 18 insertions(+), 28 deletions(-) diff --git a/comictaggerlib/taggerwindow.py b/comictaggerlib/taggerwindow.py index f7c783a..9aaf9c5 100644 --- a/comictaggerlib/taggerwindow.py +++ b/comictaggerlib/taggerwindow.py @@ -262,7 +262,7 @@ Have fun! self.settings.show_disclaimer = not checked if self.settings.check_for_new_version: - pass + self.check_latest_version_online() def open_file_event(self, url: QtCore.QUrl) -> None: logger.info(url.toLocalFile()) @@ -2121,19 +2121,19 @@ Have fun! version_checker.get_latest_version(self.settings.install_id, self.settings.send_usage_stats) ) - def version_check_complete(self, new_version: str) -> None: - if new_version not in (self.version, self.settings.dont_notify_about_this_version): + def version_check_complete(self, new_version: tuple[str, str]) -> None: + if new_version[0] not in (self.version, self.settings.dont_notify_about_this_version): website = "https://github.com/comictagger/comictagger" checked = OptionalMessageDialog.msg( self, "New version available!", - f"New version ({new_version}) available!
(You are currently running {self.version})

" - f"Visit {website} for more info.

", + f"New version ({new_version[1]}) available!
(You are currently running {self.version})

" + f"Visit {website}/releases/latest for more info.

", False, "Don't tell me about this version again", ) if checked: - self.settings.dont_notify_about_this_version = new_version + self.settings.dont_notify_about_this_version = new_version[0] def on_incoming_socket_connection(self) -> None: # Accept connection from other instance. diff --git a/comictaggerlib/versionchecker.py b/comictaggerlib/versionchecker.py index 5a0f7ce..ce197f3 100644 --- a/comictaggerlib/versionchecker.py +++ b/comictaggerlib/versionchecker.py @@ -16,8 +16,6 @@ from __future__ import annotations import logging -import platform -import sys import requests @@ -29,31 +27,23 @@ logger = logging.getLogger(__name__) class VersionChecker: def get_request_url(self, uuid: str, use_stats: bool) -> tuple[str, dict[str, str]]: - base_url = "http://comictagger1.appspot.com/latest" - params = {} - if use_stats: - params = {"uuid": uuid, "version": ctversion.version} - if platform.system() == "Windows": - params["platform"] = "win" - elif platform.system() == "Linux": - params["platform"] = "lin" - elif platform.system() == "Darwin": - params["platform"] = "mac" - else: - params["platform"] = "other" - - if not getattr(sys, "frozen", None): - params["src"] = "T" + base_url = "https://api.github.com/repos/comictagger/comictagger/releases/latest" + params: dict[str, str] = {} return base_url, params - def get_latest_version(self, uuid: str, use_stats: bool = True) -> str: + def get_latest_version(self, uuid: str, use_stats: bool = True) -> tuple[str, str]: try: url, params = self.get_request_url(uuid, use_stats) - new_version = requests.get(url, params=params).text + release = requests.get( + url, + params=params, + headers={"user-agent": "comictagger/" + ctversion.version}, + ).json() except Exception: - return "" + return ("", "") + new_version = release["tag_name"] if new_version is None or new_version == "": - return "" - return new_version.strip() + return ("", "") + return (new_version.strip(), release["name"])