diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 11348c0ad..af7a2b665 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -11,9 +11,11 @@ import argparse import html import locale +import os import pathlib import queue import re +import signal import subprocess import sys import threading @@ -335,29 +337,13 @@ def enumwindowsproc(window_handle, l_param): # noqa: CCR001 def already_running_popup(): """Create the "already running" popup.""" - import tkinter as tk - from tkinter import ttk + from tkinter import messagebox # Check for CL arg that suppresses this popup. if args.suppress_dupe_process_popup: sys.exit(0) - root = tk.Tk(className=appname.lower()) - - frame = tk.Frame(root) - frame.grid(row=1, column=0, sticky=tk.NSEW) - - label = tk.Label(frame, 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) - - try: - root.mainloop() - except KeyboardInterrupt: - logger.info("Ctrl+C Detected, Attempting Clean Shutdown") - sys.exit() - logger.info('Exiting') + messagebox.showerror(title=appname, message="An EDMarketConnector process was already running, exiting.") + sys.exit(0) journal_lock = JournalLock() locked = journal_lock.obtain_lock() @@ -2226,7 +2212,29 @@ def test_prop(self): if theme.default_ui_scale is not None: root.tk.call('tk', 'scaling', theme.default_ui_scale * float(ui_scale) / 100.0) - app = AppWindow(root) + try: + app = AppWindow(root) + except Exception as err: + logger.exception(f"EDMC Critical Error: {err}") + title = tr.tl("Error") # LANG: Generic error prefix + message = tr.tl( # LANG: EDMC Critical Error Notification + "EDSM encountered a critical error, and cannot recover. EDMC is shutting down for its own protection!" + ) + err = f"{err.__class__.__name__}: {err}" # type: ignore # hijacking the existing exception detection + detail = tr.tl( # LANG: EDMC Critical Error Details + r"Here's what EDMC Detected:\r\n\r\n{ERR}\r\n\r\nDo you want to file a Bug Report on GitHub?" + ).format(ERR=err) + detail = detail.replace('\\n', '\n') + detail = detail.replace('\\r', '\r') + msg = tk.messagebox.askyesno( + title=title, message=message, detail=detail, icon=tkinter.messagebox.ERROR, type=tkinter.messagebox.YESNO + ) + if msg: + webbrowser.open( + "https://github.com/EDCD/EDMarketConnector/issues/new?" + "assignees=&labels=bug%2C+unconfirmed&projects=&template=bug_report.md&title=" + ) + os.kill(os.getpid(), signal.SIGTERM) def messagebox_broken_plugins(): """Display message about 'broken' plugins that failed to load.""" diff --git a/L10n/en.template b/L10n/en.template index 200743c82..b2c46d7cf 100644 --- a/L10n/en.template +++ b/L10n/en.template @@ -36,6 +36,12 @@ /* companion.py: Failed to get Access Token from Frontier Auth service; In files: companion.py:508; */ "Error: unable to get token" = "Error: unable to get token"; +/* EDMarketConnector.py: EDMC Critical Error Notification; */ +"EDSM encountered a critical error, and cannot recover. EDMC is shutting down for its own protection!" = "EDSM encountered a critical error, and cannot recover. EDMC is shutting down for its own protection!"; + +/* EDMarketConnector.py: EDMC Critical Error Details; */ +"Here's what EDMC Detected:\r\n\r\n{ERR}\r\n\r\nDo you want to file a Bug Report on GitHub?" = "Here's what EDMC Detected:\r\n\r\n{ERR}\r\n\r\nDo you want to file a Bug Report on GitHub?"; + /* companion.py: Frontier CAPI returned 418, meaning down for maintenance; In files: companion.py:844; */ "Frontier CAPI down for maintenance" = "Frontier CAPI down for maintenance";