diff --git a/migrations/1779286136.sh b/migrations/1779286136.sh new file mode 100644 index 00000000..ffcf0cee --- /dev/null +++ b/migrations/1779286136.sh @@ -0,0 +1,90 @@ +echo "Replace the old Stay Awake bar widget with the Stay Awake indicator" + +config_file="$HOME/.config/omarchy/shell.json" + +if [[ -f $config_file ]] && omarchy-cmd-present jq; then + tmp=$(mktemp) + jq ' + def entry_id: + if type == "string" then + . + elif type == "object" then + (.id // "") + else + "" + end; + + def indicator_id: + if type == "string" then + . + elif type == "object" then + (.id // "") + else + "" + end; + + def has_indicator($id): + any(.[]?; indicator_id == $id); + + def stay_awake_entry: + if any(.[]?; type == "object") then + { id: "stayAwake" } + else + "stayAwake" + end; + + def add_stay_awake: + if type != "array" or has_indicator("stayAwake") then + . + else + . + [stay_awake_entry] + end; + + def update_indicators: + if type == "object" and .id == "indicators" then + if (.items | type) == "array" then + .items |= add_stay_awake + elif (.indicators | type) == "array" then + .indicators |= add_stay_awake + else + .items = ["stayAwake"] + end + elif type == "string" and . == "indicators" then + { id: "indicators", items: ["stayAwake"] } + else + . + end; + + def replace_idle_when_no_indicators: + reduce .[] as $entry ( + { rows: [], inserted: false }; + if ($entry | entry_id) == "idleInhibitor" then + if .inserted then + . + else + .rows += [{ id: "indicators", items: ["stayAwake"] }] | .inserted = true + end + else + .rows += [$entry] + end + ) | .rows; + + def replace_idle_inhibitor($has_indicators): + if type != "array" then + . + elif $has_indicators then + [ .[] | select(entry_id != "idleInhibitor") | update_indicators ] + else + replace_idle_when_no_indicators + end; + + (.bar.layout | [ .[]?[]? | select(entry_id == "indicators") ] | length > 0) as $has_indicators | + .bar.layout |= ( + if type == "object" then + with_entries(.value |= replace_idle_inhibitor($has_indicators)) + else + . + end + ) + ' "$config_file" >"$tmp" && mv "$tmp" "$config_file" || rm -f "$tmp" +fi diff --git a/shell/plugins/bar/Bar.qml b/shell/plugins/bar/Bar.qml index a0f5a150..b89246b4 100644 --- a/shell/plugins/bar/Bar.qml +++ b/shell/plugins/bar/Bar.qml @@ -315,7 +315,6 @@ Item { "notificationCenter": { displayName: "Notification center", description: "Recent notifications + DND", category: "Status", allowMultiple: false }, "systemStats": { displayName: "System stats", description: "CPU icon — hover for graphs, click to open btop", category: "System", allowMultiple: false }, "weather": { displayName: "Weather", description: "Weather pill with detail popup", category: "Info", allowMultiple: false, settingsForm: "weatherSettings" }, - "idleInhibitor": { displayName: "Stay awake", description: "Toggle whether the system can idle", category: "System", allowMultiple: false }, "microphone": { displayName: "Microphone", description: "Mic input state and mute toggle", category: "Audio", allowMultiple: false }, "activeWindow": { displayName: "Active window", description: "Title of the focused window", category: "Compositor", allowMultiple: false }, "keyboardLayout": { displayName: "Keyboard layout", description: "Current xkb layout, click cycles", category: "Compositor", allowMultiple: false }, diff --git a/shell/plugins/bar/README.md b/shell/plugins/bar/README.md index 1199dd16..2366249c 100644 --- a/shell/plugins/bar/README.md +++ b/shell/plugins/bar/README.md @@ -59,7 +59,6 @@ Example `shell.json` (bar subtree only shown): | `notificationCenter` | Bell with badge + popup with recent notifications, DND toggle | left = popup · right = toggle DND | | `systemStats` | Inline CPU + memory sparklines, popup with detail | left = popup · right = terminal | | `weather` | Weather icon + popup with forecast | left = popup · right = full notification | -| `idleInhibitor` | Coffee-cup that toggles `omarchy-toggle-idle` | left = toggle | | `microphone` | Mic icon + scroll volume | left = mute toggle · middle = audio panel · scroll = source volume | ### First-party panels (in `../panels/`) diff --git a/shell/plugins/bar/widgets/idleInhibitor.qml b/shell/plugins/bar/widgets/idleInhibitor.qml deleted file mode 100644 index 53e095e8..00000000 --- a/shell/plugins/bar/widgets/idleInhibitor.qml +++ /dev/null @@ -1,62 +0,0 @@ -import QtQuick -import Quickshell -import Quickshell.Io -import qs.Ui - -BarIndicator { - id: root - moduleName: "idleInhibitor" - - function refresh() { - if (!statusProc.running) statusProc.running = true - } - - function toggle() { - if (root.bar) root.bar.run("omarchy-toggle-idle") - refreshTimer.restart() - } - - Component.onCompleted: refresh() - - Connections { - target: root.bar - ignoreUnknownSignals: true - function onIndicatorsRefreshRequested() { root.refresh() } - } - - Process { - id: statusProc - command: ["bash", "-lc", "omarchy-shell idle status 2>/dev/null"] - stdout: StdioCollector { - waitForEnd: true - onStreamFinished: { - var raw = String(text || "").trim() - try { - var parsed = JSON.parse(raw) - root.active = parsed && parsed.enabled === false - } catch (e) { - root.active = false - } - } - } - } - - Timer { - id: refreshTimer - interval: 1500 - onTriggered: root.refresh() - } - - Timer { - interval: 5000 - running: true - repeat: true - onTriggered: root.refresh() - } - - activeText: "󰅶" - inactiveText: "󰅶" - activeTooltipText: "No lock or screensaver" - inactiveTooltipText: "Idle enabled" - onPressed: function() { root.toggle() } -}