Quit if the application is already running

This commit is contained in:
DevilXD
2022-01-14 15:10:36 +01:00
parent b6229163bf
commit fd030e33f6
3 changed files with 19 additions and 5 deletions

View File

@@ -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='{',

5
gui.py
View File

@@ -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("<KeyPress-Escape>", self.unfocus)
self._style = ttk.Style(root)

12
main.py
View File

@@ -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",