Renamed settings folder; hyphenated event names

This commit is contained in:
itdominator 2024-02-25 16:19:14 -06:00
parent ea62eb280c
commit b1096055b7
28 changed files with 55 additions and 163 deletions

View File

@ -11,7 +11,7 @@ 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
from libs.logger import Logger from libs.logger import Logger
from libs.settings_manager.manager import SettingsManager from libs.settings.manager import SettingsManager

View File

@ -33,8 +33,8 @@ class BaseContainer(Gtk.Box):
... ...
def _subscribe_to_events(self): def _subscribe_to_events(self):
event_system.subscribe("update_transparency", self._update_transparency) event_system.subscribe("update-transparency", self._update_transparency)
event_system.subscribe("remove_transparency", self._remove_transparency) event_system.subscribe("remove-transparency", self._remove_transparency)
def _load_widgets(self): def _load_widgets(self):
self.add(HeaderContainer()) self.add(HeaderContainer())

View File

@ -31,7 +31,6 @@ class CenterContainer(Gtk.Box):
... ...
def _subscribe_to_events(self): def _subscribe_to_events(self):
# event_system.subscribe("handle_file_from_ipc", self.handle_file_from_ipc)
... ...
def _load_widgets(self): def _load_widgets(self):

View File

@ -32,7 +32,7 @@ class HeaderContainer(Gtk.Box):
... ...
def _subscribe_to_events(self): def _subscribe_to_events(self):
event_system.subscribe("tggl_top_main_menubar", self.tggl_top_main_menubar) event_system.subscribe("tggl-top-main-menubar", self.tggl_top_main_menubar)
def _load_widgets(self): def _load_widgets(self):
@ -43,7 +43,7 @@ class HeaderContainer(Gtk.Box):
self.add(button) self.add(button)
def _interactive_debug(self, widget = None, eve = None): def _interactive_debug(self, widget = None, eve = None):
event_system.emit("load_interactive_debug") event_system.emit("load-interactive-debug")
def tggl_top_main_menubar(self): def tggl_top_main_menubar(self):
self.hide() if self.is_visible() else self.show() self.hide() if self.is_visible() else self.show()

View File

@ -28,7 +28,6 @@ class LeftContainer(Gtk.Box):
... ...
def _subscribe_to_events(self): def _subscribe_to_events(self):
# event_system.subscribe("handle_file_from_ipc", self.handle_file_from_ipc)
... ...
def _load_widgets(self): def _load_widgets(self):

View File

@ -28,7 +28,6 @@ class RightContainer(Gtk.Box):
... ...
def _subscribe_to_events(self): def _subscribe_to_events(self):
# event_system.subscribe("handle_file_from_ipc", self.handle_file_from_ipc)
... ...
def _load_widgets(self): def _load_widgets(self):

View File

@ -31,7 +31,7 @@ class BaseController(IPCSignalsMixin, KeyboardSignalsMixin, BaseControllerData):
self.plugins.launch_plugins() self.plugins.launch_plugins()
for file in settings_manager.get_starting_files(): for file in settings_manager.get_starting_files():
event_system.emit("post_file_to_ipc", file) event_system.emit("post-file-to-ipc", file)
logger.info(f"Made it past {self.__class__} loading...") logger.info(f"Made it past {self.__class__} loading...")
@ -45,10 +45,10 @@ class BaseController(IPCSignalsMixin, KeyboardSignalsMixin, BaseControllerData):
self.window.connect("key-release-event", self.on_global_key_release_controller) self.window.connect("key-release-event", self.on_global_key_release_controller)
def _subscribe_to_events(self): def _subscribe_to_events(self):
event_system.subscribe("shutting_down", lambda: print("Shutting down...")) event_system.subscribe("shutting-down", lambda: print("Shutting down..."))
event_system.subscribe("handle_file_from_ipc", self.handle_file_from_ipc) 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("handle-dir-from-ipc", self.handle_dir_from_ipc)
event_system.subscribe("tggl_top_main_menubar", self._tggl_top_main_menubar) event_system.subscribe("tggl-top-main-menubar", self._tggl_top_main_menubar)
def _load_controllers(self): def _load_controllers(self):
BridgeController() BridgeController()

View File

@ -20,19 +20,19 @@ class BridgeController:
... ...
def _subscribe_to_events(self): def _subscribe_to_events(self):
event_system.subscribe("handle_bridge_event", self.handle_bridge_event) event_system.subscribe("handle-bridge-event", self.handle_bridge_event)
def handle_bridge_event(self, event): def handle_bridge_event(self, event):
match event.topic: match event.topic:
case "save": case "save":
event_system.emit(f"handle_file_event_{event.originator}", (event,)) event_system.emit(f"handle-file-event-{event.originator}", (event,))
case "close": case "close":
event_system.emit(f"handle_file_event_{event.originator}", (event,)) event_system.emit(f"handle-file-event-{event.originator}", (event,))
case "load_buffer": case "load_buffer":
event_system.emit(f"handle_file_event_{event.originator}", (event,)) event_system.emit(f"handle-file-event-{event.originator}", (event,))
case "load_file": case "load_file":
event_system.emit(f"handle_file_event_{event.originator}", (event,)) event_system.emit(f"handle-file-event-{event.originator}", (event,))
case "alert": case "alert":
content = base64.b64decode( event.content.encode() ).decode("utf-8") content = base64.b64decode( event.content.encode() ).decode("utf-8")
logger.info(f"\nMessage Topic: {event.topic}\nMessage Content: {content}") logger.info(f"\nMessage Topic: {event.topic}\nMessage Content: {content}")

View File

@ -42,7 +42,7 @@ class TransparencyScale(Gtk.Scale):
adjust.set_step_increment(1.0) adjust.set_step_increment(1.0)
def _update_transparency(self, range): def _update_transparency(self, range):
event_system.emit("remove_transparency") event_system.emit("remove-transparency")
tp = int(range.get_value()) tp = int(range.get_value())
settings.theming.transparency = tp settings.theming.transparency = tp
event_system.emit("update_transparency") event_system.emit("update-transparency")

View File

@ -9,7 +9,8 @@ from gi.repository import Gdk
from gi.repository import WebKit2 from gi.repository import WebKit2
# Application imports # Application imports
from libs.data_types import Event from libs.settings.other.webkit_ui_settings import WebkitUISettings
from libs.dto.event import Event
@ -17,9 +18,6 @@ class WebkitUI(WebKit2.WebView):
def __init__(self): def __init__(self):
super(WebkitUI, self).__init__() super(WebkitUI, self).__init__()
# self.get_context().set_sandbox_enabled(False)
self._load_settings()
self._setup_styling() self._setup_styling()
self._subscribe_to_events() self._subscribe_to_events()
self._load_view() self._load_view()
@ -27,10 +25,6 @@ class WebkitUI(WebKit2.WebView):
self.show_all() self.show_all()
if settings_manager.is_debug():
inspector = self.get_inspector()
inspector.show()
def _setup_styling(self): def _setup_styling(self):
self.set_vexpand(True) self.set_vexpand(True)
@ -38,8 +32,8 @@ class WebkitUI(WebKit2.WebView):
self.set_background_color( Gdk.RGBA(0, 0, 0, 0.0) ) self.set_background_color( Gdk.RGBA(0, 0, 0, 0.0) )
def _subscribe_to_events(self): def _subscribe_to_events(self):
event_system.subscribe(f"ui_message", self.ui_message) event_system.subscribe(f"ui-message", self.ui_message)
def _load_settings(self): def _load_settings(self):
self.set_settings( WebkitUISettings() ) self.set_settings( WebkitUISettings() )
@ -54,7 +48,6 @@ class WebkitUI(WebKit2.WebView):
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)
content_manager.register_script_message_handler("backend") content_manager.register_script_message_handler("backend")
@ -64,45 +57,14 @@ 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)
def ui_message(self, mtype, message): def ui_message(self, message, mtype):
command = f"displayMessage('{message}', '{mtype}', '3')" command = f"displayMessage('{message}', '{mtype}', '3')"
self.run_javascript(command, None, None) self.run_javascript(command, None, None)
def run_javascript(self, script, cancellable, callback):
class WebkitUISettings(WebKit2.Settings): logger.debug(script)
def __init__(self): super().run_javascript(script, cancellable, callback)
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_enable_dns_prefetching(False)
self.set_allow_file_access_from_file_urls(True)
self.set_allow_universal_access_from_file_urls(True)
# self.set_enable_java(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_print_backgrounds(False)
self.set_enable_tabs_to_links(False)
self.set_enable_fullscreen(True)
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}")

View File

@ -1,67 +0,0 @@
# Python imports
# Lib imports
import gi
gi.require_version('Gdk', '3.0')
gi.require_version('WebKit2', '4.0')
from gi.repository import Gdk
from gi.repository import WebKit2
# Application imports
from libs.settings_manager.other.webkit_ui_settings import WebkitUISettings
class WebkitUI(WebKit2.WebView):
def __init__(self):
super(WebkitUI, self).__init__()
self._setup_styling()
self._subscribe_to_events()
self._load_view()
self._setup_content_manager()
self.show_all()
def _setup_styling(self):
self.set_vexpand(True)
self.set_hexpand(True)
self.set_background_color( Gdk.RGBA(0, 0, 0, 0.0) )
def _subscribe_to_events(self):
event_system.subscribe(f"ui_message", self.ui_message)
def _load_settings(self):
self.set_settings( WebkitUISettings() )
def _load_view(self):
path = settings_manager.get_context_path()
data = None
with open(f"{path}/index.html", "r") as f:
data = f.read()
self.load_html(content = data, base_uri = f"file://{path}/")
def _setup_content_manager(self):
content_manager = self.get_user_content_manager()
content_manager.connect("script-message-received", self._process_js_message)
content_manager.register_script_message_handler("backend")
def _process_js_message(self, user_content_manager, js_result):
js_value = js_result.get_js_value()
message = js_value.to_string()
try:
event = Event( **json.loads(message) )
event_system.emit("handle_bridge_event", (event,))
except Exception as e:
logger.info(e)
def ui_message(self, message, mtype):
command = f"displayMessage('{message}', '{mtype}', '3')"
self.run_javascript(command, None, None)
def run_javascript(self, script, cancellable, callback):
logger.debug(script)
super().run_javascript(script, cancellable, callback)

View File

@ -58,8 +58,8 @@ class Window(Gtk.ApplicationWindow):
GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, signal.SIGINT, self._tear_down) GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, signal.SIGINT, self._tear_down)
def _subscribe_to_events(self): def _subscribe_to_events(self):
event_system.subscribe("tear_down", self._tear_down) event_system.subscribe("tear-down", self._tear_down)
event_system.subscribe("load_interactive_debug", self._load_interactive_debug) event_system.subscribe("load-interactive-debug", self._load_interactive_debug)
def _load_widgets(self, args, unknownargs): def _load_widgets(self, args, unknownargs):
if settings_manager.is_debug(): if settings_manager.is_debug():
@ -107,17 +107,17 @@ class Window(Gtk.ApplicationWindow):
def _on_focus_in_event(self, widget, event): def _on_focus_in_event(self, widget, event):
event_system.emit("pause_dnd_signals") event_system.emit("pause-dnd-signals")
def _on_focus_out_event(self, widget, event): def _on_focus_out_event(self, widget, event):
event_system.emit("listen_dnd_signals") event_system.emit("listen-dnd-signals")
def _load_interactive_debug(self): def _load_interactive_debug(self):
self.set_interactive_debugging(True) self.set_interactive_debugging(True)
def _tear_down(self, widget = None, eve = None): def _tear_down(self, widget = None, eve = None):
event_system.emit("shutting_down") event_system.emit("shutting-down")
size = self.get_size() size = self.get_size()
pos = self.get_position() pos = self.get_position()
@ -132,4 +132,4 @@ class Window(Gtk.ApplicationWindow):
Gtk.main_quit() Gtk.main_quit()
def main(self): def main(self):
Gtk.main() Gtk.main()

View File

@ -35,7 +35,7 @@ class IPCServer(Singleton):
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)
def create_ipc_listener(self) -> None: def create_ipc_listener(self) -> None:
@ -74,12 +74,12 @@ class IPCServer(Singleton):
if "FILE|" in msg: if "FILE|" in msg:
file = msg.split("FILE|")[1].strip() file = msg.split("FILE|")[1].strip()
if file: if file:
event_system.emit("handle_file_from_ipc", file) event_system.emit("handle-file-from-ipc", file)
if "DIR|" in msg: if "DIR|" in msg:
file = msg.split("DIR|")[1].strip() file = msg.split("DIR|")[1].strip()
if file: if file:
event_system.emit("handle_dir_from_ipc", file) event_system.emit("handle-dir-from-ipc", file)
conn.close() conn.close()
break break

View File

@ -67,4 +67,4 @@ class DnDMixin:
files.append(gfile) files.append(gfile)
event_system.emit('set_pre_drop_dnd', (files,)) event_system.emit('set-pre-drop-dnd', (files,))

View File

@ -1,24 +1,24 @@
{ {
"keybindings": { "keybindings": {
"help" : "F1", "help" : "F1",
"rename_files" : ["F2", "<Control>e"], "rename-files" : ["F2", "<Control>e"],
"open_terminal" : "F4", "open-terminal" : "F4",
"refresh_tab" : ["F5", "<Control>r"], "refresh-tab" : ["F5", "<Control>r"],
"delete_files" : "Delete", "delete-files" : "Delete",
"tggl_top_main_menubar" : "Alt_L", "tggl-top-main-menubar" : "Alt_L",
"tggl_top_main_menubar" : "<Control>0", "tggl-top-main-menubar" : "<Control>0",
"trash_files" : "<Shift><Control>t", "trash-files" : "<Shift><Control>t",
"tear_down" : "<Control>q", "tear-down" : "<Control>q",
"go_up" : "<Control>Up", "go-up" : "<Control>Up",
"go_home" : "<Control>slash", "go-home" : "<Control>slash",
"grab_focus_path_entry" : "<Control>l", "grab-focus-path-entry" : "<Control>l",
"open_files" : "<Control>o", "open-files" : "<Control>o",
"show_hide_hidden_files" : "<Control>h", "show-hide-hidden-files" : "<Control>h",
"keyboard_create_tab" : "<Control>t", "keyboard-create-tab" : "<Control>t",
"keyboard_close_tab" : "<Control>w", "keyboard-close-tab" : "<Control>w",
"keyboard_copy_files" : "<Control>c", "keyboard-copy-files" : "<Control>c",
"keyboard_cut_files" : "<Control>x", "keyboard-cut-files" : "<Control>x",
"paste_files" : "<Control>v", "paste-files" : "<Control>v",
"show_new_file_menu" : "<Control>n" "show-new-file-menu" : "<Control>n"
} }
} }