Moved to module structure to work in embeded qs processes
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
pragma Singleton
|
||||
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
|
||||
QtObject {
|
||||
id: root
|
||||
|
||||
// Defaults. User config overrides any of these.
|
||||
property string fontFamily: "JetBrainsMono Nerd Font Propo"
|
||||
property int fontSize: 16
|
||||
property string giphyApiKey: ""
|
||||
property int panelWidth: 720
|
||||
property int panelHeight: 520
|
||||
property int padding: 5
|
||||
property int spacing: 5
|
||||
property int radius: 10
|
||||
property string backgroundColor: ""
|
||||
property string foregroundColor: ""
|
||||
property string idleColor: ""
|
||||
property string accentColor: ""
|
||||
property string overlayStrongColor: ""
|
||||
property string overlayWeakColor: ""
|
||||
property string borderColor: ""
|
||||
|
||||
property bool loaded: false
|
||||
readonly property string configPath: (Quickshell.env("XDG_CONFIG_HOME") || (Quickshell.env("HOME") + "/.config")) + "/omni-launcher/config.json"
|
||||
|
||||
function _apply(obj) {
|
||||
if (typeof obj.fontFamily === "string" && obj.fontFamily.length > 0) fontFamily = obj.fontFamily;
|
||||
if (typeof obj.fontSize === "number" && obj.fontSize > 0) fontSize = obj.fontSize;
|
||||
if (typeof obj.giphyApiKey === "string") giphyApiKey = obj.giphyApiKey;
|
||||
if (typeof obj.panelWidth === "number" && obj.panelWidth > 0) panelWidth = obj.panelWidth;
|
||||
if (typeof obj.panelHeight === "number" && obj.panelHeight > 0) panelHeight = obj.panelHeight;
|
||||
if (typeof obj.padding === "number" && obj.padding > 0) padding = obj.padding;
|
||||
if (typeof obj.spacing === "number" && obj.spacing > 0) spacing = obj.spacing;
|
||||
if (typeof obj.radius === "number" && obj.radius >= 0) radius = obj.radius;
|
||||
|
||||
const colors = obj.colors || {};
|
||||
if (typeof colors.background === "string" && colors.background.length > 0) backgroundColor = colors.background;
|
||||
if (typeof colors.foreground === "string" && colors.foreground.length > 0) foregroundColor = colors.foreground;
|
||||
if (typeof colors.idle === "string" && colors.idle.length > 0) idleColor = colors.idle;
|
||||
if (typeof colors.accent === "string" && colors.accent.length > 0) accentColor = colors.accent;
|
||||
if (typeof colors.overlayStrong === "string" && colors.overlayStrong.length > 0) overlayStrongColor = colors.overlayStrong;
|
||||
if (typeof colors.overlayWeak === "string" && colors.overlayWeak.length > 0) overlayWeakColor = colors.overlayWeak;
|
||||
if (typeof colors.border === "string" && colors.border.length > 0) borderColor = colors.border;
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
_load();
|
||||
_startWatcher();
|
||||
}
|
||||
|
||||
function _load() {
|
||||
_loader.running = false;
|
||||
_loader.command = ["cat", configPath];
|
||||
_loader.running = true;
|
||||
}
|
||||
|
||||
function _startWatcher() {
|
||||
_watcher.running = false;
|
||||
_watcher.command = [
|
||||
"sh", "-c",
|
||||
"while inotifywait -q -e close_write " + JSON.stringify(configPath) + " 2>/dev/null; do echo CHANGED; done"
|
||||
];
|
||||
_watcher.running = true;
|
||||
}
|
||||
|
||||
property Process _watcher: Process {
|
||||
running: false
|
||||
stdout: SplitParser {
|
||||
splitMarker: "\n"
|
||||
onRead: line => {
|
||||
if (line.indexOf("CHANGED") >= 0) {
|
||||
console.log("omni-launcher: config changed, reloading");
|
||||
root._load();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onExited: root._startWatcher()
|
||||
}
|
||||
|
||||
property Process _loader: Process {
|
||||
running: false
|
||||
stdout: StdioCollector {
|
||||
onStreamFinished: {
|
||||
const text = (this.text || "").trim();
|
||||
if (text.length > 0) {
|
||||
try {
|
||||
root._apply(JSON.parse(text));
|
||||
} catch (e) {
|
||||
console.log("omni-launcher: config.json parse error:", e);
|
||||
}
|
||||
}
|
||||
root.loaded = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user