refactor: delegate shell command construction to lib.js functions

Replace inline shell command building in QML with calls to
parseClipboardDetection, parseStatusResult, buildToggleCommand, and
buildCopyCommand. This centralizes sanitization logic and removes
duplicated try/catch and ternary blocks from the UI layer.
This commit is contained in:
Vybe (Coding Agent) 2026-05-20 19:37:08 +00:00
parent b521af3364
commit 93b257ba5d

View file

@ -66,7 +66,7 @@ PluginComponent {
stdout: StdioCollector {
onStreamFinished: {
root.clipboardCmd = this.text.trim()
root.clipboardCmd = TailscaleLib.parseClipboardDetection(this.text)
}
}
@ -82,19 +82,11 @@ PluginComponent {
stdout: StdioCollector {
onStreamFinished: {
try {
const data = JSON.parse(this.text)
root.isConnected = data.BackendState === "Running"
root.tailscaleIP = (data.Self?.TailscaleIPs?.[0]) || ""
root.currentExitNode = TailscaleLib.findActiveExitNode(data.Peer || {})
root.peers = TailscaleLib.parsePeers(data.Peer || {})
} catch (e) {
root.isConnected = false
root.tailscaleIP = ""
root.currentExitNode = ""
root.peers = []
ToastService.showError("tailscalectl", "Failed to parse Tailscale status")
}
const state = TailscaleLib.parseStatusResult(this.text)
root.isConnected = state.isConnected
root.tailscaleIP = state.tailscaleIP
root.currentExitNode = state.currentExitNode
root.peers = state.peers
}
}
@ -119,11 +111,7 @@ PluginComponent {
ToastService.showError("tailscalectl", "Tailscale not available")
return
}
if (root.isConnected) {
toggleProcess.command = ["tailscale", "down"]
} else {
toggleProcess.command = ["tailscale", "up"]
}
toggleProcess.command = TailscaleLib.buildToggleCommand(root.isConnected)
toggleProcess.running = true
}
@ -141,7 +129,12 @@ PluginComponent {
ToastService.showError("tailscalectl", "No clipboard tool found")
return
}
copyProcess.command = ["sh", "-c", "printf '%s' '" + text.replace(/'/g, "'\\''") + "' | " + root.clipboardCmd]
var cmd = TailscaleLib.buildCopyCommand(text, root.clipboardCmd)
if (!cmd) {
ToastService.showError("tailscalectl", "Invalid clipboard command")
return
}
copyProcess.command = cmd
copyProcess.running = true
ToastService.showInfo("Copied " + text + " to clipboard")
}