2022-02-25 23:53:58 +00:00
|
|
|
# Python imports
|
2023-04-29 14:27:21 +00:00
|
|
|
import signal
|
2022-10-14 01:58:44 +00:00
|
|
|
import os
|
2022-02-25 23:53:58 +00:00
|
|
|
|
|
|
|
# Lib imports
|
|
|
|
|
|
|
|
# Application imports
|
2023-04-29 14:40:09 +00:00
|
|
|
from utils.debugging import debug_signal_handler
|
2022-09-05 23:01:39 +00:00
|
|
|
from utils.ipc_server import IPCServer
|
2022-10-14 01:58:44 +00:00
|
|
|
from core.window import Window
|
2022-02-25 23:53:58 +00:00
|
|
|
|
|
|
|
|
2023-04-29 14:27:21 +00:00
|
|
|
|
2022-10-14 01:58:44 +00:00
|
|
|
class AppLaunchException(Exception):
|
2022-09-05 23:01:39 +00:00
|
|
|
...
|
2022-02-25 23:53:58 +00:00
|
|
|
|
|
|
|
|
2022-09-05 23:01:39 +00:00
|
|
|
class Application(IPCServer):
|
2023-03-28 02:25:54 +00:00
|
|
|
""" docstring for Application. """
|
2022-02-25 23:53:58 +00:00
|
|
|
|
|
|
|
def __init__(self, args, unknownargs):
|
2022-09-05 23:01:39 +00:00
|
|
|
super(Application, self).__init__()
|
2023-04-29 14:27:21 +00:00
|
|
|
|
2023-07-30 05:36:52 +00:00
|
|
|
if not settings_manager.is_trace_debug():
|
2023-10-19 02:52:45 +00:00
|
|
|
self.socket_realization_check()
|
2022-09-05 23:01:39 +00:00
|
|
|
|
|
|
|
if not self.is_ipc_alive:
|
2022-10-23 04:26:13 +00:00
|
|
|
for arg in unknownargs + [args.new_tab,]:
|
2023-03-28 02:25:54 +00:00
|
|
|
if os.path.isfile(arg):
|
2022-10-23 04:26:13 +00:00
|
|
|
message = f"FILE|{arg}"
|
|
|
|
self.send_ipc_message(message)
|
2022-02-25 23:53:58 +00:00
|
|
|
|
2022-10-23 04:26:13 +00:00
|
|
|
raise AppLaunchException(f"{app_name} IPC Server Exists: Will send path(s) to it and close...")
|
2022-02-25 23:53:58 +00:00
|
|
|
|
2023-10-19 02:02:46 +00:00
|
|
|
self.setup_debug_hook()
|
|
|
|
Window(args, unknownargs)
|
|
|
|
|
|
|
|
|
|
|
|
def socket_realization_check(self):
|
2023-10-19 02:52:45 +00:00
|
|
|
try:
|
|
|
|
self.create_ipc_listener()
|
|
|
|
except Exception:
|
|
|
|
self.send_test_ipc_message()
|
|
|
|
|
|
|
|
try:
|
|
|
|
self.create_ipc_listener()
|
|
|
|
except Exception as e:
|
|
|
|
...
|
2023-10-19 02:02:46 +00:00
|
|
|
|
|
|
|
def setup_debug_hook(self):
|
2023-04-29 14:27:21 +00:00
|
|
|
try:
|
2023-04-29 14:40:09 +00:00
|
|
|
# kill -SIGUSR2 <pid> from Linux/Unix or SIGBREAK signal from Windows
|
2023-04-29 14:27:21 +00:00
|
|
|
signal.signal(
|
2023-04-29 14:40:09 +00:00
|
|
|
vars(signal).get("SIGBREAK") or vars(signal).get("SIGUSR1"),
|
|
|
|
debug_signal_handler
|
|
|
|
)
|
2023-04-29 14:27:21 +00:00
|
|
|
except ValueError:
|
|
|
|
# Typically: ValueError: signal only works in main thread
|
|
|
|
...
|