refactored mixins; made db optional through commenting out; webkit settings externalized

This commit is contained in:
itdominator 2024-02-10 19:45:23 -06:00
parent 70f10c6263
commit ea4324911e
11 changed files with 52 additions and 81 deletions

View File

@ -6,7 +6,7 @@ import sys
# Lib imports # Lib imports
# Application imports # Application imports
from libs.db import DB # from libs.db import DB
from libs.event_system import EventSystem from libs.event_system import EventSystem
from libs.endpoint_registry import EndpointRegistry from libs.endpoint_registry import EndpointRegistry
from libs.keybindings import Keybindings from libs.keybindings import Keybindings
@ -41,7 +41,7 @@ builtins.keybindings = Keybindings()
builtins.event_system = EventSystem() builtins.event_system = EventSystem()
builtins.endpoint_registry = EndpointRegistry() builtins.endpoint_registry = EndpointRegistry()
builtins.settings_manager = SettingsManager() builtins.settings_manager = SettingsManager()
builtins.db = DB() # builtins.db = DB()
settings_manager.load_settings() settings_manager.load_settings()

View File

@ -7,8 +7,8 @@ gi.require_version('Gtk', '3.0')
from gi.repository import Gtk from gi.repository import Gtk
# Application imports # Application imports
from ..mixins.signals_mixins import SignalsMixins from libs.mixins.ipc_signals_mixin import IPCSignalsMixin
from ..mixins.dummy_mixin import DummyMixin from libs.mixins.keyboard_signals_mixin import KeyboardSignalsMixin
from ..containers.base_container import BaseContainer from ..containers.base_container import BaseContainer
@ -17,7 +17,7 @@ from .bridge_controller import BridgeController
class BaseController(DummyMixin, SignalsMixins, BaseControllerData): class BaseController(IPCSignalsMixin, KeyboardSignalsMixin, BaseControllerData):
def __init__(self, args, unknownargs): def __init__(self, args, unknownargs):
self.setup_controller_data() self.setup_controller_data()
@ -26,8 +26,6 @@ class BaseController(DummyMixin, SignalsMixins, BaseControllerData):
self._subscribe_to_events() self._subscribe_to_events()
self._load_controllers() self._load_controllers()
self.print_hello_world() # A mixin method from the DummyMixin file
if args.no_plugins == "false": if args.no_plugins == "false":
self.plugins.launch_plugins() self.plugins.launch_plugins()

View File

@ -1,3 +0,0 @@
"""
Generic Mixins Module
"""

View File

@ -1,13 +0,0 @@
# Python imports
# Lib imports
# Application imports
class DummyMixin:
""" DummyMixin is an example of how mixins are used and structured in a project. """
def print_hello_world(self) -> None:
logger.debug("Hello, World!")

View File

@ -1,3 +0,0 @@
"""
Signals module
"""

View File

@ -1,13 +0,0 @@
# Python imports
# Lib imports
# Application imports
from .signals.ipc_signals_mixin import IPCSignalsMixin
from .signals.keyboard_signals_mixin import KeyboardSignalsMixin
class SignalsMixins(KeyboardSignalsMixin, IPCSignalsMixin):
...

View File

@ -1,5 +1,3 @@
# Python imports # Python imports
# Lib imports # Lib imports
@ -10,7 +8,7 @@ from gi.repository import Gdk
from gi.repository import WebKit2 from gi.repository import WebKit2
# Application imports # Application imports
from libs.settings_manager.other.webkit_ui_settings import WebkitUISettings
class WebkitUI(WebKit2.WebView): class WebkitUI(WebKit2.WebView):
@ -45,11 +43,6 @@ class WebkitUI(WebKit2.WebView):
self.load_html(content = data, base_uri = f"file://{path}/") self.load_html(content = data, base_uri = f"file://{path}/")
# def _load_view(self):
# path = settings_manager.get_context_path()
# data = settings_manager.wrap_html_to_body("")
# self.load_html(content = data, base_uri = f"file://{path}/")
def _setup_content_manager(self): def _setup_content_manager(self):
content_manager = self.get_user_content_manager() content_manager = self.get_user_content_manager()
content_manager.connect("script-message-received", self._process_js_message) content_manager.connect("script-message-received", self._process_js_message)
@ -61,7 +54,7 @@ class WebkitUI(WebKit2.WebView):
try: try:
event = Event( **json.loads(message) ) event = Event( **json.loads(message) )
# event_system.emit("handle_bridge_event", (event,)) event_system.emit("handle_bridge_event", (event,))
except Exception as e: except Exception as e:
logger.info(e) logger.info(e)
@ -69,36 +62,3 @@ class WebkitUI(WebKit2.WebView):
command = f"displayMessage('{message}', '{mtype}', '3')" command = f"displayMessage('{message}', '{mtype}', '3')"
self.run_javascript(command, None, None) 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"{app_name}")

View File

@ -0,0 +1,3 @@
"""
Settings Other module
"""

View File

@ -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}")