diff --git a/usr/lib/python3/dist-packages/webengine/gtk3/_inject.py b/usr/lib/python3/dist-packages/webengine/gtk3/_inject.py index f58a4a7..3033595 100644 --- a/usr/lib/python3/dist-packages/webengine/gtk3/_inject.py +++ b/usr/lib/python3/dist-packages/webengine/gtk3/_inject.py @@ -15,11 +15,15 @@ class Inject: 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 time = WebKit2.UserScriptInjectionTime.END - script_data = script_data.replace("'{{env}}'", json.dumps(env)).replace("{{uuid}}", webview.uuid) - script = WebKit2.UserScript(script_data, frame, time, None, None) + code = code.replace("'{{env}}'", json.dumps(env)) + 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) diff --git a/usr/lib/python3/dist-packages/webengine/gtk3/_settings.py b/usr/lib/python3/dist-packages/webengine/gtk3/_settings.py index 228ac57..e9a261d 100644 --- a/usr/lib/python3/dist-packages/webengine/gtk3/_settings.py +++ b/usr/lib/python3/dist-packages/webengine/gtk3/_settings.py @@ -22,7 +22,7 @@ class Settings(WebKit2.Settings): 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 和 离线缓存 @@ -43,6 +43,9 @@ class Settings(WebKit2.Settings): 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): self.set_user_agent(str) @@ -75,6 +78,9 @@ def create_setting(options = None): setting.enable_devtools() 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'): setting.set_useragent(options.get('useragent')) @@ -86,6 +92,9 @@ def create_setting(options = 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) return wrapper \ No newline at end of file diff --git a/usr/lib/python3/dist-packages/webengine/gtk3/_webengine.py b/usr/lib/python3/dist-packages/webengine/gtk3/_webengine.py index af63b2d..74835f1 100644 --- a/usr/lib/python3/dist-packages/webengine/gtk3/_webengine.py +++ b/usr/lib/python3/dist-packages/webengine/gtk3/_webengine.py @@ -31,10 +31,7 @@ try: except: Keybinder = None - - - - +from ._version import version from ._settings import create_setting from ._protocal import create_protocal from ._notify import create_notify @@ -60,7 +57,8 @@ class WebEngine(WebKit2.WebView): __gsignals__ = { 'quit': (GObject.SignalFlags.RUN_FIRST, None, ()) } - + app_name = 'WebEngine' + app_version = version uuid = None root = None window = None @@ -84,7 +82,7 @@ class WebEngine(WebKit2.WebView): opener.children.add(self) 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: win.set_icon_name('web-browser') diff --git a/usr/lib/python3/dist-packages/webengine/gtk3/inject.js b/usr/lib/python3/dist-packages/webengine/gtk3/inject.js index 126d12c..d243f66 100644 --- a/usr/lib/python3/dist-packages/webengine/gtk3/inject.js +++ b/usr/lib/python3/dist-packages/webengine/gtk3/inject.js @@ -210,6 +210,8 @@ native.$on('opener_message', (data, uuid) => _postMessage(data, uuid)) Object.assign(native, { env: '{{env}}', app: { + name: '{{app_name}}', + version: '{{app_version}}', quit() { return handler('app', { action: 'quit' }, NO_CALLBACK) },