adding guard in IPC, adding settings

This commit is contained in:
itdominator 2023-03-25 15:57:13 -05:00
parent ba94493fb8
commit 48d6c505a7
2 changed files with 31 additions and 9 deletions

View File

@ -55,10 +55,14 @@ class IPCServer:
@daemon_threaded @daemon_threaded
def _run_ipc_loop(self, listener) -> None: def _run_ipc_loop(self, listener) -> None:
# NOTE: Not thread safe if using with Gtk. Need to import GLib and use idle_add
while True: while True:
conn = listener.accept() try:
start_time = time.perf_counter() conn = listener.accept()
self._handle_ipc_message(conn, start_time) start_time = time.perf_counter()
self._handle_ipc_message(conn, start_time)
except Exception as e:
...
listener.close() listener.close()

View File

@ -30,6 +30,8 @@ class Settings(StartCheckMixin):
self._KEY_BINDINGS_FILE = f"{self._HOME_CONFIG_PATH}/key-bindings.json" self._KEY_BINDINGS_FILE = f"{self._HOME_CONFIG_PATH}/key-bindings.json"
self._PID_FILE = f"{self._HOME_CONFIG_PATH}/{app_name.lower()}.pid" self._PID_FILE = f"{self._HOME_CONFIG_PATH}/{app_name.lower()}.pid"
self._WINDOW_ICON = f"{self._DEFAULT_ICONS}/{app_name.lower()}.png" self._WINDOW_ICON = f"{self._DEFAULT_ICONS}/{app_name.lower()}.png"
self._UI_WIDEGTS_PATH = f"{self._HOME_CONFIG_PATH}/ui_widgets"
self._CONTEXT_MENU = f"{self._HOME_CONFIG_PATH}/contexct_menu.json"
if not os.path.exists(self._HOME_CONFIG_PATH): if not os.path.exists(self._HOME_CONFIG_PATH):
os.mkdir(self._HOME_CONFIG_PATH) os.mkdir(self._HOME_CONFIG_PATH)
@ -63,11 +65,25 @@ class Settings(StartCheckMixin):
self._WINDOW_ICON = f"{self._USR_PATH}/icons/{app_name.lower()}.png" self._WINDOW_ICON = f"{self._USR_PATH}/icons/{app_name.lower()}.png"
if not os.path.exists(self._WINDOW_ICON): if not os.path.exists(self._WINDOW_ICON):
raise MissingConfigError("Unable to find the application icon.") raise MissingConfigError("Unable to find the application icon.")
if not os.path.exists(self._UI_WIDEGTS_PATH):
self._UI_WIDEGTS_PATH = f"{self._USR_PATH}/ui_widgets"
if not os.path.exists(self._CONTEXT_MENU):
self._CONTEXT_MENU = f"{self._USR_PATH}/contexct_menu.json"
with open(self._KEY_BINDINGS_FILE) as file: try:
bindings = json.load(file)["keybindings"] with open(self._KEY_BINDINGS_FILE) as file:
keybindings.configure(bindings) bindings = json.load(file)["keybindings"]
keybindings.configure(bindings)
except Exception as e:
print( f"Settings: {self._KEY_BINDINGS_FILE}\n\t\t{repr(e)}" )
try:
with open(self._CONTEXT_MENU) as file:
self._context_menu_data = json.load(file)
except Exception as e:
print( f"Settings: {self._CONTEXT_MENU}\n\t\t{repr(e)}" )
self._main_window = None self._main_window = None
self._main_window_w = 800 self._main_window_w = 800
@ -111,9 +127,11 @@ class Settings(StartCheckMixin):
def get_main_window(self) -> any: return self._main_window def get_main_window(self) -> any: return self._main_window
def get_main_window_width(self) -> any: return self._main_window_w def get_main_window_width(self) -> any: return self._main_window_w
def get_main_window_height(self) -> any: return self._main_window_h def get_main_window_height(self) -> any: return self._main_window_h
def get_builder(self) -> any: return self._builder def get_builder(self) -> any: return self._builder
def get_paint_bg_color(self) -> any: return self.PAINT_BG_COLOR def get_paint_bg_color(self) -> any: return self.PAINT_BG_COLOR
def get_glade_file(self) -> str: return self._GLADE_FILE def get_glade_file(self) -> str: return self._GLADE_FILE
def get_ui_widgets_path(self) -> str: return self._UI_WIDEGTS_PATH
def get_context_menu_data(self) -> str: return self._context_menu_data
def get_plugins_path(self) -> str: return self._PLUGINS_PATH def get_plugins_path(self) -> str: return self._PLUGINS_PATH
def get_icon_theme(self) -> str: return self._ICON_THEME def get_icon_theme(self) -> str: return self._ICON_THEME