diff --git a/usr/lib/python3/dist-packages/webengine/gtk3/_env.py b/usr/lib/python3/dist-packages/webengine/gtk3/_env.py new file mode 100644 index 0000000..c26a99e --- /dev/null +++ b/usr/lib/python3/dist-packages/webengine/gtk3/_env.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python3 + + +import os + +home_dir = os.getenv('HOME') + +env = { + "HOME_DIR": home_dir, + "CONFIG_DIR": os.path.join(home_dir, '.config'), + "CACHE_DIR": os.path.join(home_dir, '.cache'), + "LANG": os.environ['LANG'] or "en_US.UTF-8" +} diff --git a/usr/lib/python3/dist-packages/webengine/gtk3/_inject.py b/usr/lib/python3/dist-packages/webengine/gtk3/_inject.py index 3033595..f6eee37 100644 --- a/usr/lib/python3/dist-packages/webengine/gtk3/_inject.py +++ b/usr/lib/python3/dist-packages/webengine/gtk3/_inject.py @@ -18,10 +18,13 @@ class Inject: code = open(self.abspath('./inject.js'), 'r').read() frame = WebKit2.UserContentInjectedFrames.ALL_FRAMES time = WebKit2.UserScriptInjectionTime.END + lang, charset = env['LANG'].split('.') + 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) + code = code.replace("{{lang}}", lang) script = WebKit2.UserScript(code, frame, time, None, None) diff --git a/usr/lib/python3/dist-packages/webengine/gtk3/_utils.py b/usr/lib/python3/dist-packages/webengine/gtk3/_utils.py index f0fb3d5..3a4745a 100644 --- a/usr/lib/python3/dist-packages/webengine/gtk3/_utils.py +++ b/usr/lib/python3/dist-packages/webengine/gtk3/_utils.py @@ -7,6 +7,9 @@ import gi gi.require_version('Gtk', '3.0') from gi.repository import GdkPixbuf +def noop(): + pass + def get_monitor_info(monitor): return { "model": monitor.props.model, diff --git a/usr/lib/python3/dist-packages/webengine/gtk3/_version.py b/usr/lib/python3/dist-packages/webengine/gtk3/_version.py index 6bb16ca..23b88b2 100644 --- a/usr/lib/python3/dist-packages/webengine/gtk3/_version.py +++ b/usr/lib/python3/dist-packages/webengine/gtk3/_version.py @@ -1,4 +1,4 @@ #!/usr/bin/env python3 -build = (0, 6, 0) +build = (0, 6, 1) version = '.'.join(map(str, build)) \ 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 74835f1..832b965 100644 --- a/usr/lib/python3/dist-packages/webengine/gtk3/_webengine.py +++ b/usr/lib/python3/dist-packages/webengine/gtk3/_webengine.py @@ -31,24 +31,13 @@ try: except: Keybinder = None +from ._env import env from ._version import version from ._settings import create_setting from ._protocal import create_protocal from ._notify import create_notify from ._inject import Inject -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(): - pass +from ._utils import noop, get_monitor_info, pixbuf_to_dict, dict_to_pixbuf @@ -370,6 +359,9 @@ class WebEngine(WebKit2.WebView): case 'isdir': output = os.path.isdir(filepath) + case 'mkdir': + output = os.makedirs(filepath) + return (_error, output) diff --git a/usr/lib/python3/dist-packages/webengine/gtk3/inject.js b/usr/lib/python3/dist-packages/webengine/gtk3/inject.js index d243f66..df37359 100644 --- a/usr/lib/python3/dist-packages/webengine/gtk3/inject.js +++ b/usr/lib/python3/dist-packages/webengine/gtk3/inject.js @@ -103,6 +103,15 @@ function _postMessage(data = {}, uuid = null) { window.dispatchEvent(ev) } +function readonly(obj, key, value) { + Object.defineProperty(obj, key, { + get() { + return value + }, + enumerable: false + }) +} + class NativeImage { #origin @@ -203,6 +212,9 @@ class EventEmitter { } } +readonly(navigator, 'language', '{{lang}}') +readonly(navigator, 'languages', ['{{lang}}']) + window.native = new EventEmitter() native.$on('opener_message', (data, uuid) => _postMessage(data, uuid)) @@ -217,6 +229,9 @@ Object.assign(native, { }, relaunch() { return handler('app', { action: 'relaunch' }, NO_CALLBACK) + }, + getLocale() { + return native.env.LANG } }, fs: { @@ -265,6 +280,9 @@ Object.assign(native, { }, copy(filepath, target) { return handler('fs', { action: 'copy', filepath, target }) + }, + mkdir(filepath) { + return handler('fs', { action: 'mkdir', filepath }) } }, image(filepath) {