Added traceback on log output entry; changed js method call

This commit is contained in:
itdominator 2024-03-24 17:43:29 -05:00
parent cb7b441365
commit 01f4d17ccc
4 changed files with 24 additions and 3 deletions

View File

@ -96,6 +96,8 @@ class BridgeController:
file_type = event.ftype file_type = event.ftype
encoding_type = "utf-8" encoding_type = "utf-8"
event_system.emit(f"set_info_labels", (path, line_char, file_type, encoding_type,)) event_system.emit(f"set_info_labels", (path, line_char, file_type, encoding_type,))
case "load_javascript":
event_system.emit(f"handle_file_event_{event.originator}", (event,))
case "error": case "error":
content = base64.b64decode( event.content.encode() ).decode("utf-8") content = base64.b64decode( event.content.encode() ).decode("utf-8")
logger.info(content) logger.info(content)

View File

@ -94,6 +94,19 @@ class FilesController:
_gfiles, _gfiles,
) )
) )
case "load_javascript":
gfile = Gio.File.new_for_uri(event.fpath)
result, \
data, \
etag_out = gfile.load_contents(None)
if result:
content = base64.b64encode( data ).decode("utf-8")
event_system.emit(
f"send_script_data_{self.INDEX}",
(gfile.get_basename(), content,)
)
case _: case _:
return return

View File

@ -1,5 +1,6 @@
# Python imports # Python imports
import json import json
import traceback
# Lib imports # Lib imports
import gi import gi
@ -45,6 +46,7 @@ class AceEditor(WebKit2.WebView):
def _subscribe_to_events(self): def _subscribe_to_events(self):
event_system.subscribe(f"load_file_{self.INDEX}", self.load_file) event_system.subscribe(f"load_file_{self.INDEX}", self.load_file)
event_system.subscribe(f"send_script_data_{self.INDEX}", self.send_script_data)
event_system.subscribe(f"new_session_{self.INDEX}", self.new_session) event_system.subscribe(f"new_session_{self.INDEX}", self.new_session)
event_system.subscribe(f"switch_session_{self.INDEX}", self.switch_session) event_system.subscribe(f"switch_session_{self.INDEX}", self.switch_session)
event_system.subscribe(f"updated_session_{self.INDEX}", self.updated_session) event_system.subscribe(f"updated_session_{self.INDEX}", self.updated_session)
@ -87,12 +89,16 @@ class AceEditor(WebKit2.WebView):
event.originator = self.INDEX event.originator = self.INDEX
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(traceback.format_exc())
def load_file(self, ftype: str, fname: str, fpath: str, content: str, line: int = 0): def load_file(self, ftype: str, fname: str, fpath: str, content: str, line: int = 0):
command = f"loadFile('{ftype}', '{fname}', '{fpath}', '{content}', '{line}')" command = f"loadFile('{ftype}', '{fname}', '{fpath}', '{content}', '{line}')"
self.run_javascript(command, None, None) self.run_javascript(command, None, None)
def send_script_data(self, fname, content):
command = f"importScriptFromBackendResponse('{fname}','{content}')"
self.run_javascript(command, None, None)
def new_session(self): def new_session(self):
command = f"newSession()" command = f"newSession()"
self.run_javascript(command, None, None) self.run_javascript(command, None, None)