From 2a2fe276673b7177a8f2d1fe50d5e6c35e1f0627 Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Fri, 16 Feb 2024 20:57:23 -0600 Subject: [PATCH] Fixing loading of passed in files --- src/core/controllers/base_controller.py | 15 +------ src/core/controllers/base_controller_data.py | 14 +++++++ src/core/controllers/bridge_controller.py | 4 +- src/core/widgets/base/webkit/ace_editor.py | 38 ++--------------- src/libs/settings_manager/manager.py | 4 +- src/libs/settings_manager/other/__init__.py | 3 ++ .../other/webkit_ui_settings.py | 42 +++++++++++++++++++ 7 files changed, 70 insertions(+), 50 deletions(-) create mode 100644 src/libs/settings_manager/other/__init__.py create mode 100644 src/libs/settings_manager/other/webkit_ui_settings.py diff --git a/src/core/controllers/base_controller.py b/src/core/controllers/base_controller.py index cf3afe5..5064a30 100644 --- a/src/core/controllers/base_controller.py +++ b/src/core/controllers/base_controller.py @@ -1,5 +1,4 @@ # Python imports -import os # Lib imports import gi @@ -21,15 +20,7 @@ from .bridge_controller import BridgeController class BaseController(KeyboardSignalsMixin, BaseControllerData): def __init__(self, args, unknownargs): - messages = [] - for arg in unknownargs + [args.new_tab,]: - # NOTE: If passing line number with file split against : - if os.path.isfile(arg.replace("file://", "").split(":")[0]): - messages.append(f"FILE|{arg.replace('file://', '')}") - - if len(messages) > 0: - settings_manager.set_is_starting_with_file(True) - + self.collect_files_dirs(args, unknownargs) self.setup_controller_data() @@ -38,13 +29,9 @@ class BaseController(KeyboardSignalsMixin, BaseControllerData): self._subscribe_to_events() self._load_controllers() - if args.no_plugins == "false": self.plugins.launch_plugins() - for message in messages: - event_system.emit("post_file_to_ipc", message) - def _setup_styling(self): ... diff --git a/src/core/controllers/base_controller_data.py b/src/core/controllers/base_controller_data.py index 61c4e11..eb6c3c7 100644 --- a/src/core/controllers/base_controller_data.py +++ b/src/core/controllers/base_controller_data.py @@ -26,6 +26,20 @@ class BaseControllerData: self.load_glade_file() self.plugins = PluginsController() + def collect_files_dirs(self, args, unknownargs): + files = [] + for arg in unknownargs + [args.new_tab,]: + if os.path.isdir( arg.replace("file://", "") ): + files.append( f"DIR|{arg.replace('file://', '')}" ) + + # NOTE: If passing line number with file split against : + if os.path.isfile( arg.replace("file://", "").split(":")[0] ): + files.append( f"FILE|{arg.replace('file://', '')}" ) + + if len(files) > 0: + settings_manager.set_is_starting_with_file(True) + settings_manager.set_starting_files(files) + def set_active_src_view(self, source_view): if self.active_src_view: old_notebook = self.active_src_view.get_parent().get_parent() diff --git a/src/core/controllers/bridge_controller.py b/src/core/controllers/bridge_controller.py index 6fc9fdd..a230e83 100644 --- a/src/core/controllers/bridge_controller.py +++ b/src/core/controllers/bridge_controller.py @@ -10,7 +10,6 @@ import base64 class BridgeController: def __init__(self): - self.opened_files = {} self.originator = -1 self._setup_signals() @@ -44,6 +43,9 @@ class BridgeController: self.originator = event.originator match event.topic: + case "load_starting_files": + for file in settings_manager.get_starting_files(): + event_system.emit("post_file_to_ipc", file) case "save": event_system.emit(f"handle_file_event_{event.originator}", (event,)) case "close": diff --git a/src/core/widgets/base/webkit/ace_editor.py b/src/core/widgets/base/webkit/ace_editor.py index 17f7101..7dda6df 100644 --- a/src/core/widgets/base/webkit/ace_editor.py +++ b/src/core/widgets/base/webkit/ace_editor.py @@ -11,6 +11,7 @@ from gi.repository import GLib # Application imports from libs.data_types import Event +from libs.settings_manager.other.webkit_ui_settings import WebkitUISettings @@ -124,37 +125,6 @@ class AceEditor(WebKit2.WebView): command = f"displayMessage('{message}', '{mtype}', '3')" self.run_javascript(command, None, None) - -class WebkitUISettings(WebKit2.Settings): - def __init__(self): - super(WebkitUISettings, self).__init__() - - self._set_default_settings() - - - # Note: Highly insecure setup but most "app" like setup I could think of. - # Audit heavily any scripts/links ran/clicked under this setup! - def _set_default_settings(self): - # self.set_enable_xss_auditor(True) - # self.set_enable_hyperlink_auditing(True) - self.set_enable_xss_auditor(False) - self.set_enable_hyperlink_auditing(False) - self.set_allow_file_access_from_file_urls(True) - self.set_allow_universal_access_from_file_urls(True) - - self.set_enable_page_cache(False) - self.set_enable_offline_web_application_cache(False) - self.set_enable_html5_local_storage(False) - self.set_enable_html5_database(False) - - self.set_enable_fullscreen(False) - self.set_print_backgrounds(False) - self.set_enable_tabs_to_links(False) - self.set_enable_developer_extras(True) - self.set_enable_webrtc(True) - self.set_enable_webaudio(True) - self.set_enable_accelerated_2d_canvas(True) - - self.set_user_agent(f"Mozilla/5.0 {app_name}") - - + def run_javascript(self, script, cancellable, callback): + logger.debug(script) + super().run_javascript(script, cancellable, callback) diff --git a/src/libs/settings_manager/manager.py b/src/libs/settings_manager/manager.py index 738427f..7b3690c 100644 --- a/src/libs/settings_manager/manager.py +++ b/src/libs/settings_manager/manager.py @@ -92,6 +92,7 @@ class SettingsManager(StartCheckMixin, Singleton): self._debug = False self._dirty_start = False self._passed_in_file = False + self._starting_files = [] def register_signals_to_builder(self, classes=None): @@ -110,7 +111,6 @@ class SettingsManager(StartCheckMixin, Singleton): def set_main_window(self, window): self._main_window = window def set_builder(self, builder) -> any: self._builder = builder - def get_monitor_data(self) -> list: screen = self._main_window.get_screen() monitors = [] @@ -134,6 +134,7 @@ class SettingsManager(StartCheckMixin, Singleton): def get_home_config_path(self) -> str: return self._HOME_CONFIG_PATH def get_window_icon(self) -> str: return self._WINDOW_ICON def get_home_path(self) -> str: return self._USER_HOME + def get_starting_files(self) -> []: return self._starting_files def is_trace_debug(self) -> str: return self._trace_debug def is_debug(self) -> str: return self._debug @@ -150,6 +151,7 @@ class SettingsManager(StartCheckMixin, Singleton): def set_main_window_height(self, height = 600): self.settings.config.main_window_height = height def set_main_window_min_width(self, width = 720): self.settings.config.main_window_min_width = width def set_main_window_min_height(self, height = 480): self.settings.config.main_window_min_height = height + def set_starting_files(self, files: []) -> None: self._starting_files = files def set_trace_debug(self, trace_debug): self._trace_debug = trace_debug diff --git a/src/libs/settings_manager/other/__init__.py b/src/libs/settings_manager/other/__init__.py new file mode 100644 index 0000000..e1b5377 --- /dev/null +++ b/src/libs/settings_manager/other/__init__.py @@ -0,0 +1,3 @@ +""" + Settings Other module +""" diff --git a/src/libs/settings_manager/other/webkit_ui_settings.py b/src/libs/settings_manager/other/webkit_ui_settings.py new file mode 100644 index 0000000..962fe60 --- /dev/null +++ b/src/libs/settings_manager/other/webkit_ui_settings.py @@ -0,0 +1,42 @@ +# Python imports + +# Lib imports +import gi +gi.require_version('WebKit2', '4.0') +from gi.repository import WebKit2 + +# Application imports + + + +class WebkitUISettings(WebKit2.Settings): + def __init__(self): + super(WebkitUISettings, self).__init__() + + self._set_default_settings() + + + # Note: Highly insecure setup but most "app" like setup I could think of. + # Audit heavily any scripts/links ran/clicked under this setup! + def _set_default_settings(self): + self.set_enable_xss_auditor(True) + self.set_enable_hyperlink_auditing(True) + # self.set_enable_xss_auditor(False) + # self.set_enable_hyperlink_auditing(False) + self.set_allow_file_access_from_file_urls(True) + self.set_allow_universal_access_from_file_urls(True) + + self.set_enable_page_cache(False) + self.set_enable_offline_web_application_cache(False) + self.set_enable_html5_local_storage(False) + self.set_enable_html5_database(False) + + self.set_enable_fullscreen(False) + self.set_print_backgrounds(False) + self.set_enable_tabs_to_links(False) + self.set_enable_developer_extras(True) + self.set_enable_webrtc(True) + self.set_enable_webaudio(True) + self.set_enable_accelerated_2d_canvas(True) + + self.set_user_agent(f"{app_name}") \ No newline at end of file