修复js注入; 增加ENV注入
parent
68a773bb0c
commit
2ddfa5e2ab
2
build.sh
2
build.sh
|
@ -4,7 +4,7 @@ if [ -d unpack ]; then
|
||||||
sudo rm -rf unpack
|
sudo rm -rf unpack
|
||||||
fi
|
fi
|
||||||
|
|
||||||
version="0.2.0"
|
version="0.3.0"
|
||||||
|
|
||||||
mkdir -p unpack/DEBIAN
|
mkdir -p unpack/DEBIAN
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
Package: python3-webengine-gtk3
|
Package: python3-webengine-gtk3
|
||||||
Version: 0.2.0
|
Version: 0.3.0
|
||||||
Section: develop
|
Section: develop
|
||||||
Priority: optional
|
Priority: optional
|
||||||
Maintainer: Yutent <yutent.io@gmail.com>
|
Maintainer: Yutent <yutent.io@gmail.com>
|
||||||
|
|
|
@ -7,5 +7,5 @@ from webengine.gtk3._settings import create_setting
|
||||||
from webengine.gtk3._hotreload import create_hmr_server
|
from webengine.gtk3._hotreload import create_hmr_server
|
||||||
|
|
||||||
|
|
||||||
build = (0, 2, 0)
|
build = (0, 3, 0)
|
||||||
version = '.'.join(map(str, build))
|
version = '.'.join(map(str, build))
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
# @date 2023/08/08 15:00:27
|
# @date 2023/08/08 15:00:27
|
||||||
|
|
||||||
|
|
||||||
import os, gi
|
import os, gi, json
|
||||||
|
|
||||||
gi.require_version("WebKit2", "4.1")
|
gi.require_version("WebKit2", "4.1")
|
||||||
|
|
||||||
|
@ -15,10 +15,10 @@ class Inject:
|
||||||
|
|
||||||
self.manager = webview.get_user_content_manager()
|
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
|
frame = WebKit2.UserContentInjectedFrames.ALL_FRAMES
|
||||||
time = WebKit2.UserScriptInjectionTime.END
|
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)
|
self.manager.add_script(script)
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,14 @@ from ._inject import Inject
|
||||||
from ._utils import get_monitor_info, pixbuf_to_dict, dict_to_pixbuf
|
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():
|
def noop():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -120,6 +128,9 @@ class WebEngine(WebKit2.WebView):
|
||||||
|
|
||||||
|
|
||||||
match event:
|
match event:
|
||||||
|
case 'init':
|
||||||
|
output = env
|
||||||
|
|
||||||
case 'fs':
|
case 'fs':
|
||||||
filepath = params.get('filepath')
|
filepath = params.get('filepath')
|
||||||
|
|
||||||
|
|
|
@ -195,6 +195,7 @@ Object.assign(native, {
|
||||||
write(filepath, content = '', mode = 'w') {
|
write(filepath, content = '', mode = 'w') {
|
||||||
return handler('fs', {
|
return handler('fs', {
|
||||||
action: 'write',
|
action: 'write',
|
||||||
|
mode,
|
||||||
append: false,
|
append: false,
|
||||||
filepath,
|
filepath,
|
||||||
content
|
content
|
||||||
|
@ -203,6 +204,7 @@ Object.assign(native, {
|
||||||
append(filepath, content = '', mode = 'w') {
|
append(filepath, content = '', mode = 'w') {
|
||||||
return handler('fs', {
|
return handler('fs', {
|
||||||
action: 'write',
|
action: 'write',
|
||||||
|
mode,
|
||||||
append: true,
|
append: true,
|
||||||
filepath,
|
filepath,
|
||||||
content
|
content
|
||||||
|
@ -389,3 +391,8 @@ Object.assign(native, {
|
||||||
|
|
||||||
handler
|
handler
|
||||||
})
|
})
|
||||||
|
|
||||||
|
!(async function () {
|
||||||
|
let env = await handler('init') //.then(r => (native.env = r))
|
||||||
|
native.env = env
|
||||||
|
})()
|
||||||
|
|
Loading…
Reference in New Issue