Quit if the application is already running
This commit is contained in:
1 parent
b6229163bf
commit
fd030e33f6
3 files changed
+19
-5
No files matched your search
+6
-1
@@ -6,6 +6,9 @@ from enum import Enum, auto
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from typing import Any, Optional, Dict, Literal, Callable
|
from typing import Any, Optional, Dict, Literal, Callable
|
||||||
|
|
||||||
|
from version import __version__
|
||||||
|
|
||||||
|
|
||||||
# Typing
|
# Typing
|
||||||
JsonType = Dict[str, Any]
|
JsonType = Dict[str, Any]
|
||||||
TopicProcess = Callable[[int, JsonType], Any]
|
TopicProcess = Callable[[int, JsonType], Any]
|
||||||
@@ -32,8 +35,10 @@ PING_INTERVAL = timedelta(minutes=3)
|
|||||||
PING_TIMEOUT = timedelta(seconds=10)
|
PING_TIMEOUT = timedelta(seconds=10)
|
||||||
ONLINE_DELAY = timedelta(seconds=120)
|
ONLINE_DELAY = timedelta(seconds=120)
|
||||||
WATCH_INTERVAL = timedelta(seconds=58.8)
|
WATCH_INTERVAL = timedelta(seconds=58.8)
|
||||||
# Tags
|
# Strings
|
||||||
DROPS_ENABLED_TAG = "c2542d6d-cd10-4532-919b-3d19f30a768b"
|
DROPS_ENABLED_TAG = "c2542d6d-cd10-4532-919b-3d19f30a768b"
|
||||||
|
WINDOW_TITLE = f"Twitch Drops Miner v{__version__} (by DevilXD)"
|
||||||
|
# Logging
|
||||||
FORMATTER = logging.Formatter(
|
FORMATTER = logging.Formatter(
|
||||||
"{asctime}.{msecs:03.0f}:\t{levelname:>7}:\t{message}",
|
"{asctime}.{msecs:03.0f}:\t{levelname:>7}:\t{message}",
|
||||||
style='{',
|
style='{',
|
||||||
|
|||||||
@@ -18,8 +18,7 @@ try:
|
|||||||
except ModuleNotFoundError as exc:
|
except ModuleNotFoundError as exc:
|
||||||
raise ImportError("You have to run 'pip install pystray' first") from 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, WINDOW_TITLE, State
|
||||||
from constants import FORMATTER, WS_TOPICS_LIMIT, MAX_WEBSOCKETS, State
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from twitch import Twitch
|
from twitch import Twitch
|
||||||
@@ -781,7 +780,7 @@ class GUIManager:
|
|||||||
self._root.withdraw()
|
self._root.withdraw()
|
||||||
root.resizable(False, True)
|
root.resizable(False, True)
|
||||||
root.iconbitmap(resource_path("pickaxe.ico")) # window icon
|
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.protocol("WM_DELETE_WINDOW", self.close)
|
||||||
root.bind_all("<KeyPress-Escape>", self.unfocus)
|
root.bind_all("<KeyPress-Escape>", self.unfocus)
|
||||||
self._style = ttk.Style(root)
|
self._style = ttk.Style(root)
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import ctypes
|
||||||
import logging
|
import logging
|
||||||
import argparse
|
import argparse
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from twitch import Twitch
|
from twitch import Twitch
|
||||||
from version import __version__
|
from version import __version__
|
||||||
from constants import FORMATTER, LOG_PATH
|
from constants import FORMATTER, LOG_PATH, WINDOW_TITLE
|
||||||
|
|
||||||
|
|
||||||
class ParsedArgs(argparse.Namespace):
|
class ParsedArgs(argparse.Namespace):
|
||||||
@@ -48,6 +49,15 @@ class ParsedArgs(argparse.Namespace):
|
|||||||
return logging.NOTSET
|
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
|
# handle input parameters
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
"Twitch Drops Miner (by DevilXD).exe",
|
"Twitch Drops Miner (by DevilXD).exe",
|
||||||
|
|||||||
Reference in new issue
Block a user