2022-02-25 23:58:11 +00:00
|
|
|
# Python imports
|
2023-04-29 14:44:22 +00:00
|
|
|
import signal
|
2022-11-29 04:34:13 +00:00
|
|
|
import os
|
2022-02-25 23:58:11 +00:00
|
|
|
|
|
|
|
# Lib imports
|
|
|
|
|
|
|
|
# Application imports
|
2023-04-29 14:44:22 +00:00
|
|
|
from utils.debugging import debug_signal_handler
|
2022-08-13 03:54:16 +00:00
|
|
|
from utils.ipc_server import IPCServer
|
2023-02-24 05:03:29 +00:00
|
|
|
from core.window import Window
|
2022-02-25 23:58:11 +00:00
|
|
|
|
|
|
|
|
2023-04-29 14:44:22 +00:00
|
|
|
|
2022-10-02 03:12:14 +00:00
|
|
|
class AppLaunchException(Exception):
|
2022-09-05 06:01:51 +00:00
|
|
|
...
|
|
|
|
|
|
|
|
|
2023-11-13 05:25:46 +00:00
|
|
|
|
2024-01-09 03:11:10 +00:00
|
|
|
class Application:
|
2023-04-29 14:44:22 +00:00
|
|
|
""" docstring for Application. """
|
2022-02-25 23:58:11 +00:00
|
|
|
|
|
|
|
def __init__(self, args, unknownargs):
|
2022-08-13 03:54:16 +00:00
|
|
|
super(Application, self).__init__()
|
2022-10-10 01:59:44 +00:00
|
|
|
|
2023-07-30 04:42:59 +00:00
|
|
|
if not settings_manager.is_trace_debug():
|
2024-01-09 03:11:10 +00:00
|
|
|
self.load_ipc(args, unknownargs)
|
2022-02-25 23:58:11 +00:00
|
|
|
|
2023-10-19 02:23:45 +00:00
|
|
|
self.setup_debug_hook()
|
2024-01-04 02:36:17 +00:00
|
|
|
Window(args, unknownargs).main()
|
2023-10-19 02:23:45 +00:00
|
|
|
|
|
|
|
|
2024-01-09 03:11:10 +00:00
|
|
|
def load_ipc(self, args, unknownargs):
|
|
|
|
ipc_server = IPCServer()
|
|
|
|
self.ipc_realization_check(ipc_server)
|
|
|
|
|
|
|
|
if not ipc_server.is_ipc_alive:
|
|
|
|
for arg in unknownargs + [args.new_tab,]:
|
|
|
|
if os.path.isfile(arg):
|
|
|
|
message = f"FILE|{arg}"
|
|
|
|
ipc_server.send_ipc_message(message)
|
|
|
|
|
|
|
|
raise AppLaunchException(f"{app_name} IPC Server Exists: Have sent path(s) to it and closing...")
|
|
|
|
|
|
|
|
def ipc_realization_check(self, ipc_server):
|
2023-10-19 02:51:24 +00:00
|
|
|
try:
|
2024-01-09 03:11:10 +00:00
|
|
|
ipc_server.create_ipc_listener()
|
2023-10-19 02:51:24 +00:00
|
|
|
except Exception:
|
2024-01-09 03:11:10 +00:00
|
|
|
ipc_server.send_test_ipc_message()
|
2023-10-19 02:51:24 +00:00
|
|
|
|
|
|
|
try:
|
2024-01-09 03:11:10 +00:00
|
|
|
ipc_server.create_ipc_listener()
|
2023-10-19 02:51:24 +00:00
|
|
|
except Exception as e:
|
|
|
|
...
|
2023-10-19 02:23:45 +00:00
|
|
|
|
|
|
|
def setup_debug_hook(self):
|
2023-04-29 14:44:22 +00:00
|
|
|
try:
|
|
|
|
# kill -SIGUSR2 <pid> from Linux/Unix or SIGBREAK signal from Windows
|
|
|
|
signal.signal(
|
|
|
|
vars(signal).get("SIGBREAK") or vars(signal).get("SIGUSR1"),
|
|
|
|
debug_signal_handler
|
|
|
|
)
|
|
|
|
except ValueError:
|
|
|
|
# Typically: ValueError: signal only works in main thread
|
2023-11-13 05:25:46 +00:00
|
|
|
...
|