From 2ddfa5e2ab40be487415448b3596d7a37d2e68d5 Mon Sep 17 00:00:00 2001 From: yutent Date: Mon, 4 Sep 2023 18:29:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Djs=E6=B3=A8=E5=85=A5;=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0ENV=E6=B3=A8=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.sh | 2 +- debian/control | 2 +- .../python3/dist-packages/webengine/gtk3/__init__.py | 2 +- .../python3/dist-packages/webengine/gtk3/_inject.py | 6 +++--- .../dist-packages/webengine/gtk3/_webengine.py | 11 +++++++++++ .../python3/dist-packages/webengine/gtk3/inject.js | 7 +++++++ 6 files changed, 24 insertions(+), 6 deletions(-) diff --git a/build.sh b/build.sh index ef08f3f..c9086fe 100755 --- a/build.sh +++ b/build.sh @@ -4,7 +4,7 @@ if [ -d unpack ]; then sudo rm -rf unpack fi -version="0.2.0" +version="0.3.0" mkdir -p unpack/DEBIAN diff --git a/debian/control b/debian/control index 70ca588..6696520 100644 --- a/debian/control +++ b/debian/control @@ -1,5 +1,5 @@ Package: python3-webengine-gtk3 -Version: 0.2.0 +Version: 0.3.0 Section: develop Priority: optional Maintainer: Yutent diff --git a/usr/lib/python3/dist-packages/webengine/gtk3/__init__.py b/usr/lib/python3/dist-packages/webengine/gtk3/__init__.py index 76b2c1b..e75f3e9 100644 --- a/usr/lib/python3/dist-packages/webengine/gtk3/__init__.py +++ b/usr/lib/python3/dist-packages/webengine/gtk3/__init__.py @@ -7,5 +7,5 @@ from webengine.gtk3._settings import create_setting from webengine.gtk3._hotreload import create_hmr_server -build = (0, 2, 0) +build = (0, 3, 0) version = '.'.join(map(str, build)) diff --git a/usr/lib/python3/dist-packages/webengine/gtk3/_inject.py b/usr/lib/python3/dist-packages/webengine/gtk3/_inject.py index 1c73b32..f22c1aa 100644 --- a/usr/lib/python3/dist-packages/webengine/gtk3/_inject.py +++ b/usr/lib/python3/dist-packages/webengine/gtk3/_inject.py @@ -3,7 +3,7 @@ # @date 2023/08/08 15:00:27 -import os, gi +import os, gi, json gi.require_version("WebKit2", "4.1") @@ -15,10 +15,10 @@ class Inject: self.manager = webview.get_user_content_manager() - script = open(self.abspath('./inject.js'), 'r').read() + script_data = open(self.abspath('./inject.js'), 'r').read() frame = WebKit2.UserContentInjectedFrames.ALL_FRAMES time = WebKit2.UserScriptInjectionTime.END - script = WebKit2.UserScript(script, frame, time, None, None) + script = WebKit2.UserScript(script_data, frame, time, None, None) self.manager.add_script(script) diff --git a/usr/lib/python3/dist-packages/webengine/gtk3/_webengine.py b/usr/lib/python3/dist-packages/webengine/gtk3/_webengine.py index 8b4d8d9..2f85a1a 100644 --- a/usr/lib/python3/dist-packages/webengine/gtk3/_webengine.py +++ b/usr/lib/python3/dist-packages/webengine/gtk3/_webengine.py @@ -40,6 +40,14 @@ from ._inject import Inject from ._utils import get_monitor_info, pixbuf_to_dict, dict_to_pixbuf + +env = { + "HOME_DIR": os.getenv('HOME'), + "CONFIG_DIR": os.path.join(os.getenv('HOME'), '.config'), + "CACHE_DIR": os.path.join(os.getenv('HOME'), '.cache') +} + + def noop(): pass @@ -120,6 +128,9 @@ class WebEngine(WebKit2.WebView): match event: + case 'init': + output = env + case 'fs': filepath = params.get('filepath') diff --git a/usr/lib/python3/dist-packages/webengine/gtk3/inject.js b/usr/lib/python3/dist-packages/webengine/gtk3/inject.js index 91ab9c4..98d55a4 100644 --- a/usr/lib/python3/dist-packages/webengine/gtk3/inject.js +++ b/usr/lib/python3/dist-packages/webengine/gtk3/inject.js @@ -195,6 +195,7 @@ Object.assign(native, { write(filepath, content = '', mode = 'w') { return handler('fs', { action: 'write', + mode, append: false, filepath, content @@ -203,6 +204,7 @@ Object.assign(native, { append(filepath, content = '', mode = 'w') { return handler('fs', { action: 'write', + mode, append: true, filepath, content @@ -389,3 +391,8 @@ Object.assign(native, { handler }) + +!(async function () { + let env = await handler('init') //.then(r => (native.env = r)) + native.env = env +})()