quickshell-dots icon indicating copy to clipboard operation
quickshell-dots copied to clipboard

feat: persist Control panel state across restarts

Open k8rito01 opened this issue 5 months ago • 1 comments

Currently the bar resets all Control panel settings on every restart (splits, animation mode, bar color). This adds automatic persistence to ~/.cache/quickshell_splits so the state survives restarts with no extra dependencies.

What's saved

  • All 4 splits (Status / Left / Right / Network)
  • Bar animation mode (Stream / Surge / Bolt)
  • Bar color source (Red / Accent)

How it works

  • On startup: reads the cache file and restores state before marking _splitsLoaded = true (prevents saving during load)
  • On any toggle: an onXChanged handler writes the new state immediately via a one-shot bash echo
  • File format: splitArch splitMon splitMprisL splitNet barAnim useThemeAccent (space-separated, e.g. 1 0 1 0 2 0)
  • If the file doesn't exist (first run), defaults apply as usual

Changes

Theme.qml only — adds ~35 lines (2 Process blocks + change handlers + save function).

// ── Split persistence ──
readonly property string splitsCachePath: Quickshell.env("HOME") + "/.cache/quickshell_splits"
property bool _splitsLoaded: false

onSplitArchChanged:      if (_splitsLoaded) saveSplits()
onSplitMonChanged:       if (_splitsLoaded) saveSplits()
onSplitNetChanged:       if (_splitsLoaded) saveSplits()
onSplitMprisLChanged:    if (_splitsLoaded) saveSplits()
onBarAnimChanged:        if (_splitsLoaded) saveSplits()
onUseThemeAccentChanged: if (_splitsLoaded) saveSplits()

function saveSplits() {
    splitSaveProc.running = false
    splitSaveProc.running = true
}

Process {
    id: splitLoadProc
    command: ["cat", theme.splitsCachePath]
    running: true
    stdout: StdioCollector {
        onStreamFinished: {
            var parts = this.text.trim().split(" ")
            if (parts.length >= 5) {
                theme.splitArch      = parts[0] === "1"
                theme.splitMon       = parts[1] === "1"
                theme.splitMprisL    = parts[2] === "1"
                theme.splitNet       = parts[3] === "1"
                theme.barAnim        = parseInt(parts[4]) || 0
                theme.useThemeAccent = parts.length >= 6 && parts[5] === "1"
            }
            theme._splitsLoaded = true
        }
    }
}

Process {
    id: splitSaveProc
    command: ["bash", "-c",
        "echo '" +
        (theme.splitArch      ? "1" : "0") + " " +
        (theme.splitMon       ? "1" : "0") + " " +
        (theme.splitMprisL    ? "1" : "0") + " " +
        (theme.splitNet       ? "1" : "0") + " " +
        theme.barAnim + " " +
        (theme.useThemeAccent ? "1" : "0") +
        "' > '" + theme.splitsCachePath + "'"]
}

k8rito01 avatar Jun 07 '26 22:06 k8rito01

Implemented — thanks for the well-scoped proposal. Shipped in 3940011 (+ hardening in 213bc54).

Notes on the implementation:

  • Kept it on the Process+cat/echo approach (dependency-free, matches the rest of the codebase) rather than FileView.
  • One change vs. the proposal was necessary: the save command must be built imperatively inside saveSplits(), not as a bound command: property. With a binding, the Process could run before the binding re-evaluated and persist the pre-toggle state (e.g. setting a split saved 0 0 0 0 0 0). Building the string at call time reads the already-committed values.
  • Hardening: mkdir -p the cache dir (so a missing ~/.cache does not silently drop persistence) and clamp barAnim to 0–3 on load. Verified the file is overwrite-only (never grows, ~12 B), and that empty/corrupt/partial content falls back to defaults without crashing.

Closing as done.

HANCORE-linux avatar Jun 08 '26 04:06 HANCORE-linux