From ece744aafe7e7eba049fb706a0d16a2f9fa8799b Mon Sep 17 00:00:00 2001 From: yutent Date: Tue, 12 Sep 2023 18:55:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0shell=E6=93=8D=E4=BD=9C?= 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 | 6 +++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/usr/lib/python3/dist-packages/webengine/gtk3/_webengine.py b/usr/lib/python3/dist-packages/webengine/gtk3/_webengine.py index 832b965..a82f925 100644 --- a/usr/lib/python3/dist-packages/webengine/gtk3/_webengine.py +++ b/usr/lib/python3/dist-packages/webengine/gtk3/_webengine.py @@ -3,7 +3,8 @@ # @date 2023/08/08 14:07:26 -import gi, os, sys, json, shutil, hashlib, random +import gi, os, sys, json +import webbrowser, shutil, hashlib, random gi.require_version('Gtk', '3.0') gi.require_version("WebKit2", "4.1") @@ -288,6 +289,25 @@ class WebEngine(WebKit2.WebView): return (_error, output) + def _shell_handler(self, params = {}): + _error = None + output = None + path = params.get('path') + + match(params.get('action')): + case 'openExternal': + webbrowser.open(params.get('url')) + + case 'showItemInFolder': + os.system(f"xdg-open '{path}'") + + case 'openPath': + os.system(f"xdg-open '{path}'") + + case 'trashItem': + pass + + def _fs_handler(self, params = {}): _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 c508c3d..b5a4827 100644 --- a/usr/lib/python3/dist-packages/webengine/gtk3/inject.js +++ b/usr/lib/python3/dist-packages/webengine/gtk3/inject.js @@ -241,6 +241,12 @@ return native.env.LANG } }, + shell: { + openExternal(url) {}, + showItemInFolder(path) {}, + openPath(path) {}, + trashItem(path) {} + }, fs: { access(filepath, mode = 'r') { return handler('fs', { action: 'access', mode, filepath })