diff --git a/pyproject.toml b/pyproject.toml index 1a0659f..1508b1e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "simonsays_drgreengiant" -version = "2.0.0" +version = "2.0.1" authors = [{ name = "Simon Howroyd", email = "howroydlsu@gmail.com" }] description = "A Twitch Plays style programme to allow users in Twitch chats to control the broadcasters mouse and keyboard" keywords = ["twitch", "chat", "twitchplays", "troll"] diff --git a/requirements.txt b/requirements.txt index 16423fb..0fd441e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,6 @@ Pillow pynput +requests +semantic-version tomlkit twitchirc_drgreengiant \ No newline at end of file diff --git a/src/simonsays_drgreengiant/gui.py b/src/simonsays_drgreengiant/gui.py index f41b53b..2aa0cf4 100644 --- a/src/simonsays_drgreengiant/gui.py +++ b/src/simonsays_drgreengiant/gui.py @@ -8,6 +8,8 @@ from collections.abc import Iterable from typing import Any, Callable, NoReturn, Optional +import semantic_version + from . import config, environment, hidactions KEY_IGNORED_STR = 'ignored' @@ -171,7 +173,7 @@ def make_window(cfg: config.Config, width_px: int, height_px: int) -> tk.Tk: return window -def make_canvas(cfg: config.Config, image_path: str, *, window: tk.Tk | None = None) -> tk.Canvas: +def make_canvas(cfg: config.Config, image_path: str, updateavailable: semantic_version = None, *, window: tk.Tk | None = None) -> tk.Canvas: """Make the canvas with a background image""" # img = tk.PhotoImage(file=image_path) from PIL import Image @@ -187,7 +189,13 @@ def make_canvas(cfg: config.Config, image_path: str, *, window: tk.Tk | None = N canvas.image = img # Keep a reference to the image to prevent garbage collection channels = "\n".join(cfg.channel) canvas.create_text((5, 5), text=f"Connected to channels:\n{channels}", anchor=tk.N + tk.W) - canvas.create_text((img.width() - 5, 5), text=f"Version: {cfg.version}", anchor=tk.N + tk.E) + + versiontext = f"Version: {cfg.version}" + if updateavailable: + versiontext += "\nNew version available!" + versiontext += f"\nLatest version: {updateavailable}" + + canvas.create_text((img.width() - 5, 5), text=versiontext, anchor=tk.N + tk.E) window.update() @@ -490,9 +498,9 @@ def enabled_cb(cfg: config.Config, enabled_button: tk.Button, state_var: tk.Bool print("Enabled") -def make_gui(cfg: config.Config) -> tuple[tk.Tk, mp.Event, Callable]: +def make_gui(cfg: config.Config, updateavailable: semantic_version.Version = None) -> tuple[tk.Tk, mp.Event, Callable]: """Make the GUI""" - canvas = make_canvas(cfg, environment.resource_path("assets", "Green_tato_640.png")) + canvas = make_canvas(cfg, environment.resource_path("assets", "Green_tato_640.png"), updateavailable) window = canvas.winfo_toplevel() triggerredraw = mp.Event() diff --git a/src/simonsays_drgreengiant/simonsays.py b/src/simonsays_drgreengiant/simonsays.py index 8593735..5ad87dc 100644 --- a/src/simonsays_drgreengiant/simonsays.py +++ b/src/simonsays_drgreengiant/simonsays.py @@ -5,6 +5,8 @@ import pprint from typing import NoReturn +import requests +import semantic_version from twitchirc_drgreengiant import offlineirc, twitchirc from . import config, environment, errorcodes, gui, twitchactions @@ -100,6 +102,15 @@ def get_action_from_message(myconfig: config.Config, msg: twitchirc.TwitchMessag return functools.partial(myconfig.actions[tag].run, force=sudo), tag +def check_for_updates() -> semantic_version.Version | None: + latest = requests.get("https://api.github.com/repos/howroyd/simonsays/releases/latest") + latestversion = semantic_version.Version(latest.json()["tag_name"].lstrip("v")) + thisversion = semantic_version.Version.coerce(VERSION.lstrip("v")) + if latestversion > thisversion: + return latestversion + return None + + def main() -> NoReturn: myconfig = config.Config.load(VERSION) myconfig.save(backup_old=True) @@ -109,16 +120,20 @@ def main() -> NoReturn: with contextlib.ExitStack() as stack: executor = stack.enter_context(cf.ThreadPoolExecutor(max_workers=1)) + updateavailable = None irc = None if config.OFFLINE: print("OFFLINE MODE") irc = stack.enter_context(offlineirc.OfflineIrc(myconfig.channel, username="drgreengiant")) else: + if updateavailable := check_for_updates(): + print(f"Update available! Current version: {VERSION}, Latest version: {updateavailable}") + print("https://github.com/howroyd/simonsays/releases/tag/2.0.0\n\n") irc = stack.enter_context(twitchirc.TwitchIrc(myconfig.channel)) print(channel_connected(myconfig)) - mygui, exit_event, redraw_gui = gui.make_gui(myconfig) + mygui, exit_event, redraw_gui = gui.make_gui(myconfig, updateavailable=updateavailable) while True: redraw_gui() # Required otherwise you can't click stuff