2023-03-18 04:17:38 +00:00
|
|
|
# Python imports
|
2023-10-19 02:15:36 +00:00
|
|
|
import signal
|
2023-03-18 04:17:38 +00:00
|
|
|
import os
|
|
|
|
|
|
|
|
# Lib imports
|
|
|
|
|
|
|
|
# Application imports
|
2023-10-19 02:15:36 +00:00
|
|
|
from utils.debugging import debug_signal_handler
|
2023-03-18 04:17:38 +00:00
|
|
|
from utils.ipc_server import IPCServer
|
|
|
|
from core.window import Window
|
|
|
|
|
|
|
|
|
2023-10-07 19:51:12 +00:00
|
|
|
|
2023-03-18 04:17:38 +00:00
|
|
|
class AppLaunchException(Exception):
|
|
|
|
...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Application(IPCServer):
|
2023-11-12 07:10:27 +00:00
|
|
|
""" docstring for Application. """
|
2023-03-18 04:17:38 +00:00
|
|
|
|
|
|
|
def __init__(self, args, unknownargs):
|
|
|
|
super(Application, self).__init__()
|
2023-11-12 07:10:27 +00:00
|
|
|
|
2023-10-03 23:22:36 +00:00
|
|
|
if not settings_manager.is_trace_debug():
|
2023-10-19 02:53:28 +00:00
|
|
|
self.socket_realization_check()
|
2023-03-18 04:17:38 +00:00
|
|
|
|
|
|
|
if not self.is_ipc_alive:
|
|
|
|
for arg in unknownargs + [args.new_tab,]:
|
2023-03-26 06:07:35 +00:00
|
|
|
if os.path.isfile(arg):
|
2023-03-18 04:17:38 +00:00
|
|
|
message = f"FILE|{arg}"
|
|
|
|
self.send_ipc_message(message)
|
|
|
|
|
2023-11-12 07:10:27 +00:00
|
|
|
raise AppLaunchException(f"{app_name} IPC Server Exists: Have sent path(s) to it and closing...")
|
2023-03-18 04:17:38 +00:00
|
|
|
|
2023-10-19 02:15:36 +00:00
|
|
|
self.setup_debug_hook()
|
2023-10-09 06:23:08 +00:00
|
|
|
Window(args, unknownargs)
|
2023-10-19 02:15:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
def socket_realization_check(self):
|
2023-10-19 02:53:28 +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:15:36 +00:00
|
|
|
|
|
|
|
def setup_debug_hook(self):
|
|
|
|
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-12 07:10:27 +00:00
|
|
|
...
|