aboutsummaryrefslogtreecommitdiffstats
path: root/desktop/modules/user/User.js
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-10-16 09:57:22 +0200
committerDanilo M. <danix@danix.xyz>2026-10-16 09:57:22 +0200
commit5fabbeb09aea782b7df05e8827b552e5ec44cf83 (patch)
tree693f3c61dc60a8f4ca3e6b18e55117de4d85cf07 /desktop/modules/user/User.js
parentd5eaa4855a90057c268bf4d717f366ccf3197dba (diff)
downloadquickshell-5fabbeb09aea782b7df05e8827b552e5ec44cf83.tar.gz
quickshell-5fabbeb09aea782b7df05e8827b552e5ec44cf83.zip
feat(user): helpers for the user page
Parsing userctl's output and locale -a, and the git name preview, kept out of QML so node can test them. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Diffstat (limited to 'desktop/modules/user/User.js')
-rw-r--r--desktop/modules/user/User.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/desktop/modules/user/User.js b/desktop/modules/user/User.js
new file mode 100644
index 0000000..8160b7f
--- /dev/null
+++ b/desktop/modules/user/User.js
@@ -0,0 +1,46 @@
+// Copyright (C) 2026 Danilo M. <danix@danix.xyz>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2 as
+// published by the Free Software Foundation.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+.pragma library
+
+// Pure helpers for the user page, tested by test_user.js under node.
+
+// `userctl get` output into an object.
+function parse(text) {
+ const out = {};
+ for (const line of text.split("\n")) {
+ const i = line.indexOf("=");
+ if (i > 0) out[line.slice(0, i)] = line.slice(i + 1);
+ }
+ return out;
+}
+
+// `userctl keys` output into [{fpr, uid}].
+function keys(text) {
+ return text.split("\n").filter(l => l.includes("\t"))
+ .map(l => ({ fpr: l.slice(0, l.indexOf("\t")), uid: l.slice(l.indexOf("\t") + 1) }));
+}
+
+// `locale -a` prints it_IT.utf8; AccountsService stores it_IT.UTF-8.
+function locales(text) {
+ return text.split("\n")
+ .filter(l => /\.utf-?8$/i.test(l) && !/^C\./.test(l))
+ .map(l => l.replace(/\.utf-?8$/i, ".UTF-8"))
+ .sort();
+}
+
+// The name git gets, for the page's preview. ponytail: duplicates userctl's
+// gitname; both tests pin the same cases, keep them in step.
+function gitName(name) {
+ const w = name.trim().split(/\s+/).filter(s => s !== "");
+ if (w.length < 2) return w.join(" ");
+ return w.slice(0, -1).join(" ") + " " + Array.from(w[w.length - 1])[0] + ".";
+}