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:
parent
5ace4095c6
commit
4a7803dc42
2 changed files with 12 additions and 20 deletions
|
|
@ -14,10 +14,8 @@ PluginComponent {
|
|||
property string tailscaleIP: ""
|
||||
property string currentExitNode: ""
|
||||
property var peers: []
|
||||
property string cachedClipboardTool: ""
|
||||
property string _copyText: ""
|
||||
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)
|
||||
|
||||
layerNamespacePlugin: "tailscalectl"
|
||||
|
|
@ -51,17 +49,14 @@ PluginComponent {
|
|||
|
||||
onExited: (code, status) => {
|
||||
if (code === 0) {
|
||||
root.cachedClipboardTool = root._copyCurrentTool
|
||||
ToastService.showInfo("Copied " + root._copyText + " to clipboard")
|
||||
} else {
|
||||
root._copyAttempted += 1
|
||||
if (root._copyAttempted < TailscaleLib.allClipboardTools().length) {
|
||||
root._copyCurrentTool = TailscaleLib.nextClipboardTool(root._copyCurrentTool)
|
||||
ToastService.showInfo(TailscaleLib.getStrings().copied(root._copyText))
|
||||
} else if (root._copyCurrentTool === "dms") {
|
||||
// One simple fallback attempt: try wl-copy.
|
||||
root._copyCurrentTool = "wl-copy"
|
||||
root._executeCopy()
|
||||
} else {
|
||||
var detail = copyProcess.stderr.text.trim().slice(0, 120)
|
||||
ToastService.showError("tailscalectl", "No clipboard tool found" + (detail ? " — " + detail : ""))
|
||||
}
|
||||
var detail = copyProcess.stderr.text.trim()
|
||||
ToastService.showError("tailscalectl", TailscaleLib.formatError("clipboard", detail))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -124,19 +119,15 @@ PluginComponent {
|
|||
|
||||
function copyToClipboard(text) {
|
||||
root._copyText = text
|
||||
root._copyAttempted = 0
|
||||
if (root.cachedClipboardTool) {
|
||||
root._copyCurrentTool = root.cachedClipboardTool
|
||||
} else {
|
||||
root._copyCurrentTool = TailscaleLib.allClipboardTools()[0]
|
||||
}
|
||||
// Simple two-tool fallback per first-principles plan: dms first, then wl-copy.
|
||||
root._copyCurrentTool = "dms"
|
||||
root._executeCopy()
|
||||
}
|
||||
|
||||
function _executeCopy() {
|
||||
var cmd = TailscaleLib.buildCopyCommand(root._copyText, root._copyCurrentTool)
|
||||
if (!cmd) {
|
||||
ToastService.showError("tailscalectl", "Invalid clipboard command")
|
||||
ToastService.showError("tailscalectl", TailscaleLib.formatError("clipboard"))
|
||||
return
|
||||
}
|
||||
copyProcess.command = cmd
|
||||
|
|
|
|||
|
|
@ -115,7 +115,8 @@ function errorMessage(cmd) {
|
|||
"down": "Failed to disconnect from Tailscale",
|
||||
"disconnect": "Failed to disconnect from Tailscale",
|
||||
"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";
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue