diff --git a/constants.py b/constants.py index f5e94ac..a099154 100644 --- a/constants.py +++ b/constants.py @@ -6,6 +6,9 @@ from enum import Enum, auto from datetime import timedelta from typing import Any, Optional, Dict, Literal, Callable +from version import __version__ + + # Typing JsonType = Dict[str, Any] TopicProcess = Callable[[int, JsonType], Any] @@ -32,8 +35,10 @@ PING_INTERVAL = timedelta(minutes=3) PING_TIMEOUT = timedelta(seconds=10) ONLINE_DELAY = timedelta(seconds=120) WATCH_INTERVAL = timedelta(seconds=58.8) -# Tags +# Strings DROPS_ENABLED_TAG = "c2542d6d-cd10-4532-919b-3d19f30a768b" +WINDOW_TITLE = f"Twitch Drops Miner v{__version__} (by DevilXD)" +# Logging FORMATTER = logging.Formatter( "{asctime}.{msecs:03.0f}:\t{levelname:>7}:\t{message}", style='{', diff --git a/gui.py b/gui.py index aed4c66..9837796 100644 --- a/gui.py +++ b/gui.py @@ -18,8 +18,7 @@ try: except ModuleNotFoundError as exc: raise ImportError("You have to run 'pip install pystray' first") from exc -from version import __version__ -from constants import FORMATTER, WS_TOPICS_LIMIT, MAX_WEBSOCKETS, State +from constants import FORMATTER, WS_TOPICS_LIMIT, MAX_WEBSOCKETS, WINDOW_TITLE, State if TYPE_CHECKING: from twitch import Twitch @@ -781,7 +780,7 @@ class GUIManager: self._root.withdraw() root.resizable(False, True) root.iconbitmap(resource_path("pickaxe.ico")) # window icon - root.title(f"Twitch Drops Miner v{__version__} (by DevilXD)") # window title + root.title(WINDOW_TITLE) # window title root.protocol("WM_DELETE_WINDOW", self.close) root.bind_all("", self.unfocus) self._style = ttk.Style(root) diff --git a/main.py b/main.py index 18c74ee..9accc57 100644 --- a/main.py +++ b/main.py @@ -1,12 +1,13 @@ from __future__ import annotations +import ctypes import logging import argparse from typing import Optional from twitch import Twitch from version import __version__ -from constants import FORMATTER, LOG_PATH +from constants import FORMATTER, LOG_PATH, WINDOW_TITLE class ParsedArgs(argparse.Namespace): @@ -48,6 +49,15 @@ class ParsedArgs(argparse.Namespace): return logging.NOTSET +# check if we're not already running +try: + exists = ctypes.windll.user32.FindWindowW(None, WINDOW_TITLE) +except AttributeError: + # we're not on Windows - continue + exists = False +if exists: + # already running - exit + quit() # handle input parameters parser = argparse.ArgumentParser( "Twitch Drops Miner (by DevilXD).exe",