small refactoring
This commit is contained in:
parent
75da08d081
commit
efa42a301c
|
@ -35,6 +35,13 @@ if __name__ == "__main__":
|
|||
# Read arguments (If any...)
|
||||
args, unknownargs = parser.parse_known_args()
|
||||
|
||||
if args.debug == "true":
|
||||
settings.set_debug(True)
|
||||
|
||||
if args.trace_debug == "true":
|
||||
settings.set_trace_debug(True)
|
||||
|
||||
settings.do_dirty_start_check()
|
||||
Application(args, unknownargs)
|
||||
Gtk.main()
|
||||
except Exception as e:
|
||||
|
|
|
@ -1,57 +1,50 @@
|
|||
# Python imports
|
||||
import os, inspect, time
|
||||
import os, inspect
|
||||
|
||||
# Lib imports
|
||||
|
||||
# Application imports
|
||||
|
||||
from utils.ipc_server import IPCServer
|
||||
from utils.settings import Settings
|
||||
from core.controller import Controller
|
||||
|
||||
|
||||
class AppLaunchException(Exception):
|
||||
...
|
||||
|
||||
class ControllerStartExceptio(Exception):
|
||||
class ControllerStartException(Exception):
|
||||
...
|
||||
|
||||
|
||||
class Application(IPCServer):
|
||||
""" Create Settings and Controller classes. Bind signal to Builder. Inherit from Builtins to bind global methods and classes. """
|
||||
""" Inherit from IPCServer; create Controller classe; bind any signal(s) to Builder. """
|
||||
|
||||
def __init__(self, args, unknownargs):
|
||||
super(Application, self).__init__()
|
||||
if args.debug == "true":
|
||||
settings.set_debug(True)
|
||||
self.args, self.unknownargs = args, unknownargs
|
||||
|
||||
if args.trace_debug == "true":
|
||||
settings.set_trace_debug(True)
|
||||
|
||||
# NOTE: Instance found, sending files to it...
|
||||
if not settings.is_trace_debug():
|
||||
self.create_ipc_listener()
|
||||
time.sleep(0.05)
|
||||
try:
|
||||
self.create_ipc_listener()
|
||||
except Exception:
|
||||
...
|
||||
|
||||
if not self.is_ipc_alive:
|
||||
if unknownargs:
|
||||
for arg in unknownargs:
|
||||
if os.path.isdir(arg):
|
||||
message = f"FILE|{arg}"
|
||||
self.send_ipc_message(message)
|
||||
for arg in unknownargs + [args.new_tab,]:
|
||||
if os.path.isdir(arg):
|
||||
message = f"FILE|{arg}"
|
||||
self.send_ipc_message(message)
|
||||
|
||||
if args.new_tab and os.path.isdir(args.new_tab):
|
||||
message = f"FILE|{args.new_tab}"
|
||||
self.send_ipc_message(message)
|
||||
|
||||
raise AppLaunchException(f"IPC Server Exists: Will send path(s) to it and close...\nNote: If no fm exists, remove /tmp/{app_name}-ipc.sock")
|
||||
raise AppLaunchException(f"{app_name} IPC Server Exists: Will send path(s) to it and close...")
|
||||
|
||||
|
||||
settings.create_window()
|
||||
self._load_controller_and_builder()
|
||||
|
||||
controller = Controller(args, unknownargs)
|
||||
def _load_controller_and_builder(self):
|
||||
controller = Controller(self.args, self.unknownargs)
|
||||
if not controller:
|
||||
raise ControllerStartExceptio("Controller exited and doesn't exist...")
|
||||
raise ControllerStartException("Controller exited and doesn't exist...")
|
||||
|
||||
# Gets the methods from the classes and sets to handler.
|
||||
# Then, builder connects to any signals it needs.
|
||||
|
|
|
@ -19,27 +19,14 @@ from .controller_data import Controller_Data
|
|||
class Controller(UIMixin, KeyboardSignalsMixin, IPCSignalsMixin, ExceptionHookMixin, Controller_Data):
|
||||
""" Controller coordinates the mixins and is somewhat the root hub of it all. """
|
||||
def __init__(self, args, unknownargs):
|
||||
self._subscribe_to_events()
|
||||
self.setup_controller_data()
|
||||
self.window.show()
|
||||
|
||||
self.generate_windows(self.fm_controller_data)
|
||||
self.plugins.launch_plugins()
|
||||
|
||||
if settings.is_debug():
|
||||
self.window.set_interactive_debugging(True)
|
||||
|
||||
# NOTE: Open files if passed in from cli and not trace debugging...
|
||||
if not settings.is_trace_debug():
|
||||
self._subscribe_to_events()
|
||||
|
||||
if unknownargs:
|
||||
for arg in unknownargs:
|
||||
if os.path.isdir(arg):
|
||||
message = f"FILE|{arg}"
|
||||
event_system.emit("post_file_to_ipc", message)
|
||||
|
||||
if args.new_tab and os.path.isdir(args.new_tab):
|
||||
message = f"FILE|{args.new_tab}"
|
||||
for arg in unknownargs + [args.new_tab,]:
|
||||
if os.path.isdir(arg):
|
||||
message = f"FILE|{arg}"
|
||||
event_system.emit("post_file_to_ipc", message)
|
||||
|
||||
|
||||
|
@ -88,7 +75,7 @@ class Controller(UIMixin, KeyboardSignalsMixin, IPCSignalsMixin, ExceptionHookMi
|
|||
session_json = self.fm_controller.get_state_from_file(path)
|
||||
self.load_session(session_json)
|
||||
if (response == Gtk.ResponseType.CANCEL) or (response == Gtk.ResponseType.DELETE_EVENT):
|
||||
pass
|
||||
...
|
||||
|
||||
save_load_dialog.hide()
|
||||
|
||||
|
@ -137,7 +124,6 @@ class Controller(UIMixin, KeyboardSignalsMixin, IPCSignalsMixin, ExceptionHookMi
|
|||
|
||||
|
||||
|
||||
|
||||
@endpoint_registry.register(rule="go_home")
|
||||
def go_home(self, widget=None, eve=None):
|
||||
self.builder.get_object("go_home").released()
|
||||
|
|
|
@ -96,6 +96,10 @@ class Controller_Data:
|
|||
self.window.connect("delete-event", self.tear_down)
|
||||
GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, signal.SIGINT, self.tear_down)
|
||||
|
||||
self.window.show()
|
||||
if settings.is_debug():
|
||||
self.window.set_interactive_debugging(True)
|
||||
|
||||
|
||||
def get_current_state(self) -> State:
|
||||
'''
|
||||
|
|
|
@ -31,11 +31,10 @@ class IPCServer:
|
|||
|
||||
self._subscribe_to_events()
|
||||
|
||||
|
||||
def _subscribe_to_events(self):
|
||||
event_system.subscribe("post_file_to_ipc", self.send_ipc_message)
|
||||
|
||||
|
||||
@daemon_threaded
|
||||
def create_ipc_listener(self) -> None:
|
||||
if self._conn_type == "socket":
|
||||
if os.path.exists(self._ipc_address) and settings.is_dirty_start():
|
||||
|
@ -49,14 +48,18 @@ class IPCServer:
|
|||
|
||||
|
||||
self.is_ipc_alive = True
|
||||
self._run_ipc_loop(listener)
|
||||
|
||||
@daemon_threaded
|
||||
def _run_ipc_loop(self, listener) -> None:
|
||||
while True:
|
||||
conn = listener.accept()
|
||||
start_time = time.perf_counter()
|
||||
self.handle_message(conn, start_time)
|
||||
self._handle_ipc_message(conn, start_time)
|
||||
|
||||
listener.close()
|
||||
|
||||
def handle_message(self, conn, start_time) -> None:
|
||||
def _handle_ipc_message(self, conn, start_time) -> None:
|
||||
while True:
|
||||
msg = conn.recv()
|
||||
if settings.is_debug():
|
||||
|
|
|
@ -31,7 +31,7 @@ class Settings:
|
|||
self._KEY_BINDINGS = f"{self._CONFIG_PATH}/key-bindings.json"
|
||||
self._DEFAULT_ICONS = f"{self._CONFIG_PATH}/icons"
|
||||
self._WINDOW_ICON = f"{self._DEFAULT_ICONS}/{app_name.lower()}.png"
|
||||
self._PID_FILE = f"{self._CONFIG_PATH}/solarfm.pid"
|
||||
self._PID_FILE = f"{self._CONFIG_PATH}/{app_name.lower()}.pid"
|
||||
self._ICON_THEME = Gtk.IconTheme.get_default()
|
||||
|
||||
if not os.path.exists(self._CONFIG_PATH):
|
||||
|
@ -68,10 +68,8 @@ class Settings:
|
|||
self._debug = False
|
||||
self._dirty_start = False
|
||||
|
||||
self._check_for_dirty_state()
|
||||
|
||||
|
||||
def _check_for_dirty_state(self):
|
||||
def do_dirty_start_check(self):
|
||||
if not os.path.exists(self._PID_FILE):
|
||||
self._write_new_pid()
|
||||
else:
|
||||
|
@ -88,11 +86,12 @@ class Settings:
|
|||
try:
|
||||
os.kill(pid, 0)
|
||||
except OSError:
|
||||
print("SolarFM Is starting dirty...")
|
||||
print(f"{app_name} is starting dirty...")
|
||||
self._dirty_start = True
|
||||
self._write_new_pid()
|
||||
return
|
||||
|
||||
print("PID is alive... Let downstream errors handle app closure.")
|
||||
print("PID is alive... Let downstream errors (sans debug args) handle app closure propigation.")
|
||||
|
||||
def _write_new_pid(self):
|
||||
pid = os.getpid()
|
||||
|
|
Loading…
Reference in New Issue