add screen translation

This commit is contained in:
end-4
2026-04-03 19:31:24 +02:00
parent ec3b92a938
commit 64b52f6a90
19 changed files with 1159 additions and 20 deletions
@@ -0,0 +1,93 @@
pragma Singleton
pragma ComponentBehavior: Bound
import QtQuick
import Quickshell
import qs.modules.common.utils
Singleton {
id: root
property var keyContent: ({})
property string keyProjectId: keyContent.project_id
property bool keyError: false
property bool keyReady: false
property string token: ""
property bool tokenError: false
property bool tokenReady: false
readonly property string projectId: keyProjectId
readonly property bool loaded: keyReady && tokenReady
readonly property string tokenForKeyScriptPath: Quickshell.shellPath("services/gCloud/token-from-key-venv.sh")
function load() {
// Dummy for init
}
function setKeyJson(str: string): bool {
try {
var keyData = JSON.parse(str)
KeyringStorage.setNestedField(["googleCloud", "serviceAccountKey"], keyData);
return true;
} catch(e) {
return false;
}
}
function getToken() {
if (root.keyError) {
root.tokenError = true;
root.tokenReady = true;
return;
}
tokenProc.runSequence([(() => { // prep token fetcher
tokenProc.environment.SERVICE_KEY_CONTENT = JSON.stringify(root.keyContent);
tokenProc.command = [ //
"bash", "-c" //
, `${tokenForKeyScriptPath} "$SERVICE_KEY_CONTENT"`];
}), [] // run token fetcher
, (out => {
if (out.startsWith("Error")) {
root.tokenError = true;
} else {
root.tokenError = false;
root.token = out.trim();
}
root.tokenReady = true;
})]);
}
function loadKeyIfPossible() {
if (KeyringStorage.loaded) {
root.keyContent = KeyringStorage.keyringData?.googleCloud?.serviceAccountKey;
if (!root.keyContent?.project_id) {
root.keyError = true;
} else {
root.keyError = false;
root.keyProjectId = root.keyContent.project_id;
}
root.keyReady = true;
root.getToken();
} else {
KeyringStorage.fetchKeyringData();
}
}
Component.onCompleted: {
loadKeyIfPossible();
}
Connections {
target: KeyringStorage
function onLoadedChanged() {
root.loadKeyIfPossible();
}
function onDataChanged() {
root.loadKeyIfPossible();
}
}
MultiTurnProcess {
id: tokenProc
}
}
@@ -15,6 +15,8 @@ import QtQuick;
Singleton {
id: root
signal dataChanged()
property bool loaded: false
property var keyringData: ({})
@@ -82,6 +84,7 @@ Singleton {
if (saveData.running) {
// console.log("[KeyringStorage] Saving with command: '" + saveData.command.join("' '") + "'");
saveData.write(JSON.stringify(root.keyringData));
root.dataChanged()
stdinEnabled = false // End input stream
}
}
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source $(eval echo $ILLOGICAL_IMPULSE_VIRTUAL_ENV)/bin/activate
"$SCRIPT_DIR/token_from_key.py" "$@"
deactivate
@@ -0,0 +1,30 @@
#!/usr/bin/env python3
import sys
import json
import google.auth.transport.requests
import google.oauth2.service_account
def get_token(json_str):
try:
# Load the string into a dictionary
info = json.loads(json_str)
# Initialize credentials
creds = google.oauth2.service_account.Credentials.from_service_account_info(info)
scoped_creds = creds.with_scopes(['https://www.googleapis.com/auth/cloud-platform'])
# Refresh to get the access token
request = google.auth.transport.requests.Request()
scoped_creds.refresh(request)
print(scoped_creds.token)
except Exception as e:
sys.stderr.write(f"Error: {str(e)}\n")
sys.exit(1)
if __name__ == "__main__":
if len(sys.argv) < 2:
sys.stderr.write("Usage: python3 get_token.py '<json_string>'\n")
sys.exit(1)
get_token(sys.argv[1])