mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-06-03 09:01:13 +03:00
EDMarketConnector: popup for "already running"
* This also refactors code around so that isort and flake8 are happy about the module level imports.
This commit is contained in:
parent
c6083a2643
commit
bc3269f2f8
@ -18,7 +18,8 @@ from typing import TYPE_CHECKING, Any, Mapping, Optional, Tuple
|
||||
|
||||
from constants import applongname, appname, protocolhandler_redirect
|
||||
|
||||
def no_other_instance_running() -> bool: # noqa: CCR001
|
||||
if __name__ == "__main__":
|
||||
def no_other_instance_running() -> bool: # noqa: CCR001
|
||||
"""
|
||||
Ensure only one copy of the app is running under this user account.
|
||||
|
||||
@ -86,7 +87,27 @@ def no_other_instance_running() -> bool: # noqa: CCR001
|
||||
|
||||
return EnumWindows(enumwindowsproc, 0)
|
||||
|
||||
if __name__ == "__main__":
|
||||
return True
|
||||
|
||||
def already_running_popup():
|
||||
"""Create the "already running" popup."""
|
||||
import tkinter as tk
|
||||
from tkinter import ttk
|
||||
|
||||
root = tk.Tk(className=appname.lower())
|
||||
|
||||
frame = tk.Frame(root)
|
||||
frame.grid(row=1, column=0, sticky=tk.NSEW)
|
||||
|
||||
label = tk.Label(frame)
|
||||
label['text'] = 'An EDMarketConnector.exe process was already running, exiting.'
|
||||
label.grid(row=1, column=0, sticky=tk.NSEW)
|
||||
|
||||
button = ttk.Button(frame, text='OK', command=lambda: sys.exit(0))
|
||||
button.grid(row=2, column=0, sticky=tk.S)
|
||||
|
||||
root.mainloop()
|
||||
|
||||
if not no_other_instance_running():
|
||||
# There's a copy already running. We want to inform the user by
|
||||
# **appending** to the log file, not truncating it.
|
||||
@ -97,9 +118,15 @@ if __name__ == "__main__":
|
||||
# unbuffered not allowed for text in python3, so use `1 for line buffering
|
||||
sys.stdout = sys.stderr = open(join(tempfile.gettempdir(), f'{appname}.log'), mode='a', buffering=1)
|
||||
|
||||
# Logging isn't set up yet
|
||||
# Logging isn't set up yet.
|
||||
# We'll keep this print, but it will be over-written by any subsequent
|
||||
# write by the already-running process.
|
||||
print("An EDMarketConnector.exe process was already running, exiting.")
|
||||
|
||||
# To be sure the user knows, we need a popup
|
||||
already_running_popup()
|
||||
# If the user closes the popup with the 'X', not the 'OK' button we'll
|
||||
# reach here.
|
||||
sys.exit(0)
|
||||
|
||||
# Keep this as the very first code run to be as sure as possible of no
|
||||
@ -306,7 +333,6 @@ if TYPE_CHECKING:
|
||||
"""Fake the l10n translation functions for typing."""
|
||||
return x
|
||||
|
||||
|
||||
if getattr(sys, 'frozen', False):
|
||||
# Under py2exe sys.path[0] is the executable name
|
||||
if platform == 'win32':
|
||||
|
Loading…
x
Reference in New Issue
Block a user