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
aa3ade1777
commit
2b3b45ccfa
2 changed files with 12 additions and 20 deletions
|
|
@ -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") {
|
||||||
} else {
|
// One simple fallback attempt: try wl-copy.
|
||||||
root._copyAttempted += 1
|
root._copyCurrentTool = "wl-copy"
|
||||||
if (root._copyAttempted < TailscaleLib.allClipboardTools().length) {
|
|
||||||
root._copyCurrentTool = TailscaleLib.nextClipboardTool(root._copyCurrentTool)
|
|
||||||
root._executeCopy()
|
root._executeCopy()
|
||||||
} else {
|
} else {
|
||||||
var detail = copyProcess.stderr.text.trim().slice(0, 120)
|
var detail = copyProcess.stderr.text.trim()
|
||||||
ToastService.showError("tailscalectl", "No clipboard tool found" + (detail ? " — " + detail : ""))
|
ToastService.showError("tailscalectl", TailscaleLib.formatError("clipboard", 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
|
||||||
|
|
|
||||||
|
|
@ -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";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue