From 5b0ec56c5b704116730b33e51979e2082c9dc665 Mon Sep 17 00:00:00 2001 From: yutent Date: Tue, 1 Aug 2023 18:40:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0md5=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inject.js | 11 +++++------ main.py | 30 +++++++++++------------------- webview/app.js | 1 + 3 files changed, 17 insertions(+), 25 deletions(-) diff --git a/inject.js b/inject.js index 29a87ac..769db4e 100644 --- a/inject.js +++ b/inject.js @@ -227,12 +227,6 @@ Object.assign(native, { }, copy(filepath, target) { return handler('fs', { action: 'copy', filepath, target }) - }, - async upload(file) { - return handler('fs', { - action: 'upload', - file: new Uint8Array(await file.arrayBuffer()) - }) } }, image(filepath) { @@ -387,5 +381,10 @@ Object.assign(native, { null ) }, + + md5(value = '') { + return handler('md5', { value }) + }, + handler }) diff --git a/main.py b/main.py index be88d50..930de2e 100755 --- a/main.py +++ b/main.py @@ -1,6 +1,6 @@ #!/usr/bin/python3 -import gi, json, os, shutil +import gi, json, os, shutil, hashlib gi.require_version("Gtk", "3.0") @@ -27,8 +27,6 @@ except (ValueError, ImportError): Keybinder.init() -# im_context = Gtk.IMContext() - class WebKitWindow(Gtk.Window): def __init__(self): @@ -37,7 +35,7 @@ class WebKitWindow(Gtk.Window): Gtk.Window.__init__(self, title="WebKit Example") self.notify = Notification(self) - # Notification.__init__(self.notify, ) + self.display = Gdk.Display.get_default() self.set_default_size(800, 600) @@ -48,7 +46,6 @@ class WebKitWindow(Gtk.Window): settings.set_enable_developer_extras(True) # settings.set_disable_web_security(True) - settings.set_enable_html5_database(True) @@ -85,9 +82,8 @@ class WebKitWindow(Gtk.Window): im = self.webview.get_input_method_context() im.set_enable_preedit(True) - # self.webview.load_uri("http://127.0.0.1:10086/index.html") - self.webview.load_uri("app:///index.html") - # self.webview.load_uri("https://benchmark.wkit.fun") + # self.webview.load_uri("app:///index.html") + self.webview.load_uri("https://benchmark.wkit.fun") # 解决输入法候选框跟随问题 @@ -104,8 +100,7 @@ class WebKitWindow(Gtk.Window): def on_preedit_changed(self, im): - display = Gdk.Display.get_default() - p = display.get_pointer() # 光标位置 + p = self.display.get_pointer() # 光标位置 x, y = self.get_position() # 窗口位置 im.notify_focus_in() @@ -246,11 +241,7 @@ class WebKitWindow(Gtk.Window): if params['action'] == 'isdir': output = os.path.isdir(filepath) - - if params['action'] == 'upload': - print(params) - case 'clipboard': # 读文本 @@ -296,14 +287,12 @@ class WebKitWindow(Gtk.Window): case 'monitor': if params['action'] == 'get-all': - display = Gdk.Display.get_default() - monitor_num = display.get_n_monitors() - monitors = [display.get_monitor(i) for i in range(monitor_num)] + monitor_num = self.display.get_n_monitors() + monitors = [self.display.get_monitor(i) for i in range(monitor_num)] output = [get_monitor_info(m) for m in monitors] elif params['action'] == 'get-primary': - display = Gdk.Display.get_default() - monitor = display.get_primary_monitor() + monitor = self.display.get_primary_monitor() output = get_monitor_info(monitor) case 'keybinder': @@ -389,6 +378,9 @@ class WebKitWindow(Gtk.Window): self.notify.create(title, summary, icon, progress, urgency, params.get('callback')) + case 'md5': + output = hashlib.md5(str(params.get('value'))).hexdigest() + # 有回调则返回结果 if callback: self.call_js(callback, output) diff --git a/webview/app.js b/webview/app.js index b8f9b99..fab05f9 100644 --- a/webview/app.js +++ b/webview/app.js @@ -114,6 +114,7 @@ class App extends Component { let file = ev.target.files[0] let u8 = new Uint8Array(await file.arrayBuffer()) console.log(u8) + // 分片写入 for (let i = 0; i <= u8.length; i += 2048) { await native.fs.write( '/code/gtk/webkit/demo.png',