Files
SolarFM/src/solarfm/app.py

73 lines
1.8 KiB
Python
Raw Normal View History

# Python imports
2023-04-29 09:44:22 -05:00
import signal
import os
# Lib imports
# Application imports
2023-04-29 09:44:22 -05:00
from utils.debugging import debug_signal_handler
from utils.ipc_server import IPCServer
from core.window import Window
2023-04-29 09:44:22 -05:00
class AppLaunchException(Exception):
...
class Application:
2023-04-29 09:44:22 -05:00
""" docstring for Application. """
def __init__(self):
super(Application, self).__init__()
self.setup_debug_hook()
def run(self):
if not settings_manager.is_trace_debug():
if not self.load_ipc():
return
win = Window()
win.start()
def load_ipc(self):
args, \
unknownargs = settings_manager.get_starting_args()
ipc_server = IPCServer()
self.ipc_realization_check(ipc_server)
if ipc_server.is_ipc_alive:
return True
logger.warning(f"{app_name} IPC Server Exists: Have sent path(s) to it and closing...")
for arg in unknownargs + [args.new_tab,]:
if os.path.isfile(arg):
message = f"FILE|{arg}"
ipc_server.send_ipc_message(message)
if os.path.isdir(arg):
message = f"DIR|{arg}"
ipc_server.send_ipc_message(message)
return False
def ipc_realization_check(self, ipc_server):
2023-10-18 21:51:24 -05:00
try:
ipc_server.create_ipc_listener()
except Exception as e:
ipc_server.send_test_ipc_message()
2023-10-18 21:51:24 -05:00
def setup_debug_hook(self):
2023-04-29 09:44:22 -05:00
try:
# kill -SIGUSR2 <pid> from Linux/Unix or SIGBREAK signal from Windows
signal.signal(
vars(signal).get("SIGBREAK") or vars(signal).get("SIGUSR2"),
2023-04-29 09:44:22 -05:00
debug_signal_handler
)
except ValueError:
# Typically: ValueError: signal only works in main thread
...