Merge Stable Changesto Master #9

Merged
itdominator merged 30 commits from develop into master 2022-11-29 04:58:09 +00:00
6 changed files with 45 additions and 53 deletions
Showing only changes of commit efa42a301c - Show all commits

View File

@ -35,6 +35,13 @@ if __name__ == "__main__":
# Read arguments (If any...) # Read arguments (If any...)
args, unknownargs = parser.parse_known_args() 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) Application(args, unknownargs)
Gtk.main() Gtk.main()
except Exception as e: except Exception as e:

View File

@ -1,57 +1,50 @@
# Python imports # Python imports
import os, inspect, time import os, inspect
# Lib imports # Lib imports
# Application imports # Application imports
from utils.ipc_server import IPCServer from utils.ipc_server import IPCServer
from utils.settings import Settings
from core.controller import Controller from core.controller import Controller
class AppLaunchException(Exception): class AppLaunchException(Exception):
... ...
class ControllerStartExceptio(Exception): class ControllerStartException(Exception):
... ...
class Application(IPCServer): 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): def __init__(self, args, unknownargs):
super(Application, self).__init__() super(Application, self).__init__()
if args.debug == "true": self.args, self.unknownargs = args, unknownargs
settings.set_debug(True)
if args.trace_debug == "true":
settings.set_trace_debug(True)
# NOTE: Instance found, sending files to it...
if not settings.is_trace_debug(): if not settings.is_trace_debug():
self.create_ipc_listener() try:
time.sleep(0.05) self.create_ipc_listener()
except Exception:
...
if not self.is_ipc_alive: if not self.is_ipc_alive:
if unknownargs: for arg in unknownargs + [args.new_tab,]:
for arg in unknownargs: if os.path.isdir(arg):
if os.path.isdir(arg): message = f"FILE|{arg}"
message = f"FILE|{arg}" self.send_ipc_message(message)
self.send_ipc_message(message)
if args.new_tab and os.path.isdir(args.new_tab): raise AppLaunchException(f"{app_name} IPC Server Exists: Will send path(s) to it and close...")
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")
settings.create_window() 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: 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. # Gets the methods from the classes and sets to handler.
# Then, builder connects to any signals it needs. # Then, builder connects to any signals it needs.

View File

@ -19,27 +19,14 @@ from .controller_data import Controller_Data
class Controller(UIMixin, KeyboardSignalsMixin, IPCSignalsMixin, ExceptionHookMixin, Controller_Data): class Controller(UIMixin, KeyboardSignalsMixin, IPCSignalsMixin, ExceptionHookMixin, Controller_Data):
""" Controller coordinates the mixins and is somewhat the root hub of it all. """ """ Controller coordinates the mixins and is somewhat the root hub of it all. """
def __init__(self, args, unknownargs): def __init__(self, args, unknownargs):
self._subscribe_to_events()
self.setup_controller_data() self.setup_controller_data()
self.window.show()
self.generate_windows(self.fm_controller_data) self.generate_windows(self.fm_controller_data)
self.plugins.launch_plugins() self.plugins.launch_plugins()
if settings.is_debug(): for arg in unknownargs + [args.new_tab,]:
self.window.set_interactive_debugging(True) if os.path.isdir(arg):
message = f"FILE|{arg}"
# 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}"
event_system.emit("post_file_to_ipc", message) 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) session_json = self.fm_controller.get_state_from_file(path)
self.load_session(session_json) self.load_session(session_json)
if (response == Gtk.ResponseType.CANCEL) or (response == Gtk.ResponseType.DELETE_EVENT): if (response == Gtk.ResponseType.CANCEL) or (response == Gtk.ResponseType.DELETE_EVENT):
pass ...
save_load_dialog.hide() save_load_dialog.hide()
@ -137,7 +124,6 @@ class Controller(UIMixin, KeyboardSignalsMixin, IPCSignalsMixin, ExceptionHookMi
@endpoint_registry.register(rule="go_home") @endpoint_registry.register(rule="go_home")
def go_home(self, widget=None, eve=None): def go_home(self, widget=None, eve=None):
self.builder.get_object("go_home").released() self.builder.get_object("go_home").released()

View File

@ -96,6 +96,10 @@ class Controller_Data:
self.window.connect("delete-event", self.tear_down) self.window.connect("delete-event", self.tear_down)
GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, signal.SIGINT, 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: def get_current_state(self) -> State:
''' '''

View File

@ -31,11 +31,10 @@ class IPCServer:
self._subscribe_to_events() self._subscribe_to_events()
def _subscribe_to_events(self): def _subscribe_to_events(self):
event_system.subscribe("post_file_to_ipc", self.send_ipc_message) event_system.subscribe("post_file_to_ipc", self.send_ipc_message)
@daemon_threaded
def create_ipc_listener(self) -> None: def create_ipc_listener(self) -> None:
if self._conn_type == "socket": if self._conn_type == "socket":
if os.path.exists(self._ipc_address) and settings.is_dirty_start(): if os.path.exists(self._ipc_address) and settings.is_dirty_start():
@ -49,14 +48,18 @@ class IPCServer:
self.is_ipc_alive = True self.is_ipc_alive = True
self._run_ipc_loop(listener)
@daemon_threaded
def _run_ipc_loop(self, listener) -> None:
while True: while True:
conn = listener.accept() conn = listener.accept()
start_time = time.perf_counter() start_time = time.perf_counter()
self.handle_message(conn, start_time) self._handle_ipc_message(conn, start_time)
listener.close() listener.close()
def handle_message(self, conn, start_time) -> None: def _handle_ipc_message(self, conn, start_time) -> None:
while True: while True:
msg = conn.recv() msg = conn.recv()
if settings.is_debug(): if settings.is_debug():

View File

@ -31,7 +31,7 @@ class Settings:
self._KEY_BINDINGS = f"{self._CONFIG_PATH}/key-bindings.json" self._KEY_BINDINGS = f"{self._CONFIG_PATH}/key-bindings.json"
self._DEFAULT_ICONS = f"{self._CONFIG_PATH}/icons" self._DEFAULT_ICONS = f"{self._CONFIG_PATH}/icons"
self._WINDOW_ICON = f"{self._DEFAULT_ICONS}/{app_name.lower()}.png" 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() self._ICON_THEME = Gtk.IconTheme.get_default()
if not os.path.exists(self._CONFIG_PATH): if not os.path.exists(self._CONFIG_PATH):
@ -68,10 +68,8 @@ class Settings:
self._debug = False self._debug = False
self._dirty_start = False self._dirty_start = False
self._check_for_dirty_state()
def do_dirty_start_check(self):
def _check_for_dirty_state(self):
if not os.path.exists(self._PID_FILE): if not os.path.exists(self._PID_FILE):
self._write_new_pid() self._write_new_pid()
else: else:
@ -88,11 +86,12 @@ class Settings:
try: try:
os.kill(pid, 0) os.kill(pid, 0)
except OSError: except OSError:
print("SolarFM Is starting dirty...") print(f"{app_name} is starting dirty...")
self._dirty_start = True self._dirty_start = True
self._write_new_pid() 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): def _write_new_pid(self):
pid = os.getpid() pid = os.getpid()