Compare commits

..

No commits in common. "2aaa711a8984cd1dd536f2982435c3e60c451290" and "68a773bb0c4afb8b68a0ea0a0440a3c27febaa26" have entirely different histories.

6 changed files with 28 additions and 74 deletions

View File

@ -4,7 +4,7 @@ if [ -d unpack ]; then
sudo rm -rf unpack sudo rm -rf unpack
fi fi
version="0.3.0" version="0.2.0"
mkdir -p unpack/DEBIAN mkdir -p unpack/DEBIAN

2
debian/control vendored
View File

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

View File

@ -2,13 +2,10 @@
# @author yutent<yutent.io@gmail.com> # @author yutent<yutent.io@gmail.com>
# @date 2023/08/31 11:55:25 # @date 2023/08/31 11:55:25
# from webengine.gtk3._webengine import WebEngine from webengine.gtk3._webengine import WebEngine
# from webengine.gtk3._settings import create_setting from webengine.gtk3._settings import create_setting
# from webengine.gtk3._hotreload import create_hmr_server from webengine.gtk3._hotreload import create_hmr_server
from ._webengine import WebEngine
from ._settings import create_setting
from ._hotreload import create_hmr_server
build = (0, 3, 0) build = (0, 2, 0)
version = '.'.join(map(str, build)) version = '.'.join(map(str, build))

View File

@ -3,7 +3,7 @@
# @date 2023/08/08 15:00:27 # @date 2023/08/08 15:00:27
import os, gi, json import os, gi
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_data = open(self.abspath('./inject.js'), 'r').read() script = 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_data, frame, time, None, None) script = WebKit2.UserScript(script, frame, time, None, None)
self.manager.add_script(script) self.manager.add_script(script)

View File

@ -40,14 +40,6 @@ 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
@ -112,10 +104,8 @@ class WebEngine(WebKit2.WebView):
im.notify_cursor_area(p.x - x, p.y - y, 0, 0) # 修正输入法跟随 im.notify_cursor_area(p.x - x, p.y - y, 0, 0) # 修正输入法跟随
def call_js(self, method, data = None, err = None): def call_js(self, method, data = None):
if err is not None: scripts = 'native.$emit("' + method + '",' + json.dumps(data) + ')'
err = str(err)
scripts = 'native.$emit("' + method + '", ' + json.dumps(err) + ', ' + json.dumps(data) + ')'
self.evaluate_javascript(scripts, -1) self.evaluate_javascript(scripts, -1)
@ -127,35 +117,21 @@ class WebEngine(WebKit2.WebView):
callback = data.get('callback') callback = data.get('callback')
params = data.get('data') params = data.get('data')
output = None output = None
_error = None
match event: match event:
case 'init':
output = env
case 'fs': case 'fs':
filepath = params.get('filepath') filepath = params.get('filepath')
if params['action'] == 'access': if params['action'] == 'read':
try: with open(filepath, params.get('mode')) as file:
with open(filepath, params.get('mode')) as file: output = file.read()
output = True if params.get('mode').find('b') > -1:
except Exception as err: output = list(output)
output = False
elif params['action'] == 'read': if params['action'] == 'write':
try:
with open(filepath, params.get('mode')) as file:
output = file.read()
if params.get('mode').find('b') > -1:
output = list(output)
except Exception as err:
_error = err
elif params['action'] == 'write': # 调整以支持二进制数据写入
# 调整以支持二进制数据写入
try:
with open(filepath, params.get('mode')) as file: with open(filepath, params.get('mode')) as file:
buff = params['content'] buff = params['content']
@ -163,13 +139,11 @@ class WebEngine(WebKit2.WebView):
buff = bytes(buff) buff = bytes(buff)
output = file.write(buff) output = file.write(buff)
except Exception as err:
_error = err
elif params['action'] == 'exists': if params['action'] == 'exists':
output = os.path.exists(filepath) output = os.path.exists(filepath)
elif params['action'] == 'list': if params['action'] == 'list':
with os.scandir(filepath) as entries: with os.scandir(filepath) as entries:
output = [{ output = [{
"name": it.name, "name": it.name,
@ -180,24 +154,24 @@ class WebEngine(WebKit2.WebView):
"mtime": int(it.stat().st_mtime), "mtime": int(it.stat().st_mtime),
} for it in entries] } for it in entries]
elif params['action'] == 'remove': if params['action'] == 'remove':
if os.path.isfile(filepath): if os.path.isfile(filepath):
output = os.remove(filepath) output = os.remove(filepath)
elif os.path.isdir(filepath): elif os.path.isdir(filepath):
output = os.removedirs(filename) output = os.removedirs(filename)
elif params['action'] == 'rename': if params['action'] == 'rename':
if os.path.exists(filepath): if os.path.exists(filepath):
output = shutil.move(filepath, params['target']) output = shutil.move(filepath, params['target'])
elif params['action'] == 'copy': if params['action'] == 'copy':
if os.path.exists(filepath): if os.path.exists(filepath):
output = shutil.copy2(filepath, params['target']) output = shutil.copy2(filepath, params['target'])
elif params['action'] == 'isfile': if params['action'] == 'isfile':
output = os.path.isfile(filepath) output = os.path.isfile(filepath)
elif params['action'] == 'isdir': if params['action'] == 'isdir':
output = os.path.isdir(filepath) output = os.path.isdir(filepath)
@ -346,5 +320,5 @@ class WebEngine(WebKit2.WebView):
# 有回调则返回结果 # 有回调则返回结果
if callback: if callback:
self.call_js(callback, output, _error) self.call_js(callback, output)

View File

@ -64,13 +64,7 @@ function handler(event, data = {}, once = true) {
if (typeof once === 'boolean') { if (typeof once === 'boolean') {
callback = rand() callback = rand()
native[once ? '$once' : '$on'](callback, (err, res) => { native[once ? '$once' : '$on'](callback, _.resolve)
if (err) {
_.reject(err)
} else {
_.resolve(res)
}
})
} else { } else {
_.resolve(true) _.resolve(true)
} }
@ -193,10 +187,6 @@ Object.assign(native, {
return handler('quit', {}, null) return handler('quit', {}, null)
}, },
fs: { fs: {
access(filepath, mode = 'r') {
return handler('fs', { action: 'access', mode, filepath })
},
read(filepath, mode = 'r') { read(filepath, mode = 'r') {
return handler('fs', { action: 'read', mode, filepath }).then(r => return handler('fs', { action: 'read', mode, filepath }).then(r =>
mode.includes('b') ? new Uint8Array(r) : r mode.includes('b') ? new Uint8Array(r) : r
@ -205,7 +195,6 @@ 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
@ -214,7 +203,6 @@ 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
@ -401,8 +389,3 @@ Object.assign(native, {
handler handler
}) })
!(async function () {
let env = await handler('init') //.then(r => (native.env = r))
native.env = env
})()