修复fs模式错误; 增加window.open的支持

master
yutent 2023-09-06 17:02:37 +08:00
parent fe56af2292
commit 8822c8effd
2 changed files with 21 additions and 5 deletions

View File

@ -96,6 +96,22 @@ class WebEngine(WebKit2.WebView):
Inject(self, env).connect(self.called_by_js)
self.connect('create', self.create_new_window)
def create_new_window(self, webview, nav):
req = nav.get_request()
w, h = self.window.get_size()
win = Gtk.Window()
web = WebEngine(win)
web.set_settings(self.get_settings())
web.load_request(req)
win.set_default_size(w, h)
win.add(web)
win.show_all()
def set_root(self, root):
self.root = root
@ -147,6 +163,7 @@ class WebEngine(WebKit2.WebView):
# 退出app
case 'quit':
self.window.close()
self.emit('quit')
# 读取图片, 返回图片像素数据
@ -221,7 +238,8 @@ class WebEngine(WebKit2.WebView):
match(params.get('action')):
case 'access':
try:
with open(filepath, params.get('mode')) as file:
file = open(filepath, params.get('mode'))
file.close()
output = True
except Exception as err:
output = False

View File

@ -208,16 +208,14 @@ Object.assign(native, {
return handler('fs', {
action: 'write',
mode,
append: false,
filepath,
content
})
},
append(filepath, content = '', mode = 'w') {
append(filepath, content = '', mode = 'a+') {
return handler('fs', {
action: 'write',
mode,
append: true,
filepath,
content
})