调整环境变量

master
yutent 2023-09-12 14:12:29 +08:00
parent 2682af069b
commit f9c4007e3f
6 changed files with 43 additions and 14 deletions

View File

@ -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"
}

View File

@ -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)

View File

@ -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,

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python3
build = (0, 6, 0)
build = (0, 6, 1)
version = '.'.join(map(str, build))

View File

@ -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)

View File

@ -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) {