增加app_name和app_version的设置及注入
parent
b9e7144271
commit
c17d171ad8
|
@ -15,11 +15,15 @@ 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()
|
code = 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_data = script_data.replace("'{{env}}'", json.dumps(env)).replace("{{uuid}}", webview.uuid)
|
code = code.replace("'{{env}}'", json.dumps(env))
|
||||||
script = WebKit2.UserScript(script_data, frame, time, None, None)
|
code = code.replace("{{uuid}}", webview.uuid)
|
||||||
|
code = code.replace("{{app_name}}", webview.app_name)
|
||||||
|
code = code.replace("{{app_version}}", webview.app_version)
|
||||||
|
|
||||||
|
script = WebKit2.UserScript(code, frame, time, None, None)
|
||||||
|
|
||||||
self.manager.add_script(script)
|
self.manager.add_script(script)
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ class Settings(WebKit2.Settings):
|
||||||
self.set_javascript_can_open_windows_automatically(True)
|
self.set_javascript_can_open_windows_automatically(True)
|
||||||
|
|
||||||
|
|
||||||
self.set_user_agent_with_application_details('WebEngine', version)
|
self.set_useragent_with_app('WebEngine', version)
|
||||||
|
|
||||||
|
|
||||||
# indexedDB 和 localStorage 和 离线缓存
|
# indexedDB 和 localStorage 和 离线缓存
|
||||||
|
@ -43,6 +43,9 @@ class Settings(WebKit2.Settings):
|
||||||
self.set_media_playback_allows_inline(True)
|
self.set_media_playback_allows_inline(True)
|
||||||
|
|
||||||
|
|
||||||
|
def set_useragent_with_app(self, name, ver):
|
||||||
|
self.set_user_agent_with_application_details(name, ver)
|
||||||
|
|
||||||
def set_useragent(self, str):
|
def set_useragent(self, str):
|
||||||
self.set_user_agent(str)
|
self.set_user_agent(str)
|
||||||
|
|
||||||
|
@ -75,6 +78,9 @@ def create_setting(options = None):
|
||||||
setting.enable_devtools()
|
setting.enable_devtools()
|
||||||
setting.mock_devices()
|
setting.mock_devices()
|
||||||
|
|
||||||
|
if options.get('app_name') and options.get('app_version'):
|
||||||
|
setting.set_useragent_with_app(options['app_name'], options['app_version'])
|
||||||
|
|
||||||
if options.get('useragent'):
|
if options.get('useragent'):
|
||||||
setting.set_useragent(options.get('useragent'))
|
setting.set_useragent(options.get('useragent'))
|
||||||
|
|
||||||
|
@ -86,6 +92,9 @@ def create_setting(options = None):
|
||||||
|
|
||||||
|
|
||||||
def wrapper(app, extra = None):
|
def wrapper(app, extra = None):
|
||||||
|
if options is not None:
|
||||||
|
app.app_name = options.get('app_name')
|
||||||
|
app.app_version = options.get('app_version')
|
||||||
app.set_settings(setting)
|
app.set_settings(setting)
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
|
@ -31,10 +31,7 @@ try:
|
||||||
except:
|
except:
|
||||||
Keybinder = None
|
Keybinder = None
|
||||||
|
|
||||||
|
from ._version import version
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
from ._settings import create_setting
|
from ._settings import create_setting
|
||||||
from ._protocal import create_protocal
|
from ._protocal import create_protocal
|
||||||
from ._notify import create_notify
|
from ._notify import create_notify
|
||||||
|
@ -60,7 +57,8 @@ class WebEngine(WebKit2.WebView):
|
||||||
__gsignals__ = {
|
__gsignals__ = {
|
||||||
'quit': (GObject.SignalFlags.RUN_FIRST, None, ())
|
'quit': (GObject.SignalFlags.RUN_FIRST, None, ())
|
||||||
}
|
}
|
||||||
|
app_name = 'WebEngine'
|
||||||
|
app_version = version
|
||||||
uuid = None
|
uuid = None
|
||||||
root = None
|
root = None
|
||||||
window = None
|
window = None
|
||||||
|
@ -84,7 +82,7 @@ class WebEngine(WebKit2.WebView):
|
||||||
opener.children.add(self)
|
opener.children.add(self)
|
||||||
|
|
||||||
if win.get_title() is None:
|
if win.get_title() is None:
|
||||||
win.set_title('WebEngine')
|
win.set_title(self.app_name)
|
||||||
|
|
||||||
if win.get_icon() is None and win.get_icon_name() is None:
|
if win.get_icon() is None and win.get_icon_name() is None:
|
||||||
win.set_icon_name('web-browser')
|
win.set_icon_name('web-browser')
|
||||||
|
|
|
@ -210,6 +210,8 @@ native.$on('opener_message', (data, uuid) => _postMessage(data, uuid))
|
||||||
Object.assign(native, {
|
Object.assign(native, {
|
||||||
env: '{{env}}',
|
env: '{{env}}',
|
||||||
app: {
|
app: {
|
||||||
|
name: '{{app_name}}',
|
||||||
|
version: '{{app_version}}',
|
||||||
quit() {
|
quit() {
|
||||||
return handler('app', { action: 'quit' }, NO_CALLBACK)
|
return handler('app', { action: 'quit' }, NO_CALLBACK)
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue