Compare commits

..

No commits in common. "14a8d0a4ca14e71948a78beefd3fee1a42cb4929" and "bc864bb9d82545f5f8a6bb82676fd5a05c478d6d" have entirely different histories.

7 changed files with 104 additions and 139 deletions

View file

@ -2,7 +2,7 @@
A lightweight widget plugin that shows Tailscale connectivity status on the Dank Bar with quick controls for toggling connection, switching exit nodes, and copying peer addresses. A lightweight widget plugin that shows Tailscale connectivity status on the Dank Bar with quick controls for toggling connection, switching exit nodes, and copying peer addresses.
![Tailscale Widget v0.2.0](resources/dms_tailscalectl_v0.1.0.png) ![Tailscale Widget v0.1.0](resources/dms_tailscalectl_v0.1.0.png)
## Features ## Features
@ -14,7 +14,7 @@ A lightweight widget plugin that shows Tailscale connectivity status on the Dank
- Peer list with hostnames and IPs - Peer list with hostnames and IPs
- **Click-to-copy** any hostname or IP to clipboard - **Click-to-copy** any hostname or IP to clipboard
- **Exit node selection** — click `↗` on any exit-node-capable peer to route through it - **Exit node selection** — click `↗` on any exit-node-capable peer to route through it
- **On-demand status** — polls Tailscale for ground truth on load, explicit actions, and post-mutation verification (defensive poll-act-poll for toggles; no always-on timer) - **Auto-refresh** — status polls every 5 seconds
- **Toast notifications** for all errors - **Toast notifications** for all errors
## Requirements ## Requirements
@ -70,7 +70,7 @@ A lightweight widget plugin that shows Tailscale connectivity status on the Dank
"id": "tailscalectl", "id": "tailscalectl",
"name": "Tailscale", "name": "Tailscale",
"description": "Tailscale status and controls on the Dank Bar", "description": "Tailscale status and controls on the Dank Bar",
"version": "0.2.0", "version": "0.1.0",
"author": "John Morris & Vybe (AI Slop... er... Coding Assistant)", "author": "John Morris & Vybe (AI Slop... er... Coding Assistant)",
"icon": "vpn_key", "icon": "vpn_key",
"type": "widget", "type": "widget",
@ -79,13 +79,6 @@ A lightweight widget plugin that shows Tailscale connectivity status on the Dank
} }
``` ```
## Implementation notes
- Uses `Proc` singleton (from `qs.Common`) for all external `tailscale` commands (one-shot stdout capture + auto cleanup).
- Fully I18n-ready via `I18n.tr(...)` (source keys in American English only today; see `tailscalectl/i18n/` for scaffolding).
- Follows current `dms-plugin-dev` + DMS 1.4 plugin best practices (capabilities, requires, no raw Process for one-shots, etc.).
- Toggle uses intentional defensive poll-act-poll (see code comments).
## Testing ## Testing
```bash ```bash

View file

@ -4,6 +4,7 @@ import qs.Common
import qs.Services import qs.Services
import qs.Widgets import qs.Widgets
import qs.Modules.Plugins import qs.Modules.Plugins
import Quickshell.Io
import "./lib.js" as TailscaleLib import "./lib.js" as TailscaleLib
PluginComponent { PluginComponent {
@ -20,101 +21,127 @@ PluginComponent {
popoutWidth: 360 popoutWidth: 360
popoutHeight: 400 popoutHeight: 400
// Transient coordination for the defensive poll-act-poll toggle (exact behavior preserved).
// We poll for on-the-ground truth (so we choose the correct "up"/"down" and don't lie to the user),
// act, then poll again for verification. This is *not* long-term cached state (see AGENTS.md).
// The _pendingAction is short-lived per user action only.
property string _pendingAction: ""
Component.onCompleted: { Component.onCompleted: {
// Initial status fetch on load. Subsequent fetches are on-demand (popout open, explicit refresh, or post-action verification). // Initial status fetch on load. Subsequent fetches are on-demand (popout open, explicit refresh, or post-action verification).
root._runStatusCheck(); statusCheck.running = true
} }
function _runStatusCheck() { Process {
Proc.runCommand("tailscale-status", TailscaleLib.getStatusCommand(), (stdout, code) => { id: toggleProcess
stderr: StdioCollector {}
onExited: (code, status) => {
if (code !== 0) {
var action = root.isConnected ? "disconnect" : "connect";
var detail = toggleProcess.stderr.text.trim();
ToastService.showError("tailscalectl", TailscaleLib.formatError(action, detail));
}
root.refreshStatus();
}
}
Process {
id: copyProcess
stderr: StdioCollector {}
onExited: (code, status) => {
if (code === 0) { if (code === 0) {
const state = TailscaleLib.parseStatusResult(stdout); ToastService.showInfo(TailscaleLib.getStrings().copied(root._copyText))
root.isConnected = state.isConnected;
root.tailscaleIP = state.tailscaleIP;
root.currentExitNode = state.currentExitNode;
root.peers = state.peers;
} else { } else {
root.isConnected = false; root._copyIndex += 1
root.tailscaleIP = ""; root._runNextCopy()
root.currentExitNode = ""; }
root.peers = []; }
ToastService.showError("tailscalectl", I18n.tr(TailscaleLib.formatError("status")));
} }
const cmd = TailscaleLib.commandForPendingAction(root._pendingAction, root.isConnected); Process {
if (cmd) { id: exitNodeProcess
// Exact same decision point as before: act based on fresh poll truth, then verify.
Proc.runCommand("tailscale-toggle", cmd, (out, c) => { // Command is set dynamically by setExitNode()
if (c !== 0) {
const action = root.isConnected ? "disconnect" : "connect"; stderr: StdioCollector {}
// Note: Proc callback provides no stderr (per chosen strategy); generic error only.
ToastService.showError("tailscalectl", I18n.tr(TailscaleLib.formatError(action))); onExited: (code, status) => {
if (code !== 0) {
var detail = exitNodeProcess.stderr.text.trim();
ToastService.showError("tailscalectl", TailscaleLib.formatError("set", detail));
} }
root._pendingAction = ""; root.refreshStatus();
root._runStatusCheck(); // post-action verification poll (exact behavior) }
}); }
Process {
id: statusCheck
command: ["tailscale", "status", "--json"]
stdout: StdioCollector {}
onExited: (code, status) => {
if (code === 0) {
const state = TailscaleLib.parseStatusResult(statusCheck.stdout.text)
root.isConnected = state.isConnected
root.tailscaleIP = state.tailscaleIP
root.currentExitNode = state.currentExitNode
root.peers = state.peers
} else { } else {
root._pendingAction = ""; root.isConnected = false
root.tailscaleIP = ""
root.currentExitNode = ""
root.peers = []
ToastService.showError("tailscalectl", TailscaleLib.formatError("status"))
}
const cmd = TailscaleLib.commandForPendingAction(statusCheck._pendingAction, root.isConnected);
if (cmd) {
toggleProcess.command = cmd;
toggleProcess.running = true;
}
statusCheck._pendingAction = null;
} }
});
} }
function toggleTailscale() { function toggleTailscale() {
root._pendingAction = "toggle"; statusCheck._pendingAction = "toggle";
root._runStatusCheck(); statusCheck.running = true;
} }
function refreshStatus() { function refreshStatus() {
root._runStatusCheck(); statusCheck.running = true;
} }
function setExitNode(hostname) { function setExitNode(hostname) {
const cmd = TailscaleLib.makeExitNodeCommand(hostname); const cmd = TailscaleLib.makeExitNodeCommand(hostname)
if (!cmd) { if (!cmd) {
ToastService.showError("tailscalectl", I18n.tr(TailscaleLib.getStrings().invalidExitNodeHostname)); ToastService.showError("tailscalectl", TailscaleLib.getStrings().invalidExitNodeHostname)
return; return
} }
Proc.runCommand("tailscale-exit", cmd, (stdout, code) => { exitNodeProcess.command = cmd
if (code !== 0) { exitNodeProcess.running = true
// Note: no stderr detail available from Proc (accepted per plan).
ToastService.showError("tailscalectl", I18n.tr(TailscaleLib.formatError("set")));
}
root._runStatusCheck();
});
} }
function copyToClipboard(text) { function copyToClipboard(text) {
root._copyText = text; root._copyText = text
root._copyIndex = 0; root._copyIndex = 0
root._runNextCopy(); root._runNextCopy()
} }
function _runNextCopy() { function _runNextCopy() {
const cmds = TailscaleLib.getClipboardCommands(root._copyText); const cmds = TailscaleLib.getClipboardCommands(root._copyText)
if (root._copyIndex >= cmds.length) { if (root._copyIndex >= cmds.length) {
ToastService.showError("tailscalectl", I18n.tr(TailscaleLib.formatError("clipboard"))); ToastService.showError("tailscalectl", TailscaleLib.formatError("clipboard"))
return; return
} }
Proc.runCommand("tailscale-copy-" + root._copyIndex, cmds[root._copyIndex], (stdout, code) => { copyProcess.command = cmds[root._copyIndex]
if (code === 0) { copyProcess.running = true
ToastService.showInfo(I18n.tr(TailscaleLib.getStrings().copied).arg(root._copyText));
} else {
root._copyIndex += 1;
root._runNextCopy();
}
});
} }
popoutContent: Component { popoutContent: Component {
PopoutComponent { PopoutComponent {
headerText: I18n.tr(TailscaleLib.getStrings().header) headerText: "Tailscale"
detailsText: root.isConnected ? I18n.tr(TailscaleLib.getStrings().connected) : I18n.tr(TailscaleLib.getStrings().disconnected) detailsText: root.isConnected ? TailscaleLib.getStrings().connected : TailscaleLib.getStrings().disconnected
showCloseButton: true showCloseButton: true
Item { Item {
@ -161,7 +188,7 @@ PluginComponent {
Item { width: 1; height: 1; Layout.fillWidth: true } Item { width: 1; height: 1; Layout.fillWidth: true }
StyledText { StyledText {
text: I18n.tr(TailscaleLib.getStrings().exitNodePrefix) + (root.currentExitNode || I18n.tr(TailscaleLib.getStrings().none)) text: TailscaleLib.getStrings().exitNodePrefix + (root.currentExitNode || TailscaleLib.getStrings().none)
font.pixelSize: Theme.fontSizeSmall font.pixelSize: Theme.fontSizeSmall
color: Theme.surfaceVariantText color: Theme.surfaceVariantText
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter

View file

@ -1,40 +0,0 @@
# I18n for tailscalectl
This plugin is fully instrumented with `I18n.tr(...)` (from `qs.Common`) for all user-facing strings.
- Source keys are the American English strings defined in `lib.js` (returned by `getStrings()`, plus bases from `errorMessage()` / `formatError()`).
- Call sites in `TailscaleWidget.qml` wrap them: `I18n.tr(TailscaleLib.getStrings().foo)` or `I18n.tr(TailscaleLib.getStrings().copied).arg(text)`.
- Today: falls back to the key (perfect en-US).
- Future: Drop additional `xx.json` here (or contribute keys to DMS core translations) when a loader or extraction process supports per-plugin locales.
## Current keys (source of truth)
See `getStrings()` and `errorMessage()` in `lib.js` for the canonical list.
Example `en.json` (for documentation / future tools):
```json
{
"Tailscale": "Tailscale",
"Connected": "Connected",
"Disconnected": "Disconnected",
"Exit node: ": "Exit node: ",
"None": "None",
"Copied %1 to clipboard": "Copied %1 to clipboard",
"Invalid exit node hostname": "Invalid exit node hostname",
"Failed to connect to Tailscale": "Failed to connect to Tailscale",
"Failed to disconnect from Tailscale": "Failed to disconnect from Tailscale",
"Failed to set exit node": "Failed to set exit node",
"Failed to read Tailscale status": "Failed to read Tailscale status",
"Error copying to clipboard": "Error copying to clipboard",
"Tailscale command failed": "Tailscale command failed"
}
```
## Notes
- Symbols/glyphs ("×", "↗", "—") are intentionally left as literals in the UI (not run through I18n as they are not linguistic content).
- Plugin name/description in `plugin.json` and technical IDs ("tailscalectl") remain English.
- This follows DMS `dms-plugin-dev` best practice for future-proofing even when only en is shipped.
Written by AI agent working for @jtmorris. Model: grok-build-0.1.

View file

@ -1,15 +0,0 @@
{
"Tailscale": "Tailscale",
"Connected": "Connected",
"Disconnected": "Disconnected",
"Exit node: ": "Exit node: ",
"None": "None",
"Copied %1 to clipboard": "Copied %1 to clipboard",
"Invalid exit node hostname": "Invalid exit node hostname",
"Failed to connect to Tailscale": "Failed to connect to Tailscale",
"Failed to disconnect from Tailscale": "Failed to disconnect from Tailscale",
"Failed to set exit node": "Failed to set exit node",
"Failed to read Tailscale status": "Failed to read Tailscale status",
"Error copying to clipboard": "Error copying to clipboard",
"Tailscale command failed": "Tailscale command failed"
}

View file

@ -52,7 +52,9 @@ function getStrings() {
disconnected: "Disconnected", disconnected: "Disconnected",
exitNodePrefix: "Exit node: ", exitNodePrefix: "Exit node: ",
none: "None", none: "None",
copied: "Copied %1 to clipboard", copied: function (text) { return "Copied " + text + " to clipboard"; },
clearExitNode: "×",
setExitNode: "↗",
invalidExitNodeHostname: "Invalid exit node hostname" invalidExitNodeHostname: "Invalid exit node hostname"
}; };
} }

View file

@ -6,9 +6,6 @@
"author": "John Morris", "author": "John Morris",
"icon": "vpn_key", "icon": "vpn_key",
"type": "widget", "type": "widget",
"capabilities": ["dankbar-widget"],
"component": "./TailscaleWidget.qml", "component": "./TailscaleWidget.qml",
"permissions": ["process"], "permissions": ["process"]
"requires": ["tailscale"],
"version": "0.2.0"
} }

View file

@ -8,9 +8,9 @@ const { parsePeers, makeExitNodeCommand, findActiveExitNode, errorMessage, forma
* *
* All functions in lib.js are exercised via Node's built-in test runner. * All functions in lib.js are exercised via Node's built-in test runner.
* *
* TailscaleWidget.qml has no automated test coverage. The Proc.runCommand * TailscaleWidget.qml has no automated test coverage. The four Process
* calls, callback-based coordination (exact poll-act-poll preserved), and all * objects, their onExited handlers, and all widget UI behavior must be
* widget UI behavior must be verified manually in a running DMS instance. * verified manually.
*/ */
test("parsePeers extracts exitNode from ExitNodeOption", () => { test("parsePeers extracts exitNode from ExitNodeOption", () => {
@ -115,9 +115,10 @@ test("getStrings returns canonical UI strings for the widget", () => {
assert.ok(s.copied) assert.ok(s.copied)
}) })
test("getStrings.copied is the I18n template key (interpolation happens at call site via .arg)", () => { test("getStrings.copied interpolates the text", () => {
const s = getStrings(); const s = getStrings()
assert.strictEqual(s.copied, "Copied %1 to clipboard"); const msg = s.copied("100.64.0.5")
assert.ok(msg.includes("100.64.0.5"))
}) })
test("shouldShowClearExitNode returns true only when there is a current exit node", () => { test("shouldShowClearExitNode returns true only when there is a current exit node", () => {