Added args handler, made IPC singleton
This commit is contained in:
parent
ef03030c88
commit
b4120bdca4
|
@ -14,7 +14,7 @@ class AppLaunchException(Exception):
|
|||
|
||||
|
||||
class Application(IPCServer):
|
||||
''' Create Settings and Controller classes. Bind signal to Builder. Inherit from Builtins to bind global methods and classes.'''
|
||||
""" docstring for Application. """
|
||||
|
||||
def __init__(self, args, unknownargs):
|
||||
super(Application, self).__init__()
|
||||
|
@ -26,7 +26,7 @@ class Application(IPCServer):
|
|||
|
||||
if not self.is_ipc_alive:
|
||||
for arg in unknownargs + [args.new_tab,]:
|
||||
if os.path.isdir(arg):
|
||||
if os.path.isfile(arg):
|
||||
message = f"FILE|{arg}"
|
||||
self.send_ipc_message(message)
|
||||
|
||||
|
|
|
@ -27,6 +27,18 @@ class Controller(DummyMixin, SignalsMixins, ControllerData):
|
|||
|
||||
self.print_hello_world() # A mixin method from the DummyMixin file
|
||||
|
||||
if args.no_plugins == "false":
|
||||
self.plugins.launch_plugins()
|
||||
|
||||
for arg in unknownargs + [args.new_tab,]:
|
||||
if os.path.isfile(arg):
|
||||
message = f"FILE|{arg}"
|
||||
event_system.emit("post_file_to_ipc", message)
|
||||
|
||||
if os.path.isdir(arg):
|
||||
message = f"DIR|{arg}"
|
||||
event_system.emit("post_file_to_ipc", message)
|
||||
|
||||
logger.info(f"Made it past {self.__class__} loading...")
|
||||
|
||||
|
||||
|
@ -40,6 +52,7 @@ class Controller(DummyMixin, SignalsMixins, ControllerData):
|
|||
|
||||
def _subscribe_to_events(self):
|
||||
event_system.subscribe("handle_file_from_ipc", self.handle_file_from_ipc)
|
||||
event_system.subscribe("handle_dir_from_ipc", self.handle_dir_from_ipc)
|
||||
event_system.subscribe("tggl_top_main_menubar", self._tggl_top_main_menubar)
|
||||
|
||||
def load_glade_file(self):
|
||||
|
|
|
@ -14,4 +14,7 @@ class IPCSignalsMixin:
|
|||
print(message)
|
||||
|
||||
def handle_file_from_ipc(self, path: str) -> None:
|
||||
print(f"Path From IPC: {path}")
|
||||
print(f"File From IPC: {path}")
|
||||
|
||||
def handle_dir_from_ipc(self, path: str) -> None:
|
||||
print(f"Dir From IPC: {path}")
|
||||
|
|
|
@ -8,11 +8,11 @@ from multiprocessing.connection import Listener
|
|||
# Lib imports
|
||||
|
||||
# Application imports
|
||||
from .singleton import Singleton
|
||||
|
||||
|
||||
|
||||
|
||||
class IPCServer:
|
||||
class IPCServer(Singleton):
|
||||
""" Create a listener so that other {app_name} instances send requests back to existing instance. """
|
||||
def __init__(self, ipc_address: str = '127.0.0.1', conn_type: str = "socket"):
|
||||
self.is_ipc_alive = False
|
||||
|
@ -77,6 +77,11 @@ class IPCServer:
|
|||
if file:
|
||||
event_system.emit("handle_file_from_ipc", file)
|
||||
|
||||
if "DIR|" in msg:
|
||||
file = msg.split("DIR|")[1].strip()
|
||||
if file:
|
||||
event_system.emit("handle_dir_from_ipc", file)
|
||||
|
||||
conn.close()
|
||||
break
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
# Application imports
|
||||
|
||||
|
||||
|
||||
class SingletonError(Exception):
|
||||
pass
|
||||
|
||||
|
|
Loading…
Reference in New Issue