From b9e7144271f2b7eb85c5d708be426410e68f8f16 Mon Sep 17 00:00:00 2001 From: yutent Date: Fri, 8 Sep 2023 18:38:39 +0800 Subject: [PATCH] =?UTF-8?q?quit=E6=96=B9=E6=B3=95=E7=A7=BB=E5=85=A5app?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1;=20app=E6=96=B0=E5=A2=9Erelaunch=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../webengine/gtk3/_webengine.py | 48 +++++++++++-------- .../dist-packages/webengine/gtk3/inject.js | 10 ++-- 2 files changed, 36 insertions(+), 22 deletions(-) diff --git a/usr/lib/python3/dist-packages/webengine/gtk3/_webengine.py b/usr/lib/python3/dist-packages/webengine/gtk3/_webengine.py index 5f55812..af63b2d 100644 --- a/usr/lib/python3/dist-packages/webengine/gtk3/_webengine.py +++ b/usr/lib/python3/dist-packages/webengine/gtk3/_webengine.py @@ -3,7 +3,7 @@ # @date 2023/08/08 14:07:26 -import gi, os, json, shutil, hashlib, random +import gi, os, sys, json, shutil, hashlib, random gi.require_version('Gtk', '3.0') gi.require_version("WebKit2", "4.1") @@ -183,22 +183,17 @@ class WebEngine(WebKit2.WebView): match event: - case 'init': - output = env + + case 'app': + _error, output = self._app_handler(params) case 'fs': - _error, output = self._fs_setting(params) + _error, output = self._fs_handler(params) case 'clipboard': - _error, output = self._clipboard_setting(params) + _error, output = self._clipboard_handler(params) - - # 退出app - case 'quit': - self.close_window() - self.emit('quit') - # 读取图片, 返回图片像素数据 case 'image': filename = params['value'] @@ -217,7 +212,7 @@ class WebEngine(WebKit2.WebView): case 'keybinder': - _error, output = self._keybinder_setting(params) + _error, output = self._keybinder_handler(params) case 'tray': @@ -257,7 +252,7 @@ class WebEngine(WebKit2.WebView): return case 'window': - _error, output = self._window_setting(params) + _error, output = self._window_handler(params) case 'notify': @@ -274,7 +269,7 @@ class WebEngine(WebKit2.WebView): case 'proxy': - _error, output = self._proxy_setting(params) + _error, output = self._proxy_handler(params) case 'md5': @@ -291,8 +286,23 @@ class WebEngine(WebKit2.WebView): self.call_js(callback, output, _error) + def _app_handler(self, params = {}): + _error = None + output = None + match(params.get('action')): + # 退出app + case 'quit': + self.close_window() + self.emit('quit') - def _fs_setting(self, params = {}): + case 'relaunch': + py = sys.executable + os.execl(py, py, *sys.argv) + + return (_error, output) + + + def _fs_handler(self, params = {}): _error = None output = None filepath = params.get('filepath') @@ -366,7 +376,7 @@ class WebEngine(WebKit2.WebView): - def _clipboard_setting(self, params = {}): + def _clipboard_handler(self, params = {}): _error = None output = None @@ -403,7 +413,7 @@ class WebEngine(WebKit2.WebView): return (_error, output) - def _keybinder_setting(self, params = {}): + def _keybinder_handler(self, params = {}): _error = None output = None keymap = params.get('value') @@ -434,7 +444,7 @@ class WebEngine(WebKit2.WebView): - def _window_setting(self, params = {}): + def _window_handler(self, params = {}): _error = None output = None @@ -496,7 +506,7 @@ class WebEngine(WebKit2.WebView): - def _proxy_setting(self, params = {}): + def _proxy_handler(self, params = {}): dm = self.get_website_data_manager() output = True _error = None diff --git a/usr/lib/python3/dist-packages/webengine/gtk3/inject.js b/usr/lib/python3/dist-packages/webengine/gtk3/inject.js index 120a8d4..126d12c 100644 --- a/usr/lib/python3/dist-packages/webengine/gtk3/inject.js +++ b/usr/lib/python3/dist-packages/webengine/gtk3/inject.js @@ -209,9 +209,13 @@ native.$on('opener_message', (data, uuid) => _postMessage(data, uuid)) Object.assign(native, { env: '{{env}}', - - quit() { - return handler('quit', {}, NO_CALLBACK) + app: { + quit() { + return handler('app', { action: 'quit' }, NO_CALLBACK) + }, + relaunch() { + return handler('app', { action: 'relaunch' }, NO_CALLBACK) + } }, fs: { access(filepath, mode = 'r') {