Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
17 changes: 14 additions & 3 deletions Panel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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: "⋯"
Expand Down Expand Up @@ -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"
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
76 changes: 61 additions & 15 deletions bin/varlatch-menu
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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; }
Expand Down Expand Up @@ -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=""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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"))
Expand All @@ -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:
Expand Down Expand Up @@ -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
;;
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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`.",
Expand Down
14 changes: 14 additions & 0 deletions tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down
Loading