quit方法移入app对象; app新增relaunch方法

master
yutent 2023-09-08 18:38:39 +08:00
parent 6e0beb6a66
commit b9e7144271
2 changed files with 36 additions and 22 deletions

View File

@ -3,7 +3,7 @@
# @date 2023/08/08 14:07:26
import gi, os, json, shutil, hashlib, random
import gi, os, sys, json, shutil, hashlib, random
gi.require_version('Gtk', '3.0')
gi.require_version("WebKit2", "4.1")
@ -183,21 +183,16 @@ class WebEngine(WebKit2.WebView):
match event:
case 'init':
output = env
case 'app':
_error, output = self._app_handler(params)
case 'fs':
_error, output = self._fs_setting(params)
_error, output = self._fs_handler(params)
case 'clipboard':
_error, output = self._clipboard_setting(params)
# 退出app
case 'quit':
self.close_window()
self.emit('quit')
_error, output = self._clipboard_handler(params)
# 读取图片, 返回图片像素数据
case 'image':
@ -217,7 +212,7 @@ class WebEngine(WebKit2.WebView):
case 'keybinder':
_error, output = self._keybinder_setting(params)
_error, output = self._keybinder_handler(params)
case 'tray':
@ -257,7 +252,7 @@ class WebEngine(WebKit2.WebView):
return
case 'window':
_error, output = self._window_setting(params)
_error, output = self._window_handler(params)
case 'notify':
@ -274,7 +269,7 @@ class WebEngine(WebKit2.WebView):
case 'proxy':
_error, output = self._proxy_setting(params)
_error, output = self._proxy_handler(params)
case 'md5':
@ -291,8 +286,23 @@ class WebEngine(WebKit2.WebView):
self.call_js(callback, output, _error)
def _app_handler(self, params = {}):
_error = None
output = None
match(params.get('action')):
# 退出app
case 'quit':
self.close_window()
self.emit('quit')
def _fs_setting(self, params = {}):
case 'relaunch':
py = sys.executable
os.execl(py, py, *sys.argv)
return (_error, output)
def _fs_handler(self, params = {}):
_error = None
output = None
filepath = params.get('filepath')
@ -366,7 +376,7 @@ class WebEngine(WebKit2.WebView):
def _clipboard_setting(self, params = {}):
def _clipboard_handler(self, params = {}):
_error = None
output = None
@ -403,7 +413,7 @@ class WebEngine(WebKit2.WebView):
return (_error, output)
def _keybinder_setting(self, params = {}):
def _keybinder_handler(self, params = {}):
_error = None
output = None
keymap = params.get('value')
@ -434,7 +444,7 @@ class WebEngine(WebKit2.WebView):
def _window_setting(self, params = {}):
def _window_handler(self, params = {}):
_error = None
output = None
@ -496,7 +506,7 @@ class WebEngine(WebKit2.WebView):
def _proxy_setting(self, params = {}):
def _proxy_handler(self, params = {}):
dm = self.get_website_data_manager()
output = True
_error = None

View File

@ -209,9 +209,13 @@ native.$on('opener_message', (data, uuid) => _postMessage(data, uuid))
Object.assign(native, {
env: '{{env}}',
app: {
quit() {
return handler('quit', {}, NO_CALLBACK)
return handler('app', { action: 'quit' }, NO_CALLBACK)
},
relaunch() {
return handler('app', { action: 'relaunch' }, NO_CALLBACK)
}
},
fs: {
access(filepath, mode = 'r') {