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 +})()