From 8822c8effd042f963ee4922696648a336d490f1a Mon Sep 17 00:00:00 2001 From: yutent Date: Wed, 6 Sep 2023 17:02:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dfs=E6=A8=A1=E5=BC=8F=E9=94=99?= =?UTF-8?q?=E8=AF=AF;=20=E5=A2=9E=E5=8A=A0window.open=E7=9A=84=E6=94=AF?= =?UTF-8?q?=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../webengine/gtk3/_webengine.py | 22 +++++++++++++++++-- .../dist-packages/webengine/gtk3/inject.js | 4 +--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/usr/lib/python3/dist-packages/webengine/gtk3/_webengine.py b/usr/lib/python3/dist-packages/webengine/gtk3/_webengine.py index 2d3b488..6352c25 100644 --- a/usr/lib/python3/dist-packages/webengine/gtk3/_webengine.py +++ b/usr/lib/python3/dist-packages/webengine/gtk3/_webengine.py @@ -96,6 +96,22 @@ class WebEngine(WebKit2.WebView): Inject(self, env).connect(self.called_by_js) + self.connect('create', self.create_new_window) + + + + + def create_new_window(self, webview, nav): + req = nav.get_request() + w, h = self.window.get_size() + win = Gtk.Window() + web = WebEngine(win) + web.set_settings(self.get_settings()) + web.load_request(req) + win.set_default_size(w, h) + win.add(web) + win.show_all() + def set_root(self, root): self.root = root @@ -147,6 +163,7 @@ class WebEngine(WebKit2.WebView): # 退出app case 'quit': + self.window.close() self.emit('quit') # 读取图片, 返回图片像素数据 @@ -221,8 +238,9 @@ class WebEngine(WebKit2.WebView): match(params.get('action')): case 'access': try: - with open(filepath, params.get('mode')) as file: - output = True + file = open(filepath, params.get('mode')) + file.close() + output = True except Exception as err: output = False diff --git a/usr/lib/python3/dist-packages/webengine/gtk3/inject.js b/usr/lib/python3/dist-packages/webengine/gtk3/inject.js index f7196a0..6147341 100644 --- a/usr/lib/python3/dist-packages/webengine/gtk3/inject.js +++ b/usr/lib/python3/dist-packages/webengine/gtk3/inject.js @@ -208,16 +208,14 @@ Object.assign(native, { return handler('fs', { action: 'write', mode, - append: false, filepath, content }) }, - append(filepath, content = '', mode = 'w') { + append(filepath, content = '', mode = 'a+') { return handler('fs', { action: 'write', mode, - append: true, filepath, content })