修复js注入; 增加ENV注入

master
yutent 2023-09-04 18:29:12 +08:00
parent 68a773bb0c
commit 2ddfa5e2ab
6 changed files with 24 additions and 6 deletions

View File

@ -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

2
debian/control vendored
View File

@ -1,5 +1,5 @@
Package: python3-webengine-gtk3
Version: 0.2.0
Version: 0.3.0
Section: develop
Priority: optional
Maintainer: Yutent <yutent.io@gmail.com>

View File

@ -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))

View File

@ -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)

View File

@ -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')

View File

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