refactor: simplify copy path — drop caching and multi-tool retry state machine, keep simple dms→wl-copy fallback (first-principles plan)

This commit is contained in:
Vybe (Coding Agent) 2026-05-22 10:20:27 +00:00
parent 5ace4095c6
commit 4a7803dc42
2 changed files with 12 additions and 20 deletions

View file

@ -14,10 +14,8 @@ PluginComponent {
property string tailscaleIP: "" property string tailscaleIP: ""
property string currentExitNode: "" property string currentExitNode: ""
property var peers: [] property var peers: []
property string cachedClipboardTool: ""
property string _copyText: "" property string _copyText: ""
property string _copyCurrentTool: "" property string _copyCurrentTool: ""
property int _copyAttempted: 0
property bool _pendingToggle: false // transient one-shot for post-action verification (to be removed in first-principles refactor) property bool _pendingToggle: false // transient one-shot for post-action verification (to be removed in first-principles refactor)
layerNamespacePlugin: "tailscalectl" layerNamespacePlugin: "tailscalectl"
@ -51,17 +49,14 @@ PluginComponent {
onExited: (code, status) => { onExited: (code, status) => {
if (code === 0) { if (code === 0) {
root.cachedClipboardTool = root._copyCurrentTool ToastService.showInfo(TailscaleLib.getStrings().copied(root._copyText))
ToastService.showInfo("Copied " + root._copyText + " to clipboard") } else if (root._copyCurrentTool === "dms") {
// One simple fallback attempt: try wl-copy.
root._copyCurrentTool = "wl-copy"
root._executeCopy()
} else { } else {
root._copyAttempted += 1 var detail = copyProcess.stderr.text.trim()
if (root._copyAttempted < TailscaleLib.allClipboardTools().length) { ToastService.showError("tailscalectl", TailscaleLib.formatError("clipboard", detail))
root._copyCurrentTool = TailscaleLib.nextClipboardTool(root._copyCurrentTool)
root._executeCopy()
} else {
var detail = copyProcess.stderr.text.trim().slice(0, 120)
ToastService.showError("tailscalectl", "No clipboard tool found" + (detail ? " — " + detail : ""))
}
} }
} }
} }
@ -124,19 +119,15 @@ PluginComponent {
function copyToClipboard(text) { function copyToClipboard(text) {
root._copyText = text root._copyText = text
root._copyAttempted = 0 // Simple two-tool fallback per first-principles plan: dms first, then wl-copy.
if (root.cachedClipboardTool) { root._copyCurrentTool = "dms"
root._copyCurrentTool = root.cachedClipboardTool
} else {
root._copyCurrentTool = TailscaleLib.allClipboardTools()[0]
}
root._executeCopy() root._executeCopy()
} }
function _executeCopy() { function _executeCopy() {
var cmd = TailscaleLib.buildCopyCommand(root._copyText, root._copyCurrentTool) var cmd = TailscaleLib.buildCopyCommand(root._copyText, root._copyCurrentTool)
if (!cmd) { if (!cmd) {
ToastService.showError("tailscalectl", "Invalid clipboard command") ToastService.showError("tailscalectl", TailscaleLib.formatError("clipboard"))
return return
} }
copyProcess.command = cmd copyProcess.command = cmd

View file

@ -115,7 +115,8 @@ function errorMessage(cmd) {
"down": "Failed to disconnect from Tailscale", "down": "Failed to disconnect from Tailscale",
"disconnect": "Failed to disconnect from Tailscale", "disconnect": "Failed to disconnect from Tailscale",
"set": "Failed to set exit node", "set": "Failed to set exit node",
"status": "Failed to read Tailscale status" "status": "Failed to read Tailscale status",
"clipboard": "Error copying to clipboard"
}; };
return messages[cmd] || "Tailscale command failed"; return messages[cmd] || "Tailscale command failed";
} }