From 3d9c4cb7db5d46a7f08fe2f99165c13724486552 Mon Sep 17 00:00:00 2001 From: Jeremy Deceuster Date: Mon, 9 Nov 2026 10:32:10 +0100 Subject: [PATCH 1/3] fix: browser sign-in closes the panel The panel is a full-screen overlay layer that holds keyboard focus. Left open during a browser sign-in, it covered the browser for the whole passkey prompt, which is when the bar and the Omarchy menu stopped responding until the shell was restarted. log in, renew and connect now close it; reopening the panel shows the sign-in under way. Device sign-in keeps the panel open, since it shows the code and QR code. Co-Authored-By: Claude Opus 5.5 --- Panel.qml | 17 ++++++++++++++--- README.md | 7 ++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Panel.qml b/Panel.qml index 8a87371..bc784a1 100644 --- a/Panel.qml +++ b/Panel.qml @@ -75,6 +75,17 @@ Panel { Quickshell.execDetached([root.menuHelper].concat(args)) } + // Browser sign-in closes the panel. The panel is a full-screen overlay + // that holds keyboard focus, and left open it sits over the browser + // window for the whole passkey sign-in, which is when the bar and the + // Omarchy menu have been seen to stop responding. Reopening the panel shows the sign-in + // under way. Device sign-in keeps the panel open: it shows the code and + // the QR code, and no browser opens here. + function startBrowserLogin(server) { + act(["login", server]) + root.close() + } + readonly property var expiredServers: servers.filter(function (s) { return s.expired === true }) readonly property bool loginUseful: servers.length === 0 || expiredServers.length > 0 @@ -125,8 +136,8 @@ Panel { connectError = "Give the server's address, such as varlatch.example.com" return } - act(["login", url]) stopConnect() + startBrowserLogin(url) } component Chip: Rectangle { @@ -455,7 +466,7 @@ Panel { Chip { label: sessionRow.modelData.expired === true ? "log in" : "renew" visible: root.pendingLogin === null - onClicked: root.act(["login", sessionRow.modelData.server]) + onClicked: root.startBrowserLogin(sessionRow.modelData.server) } Chip { label: "⋯" @@ -560,7 +571,7 @@ Panel { Chip { label: "log in" visible: root.sessionState === "none" && root.knownServer !== "" && !root.connecting - onClicked: root.act(["login", root.knownServer]) + onClicked: root.startBrowserLogin(root.knownServer) } Chip { label: "other device" diff --git a/README.md b/README.md index 0f9c04e..32bd243 100644 --- a/README.md +++ b/README.md @@ -90,9 +90,10 @@ with arguments, gets the release notes instead, since you update those yourself. Signing in needs no terminal window. The CLI opens your browser for the -passkey prompt, and while it waits the panel shows "Signing in to …" with -**open link**, for when the page opens in the wrong browser, **other -device**, and **cancel**. The result arrives as a notification. +passkey prompt and the panel closes, so it never covers the browser. While +the CLI waits, reopening the panel shows "Signing in to …" with **open +link**, for when the page opens in the wrong browser, **other device**, and +**cancel**. The result arrives as a notification. ## Sign in from another device From 26d542e5df7b4d309250a578c4bf9eb891cf482b Mon Sep 17 00:00:00 2001 From: Jeremy Deceuster Date: Mon, 9 Nov 2026 10:32:10 +0100 Subject: [PATCH 2/3] fix: sync-menu writes atomically, one run at a time, in whole hours The widget runs sync-menu after every status poll. The menu rows showed time left to the minute, so a live session rewrote omarchy-menu.jsonc and reloaded the menu every minute; the write was in place, so the menu could parse a half-written file, and overlapping runs could interleave writes. - Runs hold a lock, so they no longer overlap. - The menu file and state files are written to a temporary file and renamed into place (through a symlink, to its target). - servers.json is only rewritten when the servers change. - The menu counts whole hours; the panel keeps the minutes. Co-Authored-By: Claude Opus 5.5 --- bin/varlatch-menu | 76 +++++++++++++++++++++++++++++++++++++---------- tests/run.sh | 14 +++++++++ 2 files changed, 75 insertions(+), 15 deletions(-) diff --git a/bin/varlatch-menu b/bin/varlatch-menu index 7974df1..a8fcf76 100755 --- a/bin/varlatch-menu +++ b/bin/varlatch-menu @@ -49,7 +49,17 @@ login_running() { [ -n "$pid" ] && { [ -z "$boot" ] || [ "$boot" = "$(boot_id)" ]; } && kill -0 "$pid" 2>/dev/null } -login_idle() { mkdir -p "$STATE_DIR"; echo '{"state":"idle"}' > "$LOGIN_FILE"; } +# Replace a state file with stdin in one rename: the widget reloads these +# files the moment they change and must never read one half-written. +write_state() { + local tmp + tmp=$(mktemp "$1.XXXXXX") || return 1 + # Nothing on stdin means the writer failed: keep the old file. + if cat > "$tmp" && [ -s "$tmp" ] && mv -f "$tmp" "$1"; then return 0; fi + rm -f "$tmp"; return 1 +} + +login_idle() { mkdir -p "$STATE_DIR"; echo '{"state":"idle"}' | write_state "$LOGIN_FILE"; } # "https://varlatch.example.com" from what a person typed: trimmed, # https:// when no scheme is given, no trailing slash. @@ -67,7 +77,7 @@ remember_server() { mkdir -p "$STATE_DIR" local known="[]" [ -f "$STATE_FILE" ] && known=$(jq -c 'if type == "array" then . else [] end' "$STATE_FILE" 2>/dev/null || echo "[]") - jq -cn --arg s "$1" --argjson known "$known" '[$s] + ($known - [$s])' > "$STATE_FILE" + jq -cn --arg s "$1" --argjson known "$known" '[$s] + ($known - [$s])' | write_state "$STATE_FILE" } status_json() { eval "$CMD status --json" 2>/dev/null; } @@ -282,7 +292,7 @@ case "${1:-}" in cli=$! write_login() { jq -n --arg s "$server" --arg u "$1" --argjson p "$cli" --arg b "$(boot_id)" \ - '{state: "pending", server: $s, url: $u, pid: $p, boot: $b}' > "$LOGIN_FILE" + '{state: "pending", server: $s, url: $u, pid: $p, boot: $b}' | write_state "$LOGIN_FILE" } write_login "" url="" @@ -365,7 +375,7 @@ case "${1:-}" in jq -n --arg s "$server" --arg u "$uri" --arg c "$code" --arg e "$expires" \ --arg q "$([ -f "$qr" ] && echo "$qr")" --argjson p "$waiter" --arg b "$(boot_id)" \ '{state: "pending", mode: "device", server: $s, url: $u, code: $c, expiresAt: $e, - qr: $q, pid: $p, boot: $b}' > "$LOGIN_FILE" + qr: $q, pid: $p, boot: $b}' | write_state "$LOGIN_FILE" rc=0; wait "$waiter" || rc=$? state=$(tail -n 1 "$out" | jq -r '.state // empty' 2>/dev/null || true) if [ "$rc" -eq 0 ]; then @@ -710,10 +720,39 @@ case "${1:-}" in # current session state, so the submenu shows what you are logged in to # and offers only the actions that make sense. The menu hot-reloads the # file; we only rewrite (and refresh) when the content actually changed. + # The widget runs this after every status poll, so runs can overlap: one + # at a time, or two would interleave their writes to the menu file. + mkdir -p "$STATE_DIR" + exec 9>"$STATE_DIR/sync-menu.lock" + flock -w 30 9 || exit 0 VARLATCH_RESTART_VERSION="$restart_version" VARLATCH_MENU_CMD="$CMD" VARLATCH_SHOW_LOCALHOST="$(show_localhost && echo on || echo off)" python3 - <<'PY' -import json, os, re, subprocess, sys +import json, os, re, subprocess, sys, tempfile from datetime import datetime, timezone +def write_atomic(path, text): + # The shell watches these files and reads them the moment they change, + # so never let it see one half-written: write a sibling and rename it + # over. Through a symlink (dotfiles), replace the file it points to. + path = os.path.realpath(path) + directory = os.path.dirname(path) + os.makedirs(directory, exist_ok=True) + try: + mode = os.stat(path).st_mode & 0o777 + except FileNotFoundError: + mode = 0o644 + fd, tmp = tempfile.mkstemp(dir=directory, prefix="." + os.path.basename(path) + ".") + try: + with os.fdopen(fd, "w", encoding="utf-8") as f: + f.write(text) + os.chmod(tmp, mode) + os.replace(tmp, path) + except BaseException: + try: + os.unlink(tmp) + except FileNotFoundError: + pass + raise + home = os.path.expanduser("~") menu_path = os.path.join(home, ".config/omarchy/extensions/omarchy-menu.jsonc") bin_path = os.path.join(home, ".config/omarchy/plugins/varlatch/bin/varlatch-menu") @@ -735,11 +774,16 @@ def not_local(u): return not re.match(r"^[a-z]+://(localhost|127\.)", str(u)) if os.environ.get("VARLATCH_SHOW_LOCALHOST") != "on": servers = [s for s in servers if not_local(s["server"])] -# Remember servers across logouts so "Log in" keeps a target. +# Remember servers across logouts so "Log in" keeps a target. The widget +# reloads the file on every change, so leave it alone when nothing changed. if servers: - os.makedirs(os.path.dirname(state_file), exist_ok=True) - with open(state_file, "w", encoding="utf-8") as f: - json.dump([s["server"] for s in servers], f) + known = json.dumps([s["server"] for s in servers]) + try: + previous = open(state_file, encoding="utf-8").read() + except OSError: + previous = None + if previous != known: + write_atomic(state_file, known) remembered = [] try: remembered = json.load(open(state_file, encoding="utf-8")) @@ -760,11 +804,14 @@ def left(s, now): dt = datetime.fromisoformat(exp.replace("Z", "+00:00")) except ValueError: return "no expiry recorded" - ms = (dt - now).total_seconds() - if ms <= 0: + seconds = (dt - now).total_seconds() + if seconds <= 0: return "EXPIRED" - h, m = int(ms // 3600), int(ms % 3600 // 60) - return (f"{h}h {m}m left" if h else f"{m}m left") + # Whole hours only: every change to this text rewrites the menu file and + # reloads the menu, and minutes would do that once a minute. The panel + # keeps the minute countdown. + h = int(seconds // 3600) + return f"{h}h left" if h else "under an hour left" # CLI version and update, from the widget's last version-info. try: @@ -903,8 +950,7 @@ else: sys.exit(f"varlatch-menu: {menu_path} is not a JSONC object; menu entries not added.") if new == raw: sys.exit(0) -os.makedirs(os.path.dirname(menu_path), exist_ok=True) -open(menu_path, "w", encoding="utf-8").write(new) +write_atomic(menu_path, new) subprocess.run(["omarchy", "menu", "refresh"], capture_output=True) PY ;; diff --git a/tests/run.sh b/tests/run.sh index e31731c..b9b90fc 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -207,6 +207,20 @@ echo '{"current": "0.13.0"}' > "$U"; "$H" sync-menu check "no device sign-in row before 0.14.0" "menu_has 'has(\"varlatch.device\") | not'" echo '{"current": "0.14.0", "latest": "0.15.0", "updateAvailable": true, "install": "release"}' > "$U"; "$H" sync-menu check "Update CLI row for a release install" "menu_has '.[\"varlatch.update\"].description == \"0.14.0 → 0.15.0\"'" +jq -n --arg e "$(date -u -d '+90 minutes' +%Y-%m-%dT%H:%M:%SZ)" '{version: 1, repo: null, servers: [{server: "https://vl.example.com", + name: null, issuedAt: "2026-10-07T06:00:00Z", expiresAt: $e, expired: false, expiring: false}]}' > "$T/status.json" +"$H" sync-menu +check "menu counts down in whole hours" "menu_has '.[\"varlatch.session0\"].description == \"Logged in, 1h left\"'" "$(cat "$MENU")" +touch -d '2000-01-01' "$S/servers.json"; "$H" sync-menu +check "same servers leave servers.json alone" "[ \"\$(stat -c %Y '$S/servers.json')\" = \"\$(date -d 2000-01-01 +%s)\" ]" +printf '{\n "mine": {"label": "x"},\n}\n' > "$MENU" +for _ in 1 2 3 4 5 6; do "$H" sync-menu & done; wait +check "overlapping runs leave one valid block" \ + "menu_has 'has(\"mine\") and has(\"varlatch.session0\")' && [ \$(grep -c '>>> varlatch plugin' \"\$MENU\") -eq 1 ]" "$(cat "$MENU")" +check "no temporary menu file is left" "[ -z \"\$(find '$T/.config/omarchy/extensions' -name '.omarchy-menu.jsonc.*')\" ]" +mkdir -p "$T/dotfiles"; mv "$MENU" "$T/dotfiles/omarchy-menu.jsonc"; ln -s "$T/dotfiles/omarchy-menu.jsonc" "$MENU" +session https://vl.example.com true; "$H" sync-menu +check "a symlinked menu file stays a symlink" "[ -L '$MENU' ] && menu_has 'has(\"mine\") and has(\"varlatch.login\")'" # -------------------------------------------------------------------------- section "verify (status --probe)" From ff4af4e4ed086cf01ce5d29c73cb42836628555f Mon Sep 17 00:00:00 2001 From: Jeremy Deceuster Date: Mon, 9 Nov 2026 10:32:10 +0100 Subject: [PATCH 3/3] chore: 0.5.2 Changelog for the sign-in panel and sync-menu fixes; manifest 0.5.2. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 17 +++++++++++++++++ manifest.json | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1285489..96da868 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,22 @@ # Changelog +## 0.5.2 (2026-11-09) + +- **Fix: the bar and the Omarchy menu stopped responding** after a browser + sign-in from the panel, until the shell was restarted (or the laptop + forced off). The panel is a full-screen overlay that holds keyboard focus, + and it stayed open over the browser for the whole sign-in. **log in**, + **renew** and **connect** now close it; reopen it to see the sign-in under + way. Signing in from another device keeps it open for the code. +- **The menu file is rewritten far less often.** The menu showed time left + to the minute, so a live session rewrote `omarchy-menu.jsonc` and reloaded + the menu every minute. It now counts whole hours ("Logged in, 3h left"); + the panel keeps the minutes. +- **No half-written files.** The menu file and the plugin's state files are + written to a temporary file and renamed into place, so the shell never + reads one mid-write, and menu updates run one at a time instead of + interleaving. A symlinked `omarchy-menu.jsonc` stays a symlink. + ## 0.5.1 (2026-10-24) - **Fix: Verify did nothing** when the Varlatch CLI printed a warning, as diff --git a/manifest.json b/manifest.json index 8445733..c6bddbf 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,7 @@ "schemaVersion": 1, "id": "varlatch", "name": "Varlatch", - "version": "0.5.1", + "version": "0.5.2", "author": "Varlatch", "license": "Apache-2.0", "description": "Varlatch sessions in the Omarchy bar: which servers you hold credentials for, when they expire, and quick sign-in and sign-out, all read offline from `varlatch status --json`.",