diff --git a/BarWidget.qml b/BarWidget.qml index 579904f..f5969d9 100644 --- a/BarWidget.qml +++ b/BarWidget.qml @@ -6,7 +6,7 @@ import qs.Commons import qs.Ui // Varlatch session disclosure. Everything shown here -// comes from `varlatch status --json`, which reads local files only — the +// comes from `varlatch status --json`, which reads local files only: the // widget never makes ambient authenticated calls with a stored credential. // The one ambient network read is the opt-in release check (checkUpdates), // which is anonymous and cached by the helper. @@ -183,7 +183,7 @@ BarWidget { // ("Renew now" / "Log in") can start the login. Quickshell.execDetached([root.menuHelper, "notify-session", s.server, s.state, s.state === "expired" - ? "Credential for " + shortHost(s.server) + " has expired — log in again." + ? "Credential for " + shortHost(s.server) + " has expired; log in again." : "Credential for " + shortHost(s.server) + " expires soon (" + remainingText(s.expiresAt, now) + ")."]) } } @@ -357,8 +357,14 @@ BarWidget { function toggle(): void { root.togglePanel() } // Open the panel on its server address form. function connect(): void { if (panelLoader.item) panelLoader.item.startConnect() } + // Open the panel with a server's other actions showing (for checks). + function showActions(server: string): void { + if (!panelLoader.item) return + panelLoader.item.open() + panelLoader.item.expandedServer = server + } function debugState(): string { - return JSON.stringify({ sessionState: root.sessionState, servers: root.servers, pendingLogin: root.pendingLogin, cliVersion: root.cliVersion, cliInstall: root.cliInstall, latestVersion: root.latestVersion, updateAvailable: root.updateAvailable, errorDetail: root.errorDetail, opened: root.opened, hasPanel: !!panelLoader.item, connecting: panelLoader.item ? panelLoader.item.connecting : false, connectFocused: panelLoader.item ? panelLoader.item.connectFocused : false }) + return JSON.stringify({ sessionState: root.sessionState, servers: root.servers, pendingLogin: root.pendingLogin, cliVersion: root.cliVersion, cliInstall: root.cliInstall, latestVersion: root.latestVersion, updateAvailable: root.updateAvailable, errorDetail: root.errorDetail, opened: root.opened, hasPanel: !!panelLoader.item, connecting: panelLoader.item ? panelLoader.item.connecting : false, connectFocused: panelLoader.item ? panelLoader.item.connectFocused : false, expandedServer: panelLoader.item ? panelLoader.item.expandedServer : "" }) } } diff --git a/Panel.qml b/Panel.qml index 72e0a07..07ae6c4 100644 --- a/Panel.qml +++ b/Panel.qml @@ -42,6 +42,7 @@ Panel { } else { connecting = false connectError = "" + expandedServer = "" } } @@ -82,6 +83,8 @@ Panel { // another server. Submitting starts the usual browser sign-in. property bool connecting: false property string connectError: "" + // The server whose row shows its other actions ("⋯"), if any. + property string expandedServer: "" readonly property bool connectShown: cliUsable && pendingLogin === null && (connecting || (servers.length === 0 && knownServer === "")) // Something to go back to, so the form gets a cancel. @@ -224,10 +227,11 @@ Panel { visible: root.servers.length > 0 onClicked: { if (root.hostWidget && !root.hostWidget.verifying) root.hostWidget.verify() } } + // With several servers, each row opens its own dashboard. Chip { label: "dashboard" - visible: root.servers.length > 0 - onClicked: { root.act(["web"]); root.close() } + visible: root.servers.length === 1 + onClicked: { root.act(["web", root.servers[0].server]); root.close() } } } } @@ -363,78 +367,135 @@ Panel { } } - // ---- Sessions + // ---- Sessions. The host name opens that server's dashboard; "⋯" + // shows the row's other actions: dashboard, copy address, signing + // in again from another device, and log out. Repeater { model: root.servers - delegate: Item { + delegate: Column { id: sessionRow required property var modelData width: mainColumn.width - height: Style.space(44) + spacing: Style.space(4) readonly property bool bad: modelData.expired === true || modelData.state === "warning" + readonly property bool expanded: root.expandedServer === modelData.server - Rectangle { - width: Style.space(8) - height: width - radius: width / 2 - anchors.left: parent.left - anchors.verticalCenter: parent.verticalCenter - color: modelData.expired === true ? root.urgent - : modelData.state === "warning" ? Qt.alpha(root.urgent, 0.75) - : "#7bc96f" - } - - Column { - anchors.left: parent.left - anchors.leftMargin: Style.space(18) - anchors.verticalCenter: parent.verticalCenter - spacing: Style.space(2) + Item { + width: parent.width + height: Style.space(44) + + Rectangle { + width: Style.space(8) + height: width + radius: width / 2 + anchors.left: parent.left + anchors.verticalCenter: parent.verticalCenter + color: sessionRow.modelData.expired === true ? root.urgent + : sessionRow.modelData.state === "warning" ? Qt.alpha(root.urgent, 0.75) + : "#7bc96f" + } - Text { - text: root.shortHost(modelData.server) - color: root.fg - font.family: root.fontFamily - font.pixelSize: Style.font.body + Column { + anchors.left: parent.left + anchors.leftMargin: Style.space(18) + anchors.right: rowChips.left + anchors.rightMargin: Style.space(8) + anchors.verticalCenter: parent.verticalCenter + spacing: Style.space(2) + + Text { + width: parent.width + elide: Text.ElideRight + text: root.shortHost(sessionRow.modelData.server) + color: root.fg + font.family: root.fontFamily + font.pixelSize: Style.font.body + font.underline: hostMouse.containsMouse + MouseArea { + id: hostMouse + anchors.fill: parent + hoverEnabled: true + cursorShape: Qt.PointingHandCursor + onClicked: { root.act(["web", sessionRow.modelData.server]); root.close() } + } + } + Text { + width: parent.width + elide: Text.ElideRight + text: { + var m = sessionRow.modelData + var base = m.expired === true + ? "Session expired, log in again" + : "Logged in, " + root.remaining(m) + var p = m.probe + if (p) base += p.state === "valid" ? " · ✓ verified" + : p.state === "invalid" ? " · ✕ " + (p.detail || "invalid") + : " · server unreachable" + return base + } + color: sessionRow.bad || (sessionRow.modelData.probe && sessionRow.modelData.probe.state !== "valid") + ? root.urgent : root.dim + font.family: root.fontFamily + font.pixelSize: Style.font.caption + } } - Text { - text: { - var base = modelData.expired === true - ? "Session expired — log in again" - : "Logged in — " + root.remaining(modelData) - var p = modelData.probe - if (p) base += p.state === "valid" ? " · ✓ verified" - : p.state === "invalid" ? " · ✕ " + (p.detail || "invalid") - : " · server unreachable" - return base + + Row { + id: rowChips + anchors.right: parent.right + anchors.verticalCenter: parent.verticalCenter + spacing: Style.space(6) + // Renew = log in again to the same server; the CLI revokes the + // old credential only once the new one is saved, so a cancelled + // sign-in loses nothing. + Chip { + label: sessionRow.modelData.expired === true ? "log in" : "renew" + visible: root.pendingLogin === null + onClicked: root.act(["login", sessionRow.modelData.server]) + } + Chip { + label: "⋯" + onClicked: root.expandedServer = sessionRow.expanded ? "" : sessionRow.modelData.server } - color: sessionRow.bad || (modelData.probe && modelData.probe.state !== "valid") - ? root.urgent : root.dim - font.family: root.fontFamily - font.pixelSize: Style.font.caption } } - Row { - anchors.right: parent.right - anchors.verticalCenter: parent.verticalCenter + // Right-aligned and wrapping, so children are listed right to + // left: log out ends up last on the line. + Flow { + visible: sessionRow.expanded + width: parent.width + layoutDirection: Qt.RightToLeft spacing: Style.space(6) - // Renew = log in again to the same server; the CLI revokes the - // old credential only once the new one is saved, so a cancelled - // sign-in loses nothing. + Chip { - label: "renew" - visible: modelData.expired !== true && root.pendingLogin === null - onClicked: root.act(["login", modelData.server]) + label: "log out" + danger: true + onClicked: { root.act(["logout", sessionRow.modelData.server]); root.close() } } + // Renew (or log in again) from a phone or another computer. Chip { - label: modelData.expired === true ? "log in" : "log out" - danger: modelData.expired !== true - visible: modelData.expired !== true || root.pendingLogin === null + label: "other device" + visible: root.pendingLogin === null && !!root.hostWidget && root.hostWidget.deviceSignIn + onClicked: root.act(["login-device", sessionRow.modelData.server]) + } + Chip { + id: copyChip + property bool copied: false + label: copied ? "copied" : "copy address" onClicked: { - if (modelData.expired === true) root.act(["login", modelData.server]) - else { root.act(["logout", modelData.server]); root.close() } + Quickshell.execDetached(["wl-copy", sessionRow.modelData.server]) + copied = true + copiedTimer.restart() } + Timer { id: copiedTimer; interval: 1500; onTriggered: copyChip.copied = false } + } + // With one server, the header's dashboard is this one. + Chip { + label: "dashboard" + visible: root.servers.length > 1 + onClicked: { root.act(["web", sessionRow.modelData.server]); root.close() } } } } @@ -498,6 +559,12 @@ Panel { visible: root.sessionState === "none" && root.knownServer !== "" && !root.connecting onClicked: root.act(["login", root.knownServer]) } + Chip { + label: "other device" + visible: root.sessionState === "none" && root.knownServer !== "" && !root.connecting + && !!root.hostWidget && root.hostWidget.deviceSignIn + onClicked: root.act(["login-device", root.knownServer]) + } Chip { label: "other server" visible: root.sessionState === "none" && root.knownServer !== "" && !root.connecting diff --git a/bin/varlatch-menu b/bin/varlatch-menu index 6c4a0eb..8b47859 100755 --- a/bin/varlatch-menu +++ b/bin/varlatch-menu @@ -430,7 +430,8 @@ case "${1:-}" in ;; web) - server=$(first_server) + # A given server's dashboard, else the first stored one. + server="${2:-$(first_server)}" [ -n "$server" ] || { notify "No stored server."; exit 1; } xdg-open "$server" >/dev/null 2>&1 & ;; @@ -737,7 +738,7 @@ elif not servers: root_desc = "Not logged in" elif len(servers) == 1: s = servers[0] - root_desc = f"{host(s['server'])} — {left(s, now)}" + root_desc = f"{host(s['server'])}, {left(s, now)}" else: root_desc = f"{len(live)}/{len(servers)} sessions live" @@ -746,8 +747,8 @@ for i, s in enumerate(servers): entries.append((f"varlatch.session{i}", { "icon": "", "label": host(s["server"]), - "description": "Logged in — " + left(s, now) if s.get("expired") is not True - else "Session EXPIRED — log in again", + "description": "Logged in, " + left(s, now) if s.get("expired") is not True + else "Session expired, log in again", "action": f"{bin_path} status-notify", })) if cli_missing: @@ -777,7 +778,7 @@ elif not servers or expired: for i, s in enumerate(live): entries.append((f"varlatch.renew{i}", {"icon": "\uf021", "label": "Renew session" if len(live) == 1 else f"Renew {host(s['server'])}", - "description": f"{host(s['server'])} — {left(s, now)} · browser passkey sign-in", + "description": f"{host(s['server'])}, {left(s, now)} · browser passkey sign-in", "action": f"{bin_path} login {s['server']}"})) if servers: if len(servers) == 1: @@ -794,8 +795,14 @@ if servers: entries.append(("varlatch.verify", {"icon": "", "label": "Verify credentials", "description": "Probe each stored credential against its server", "action": f"{bin_path} verify"})) - entries.append(("varlatch.web", {"icon": "", "label": "Open dashboard", - "action": f"{bin_path} web"})) + # One dashboard row per server: the dashboard is the server itself. + if len(servers) == 1: + entries.append(("varlatch.web", {"icon": "", "label": "Open dashboard", + "action": f"{bin_path} web {servers[0]['server']}"})) + else: + for i, s in enumerate(servers): + entries.append((f"varlatch.web{i}", {"icon": "", "label": f"Open {host(s['server'])}", + "description": "Dashboard", "action": f"{bin_path} web {s['server']}"})) if ver.get("updateAvailable") and ver.get("install") == "release": entries.append(("varlatch.update", {"icon": "", "label": "Update CLI", "description": f"{ver.get('current')} → {ver.get('latest')}", @@ -845,7 +852,7 @@ PY ;; *) - echo "Usage: varlatch-menu |login [server]|login-device [server]|login-cancel|login-check|logout [server]|web|refresh|sync-menu|version-info [--force|--max-age ]|notify-update |upgrade-cli [version]|install-cli>" >&2 + echo "Usage: varlatch-menu |login [server]|login-device [server]|login-cancel|login-check|logout [server]|web [server]|refresh|sync-menu|version-info [--force|--max-age ]|notify-update |upgrade-cli [version]|install-cli>" >&2 exit 1 ;; esac diff --git a/tests/run.sh b/tests/run.sh index 3123286..1921c67 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -178,6 +178,7 @@ session https://vl.example.com false "$H" sync-menu check "live session: session, renew, log out, verify, dashboard" \ "menu_has 'has(\"varlatch.session0\") and has(\"varlatch.renew0\") and has(\"varlatch.logout\") and has(\"varlatch.verify\") and has(\"varlatch.web\") and (has(\"varlatch.connect\") | not)'" +check "one server: Open dashboard opens it" "menu_has '.[\"varlatch.web\"].action | endswith(\"web https://vl.example.com\")'" check "every row has a glyph" "menu_has '[to_entries[] | select(.key | startswith(\"varlatch\")) | .value.icon] | all(. != \"\")'" # shellcheck disable=SC2034 # read by check before=$(cat "$MENU"); "$H" sync-menu @@ -190,6 +191,16 @@ session https://vl.example.com true "$H" sync-menu check "managed block rewritten in place, user entries kept" \ "menu_has 'has(\"mine\") and has(\"varlatch.login\")' && [ \$(grep -c '>>> varlatch plugin' \"\$MENU\") -eq 1 ]" +jq '.servers += [.servers[0] | .server = "https://two.example.com"]' "$T/status.json" > "$T/status2.json" +mv "$T/status2.json" "$T/status.json"; "$H" sync-menu +check "several servers: one dashboard row each" \ + "menu_has '(.[\"varlatch.web0\"].action | endswith(\"web https://vl.example.com\")) and (.[\"varlatch.web1\"].action | endswith(\"web https://two.example.com\")) and (has(\"varlatch.web\") | not)'" +check "several servers: every row has a glyph" "menu_has '[to_entries[] | select(.key | startswith(\"varlatch\")) | .value.icon] | all(. != \"\")'" +: > "$T/calls.log"; "$H" web https://two.example.com; sleep 0.2 +check "web opens the given server" "calls | grep -q 'xdg-open https://two.example.com'" +: > "$T/calls.log"; "$H" web; sleep 0.2 +check "web with no server opens the first one" "calls | grep -q 'xdg-open https://vl.example.com'" +session https://vl.example.com true echo '{"current": "0.15.0"}' > "$U"; "$H" sync-menu check "device sign-in row from CLI 0.14.0" "menu_has '.[\"varlatch.device\"].action | endswith(\"login-device https://vl.example.com\")'" echo '{"current": "0.13.0"}' > "$U"; "$H" sync-menu