-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdesktop_app.py
More file actions
72 lines (58 loc) · 2.02 KB
/
Copy pathdesktop_app.py
File metadata and controls
72 lines (58 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
"""Cross-platform desktop entry point for UnityScraper."""
from __future__ import annotations
import sys
import traceback
from app_paths import LOG_DIR, ensure_app_dirs, ensure_user_titleids_file
def _write_startup_report(exc: BaseException) -> str:
details = "".join(traceback.format_exception(type(exc), exc, exc.__traceback__))
try:
(LOG_DIR / "fatal_startup.log").write_text(details, encoding="utf-8")
except OSError:
pass
return details
def main() -> int:
"""Initialize writable storage and launch the desktop application."""
if len(sys.argv) > 1 and sys.argv[1] == "--plugin-worker":
from plugin_worker import main as plugin_worker_main
return plugin_worker_main(sys.argv[2:])
ensure_app_dirs()
ensure_user_titleids_file()
try:
import tkinter as tk
from modern_gui import main as gui_main
except ImportError as exc:
details = _write_startup_report(exc)
print(
"UnityScraper requires Tkinter. On Debian/Ubuntu install python3-tk; "
"on Fedora install python3-tkinter.",
file=sys.stderr,
)
print(details, file=sys.stderr)
return 1
try:
gui_main()
except tk.TclError as exc:
details = _write_startup_report(exc)
print(
"UnityScraper could not connect to a graphical desktop. "
"Start it from an X11 or Wayland session.",
file=sys.stderr,
)
print(details, file=sys.stderr)
return 1
except Exception as exc:
report = LOG_DIR / "fatal_startup.log"
details = _write_startup_report(exc)
try:
from tkinter import messagebox
messagebox.showerror(
"UnityScraper could not start",
f"A startup report was written to:\n{report}\n\n{exc}",
)
except tk.TclError:
pass
print(details, file=sys.stderr)
return 1
return 0
if __name__ == "__main__":
raise SystemExit(main())