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:
parent
b521af3364
commit
93b257ba5d
1 changed files with 13 additions and 20 deletions
|
|
@ -66,7 +66,7 @@ PluginComponent {
|
||||||
|
|
||||||
stdout: StdioCollector {
|
stdout: StdioCollector {
|
||||||
onStreamFinished: {
|
onStreamFinished: {
|
||||||
root.clipboardCmd = this.text.trim()
|
root.clipboardCmd = TailscaleLib.parseClipboardDetection(this.text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -82,19 +82,11 @@ PluginComponent {
|
||||||
|
|
||||||
stdout: StdioCollector {
|
stdout: StdioCollector {
|
||||||
onStreamFinished: {
|
onStreamFinished: {
|
||||||
try {
|
const state = TailscaleLib.parseStatusResult(this.text)
|
||||||
const data = JSON.parse(this.text)
|
root.isConnected = state.isConnected
|
||||||
root.isConnected = data.BackendState === "Running"
|
root.tailscaleIP = state.tailscaleIP
|
||||||
root.tailscaleIP = (data.Self?.TailscaleIPs?.[0]) || ""
|
root.currentExitNode = state.currentExitNode
|
||||||
root.currentExitNode = TailscaleLib.findActiveExitNode(data.Peer || {})
|
root.peers = state.peers
|
||||||
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")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -119,11 +111,7 @@ PluginComponent {
|
||||||
ToastService.showError("tailscalectl", "Tailscale not available")
|
ToastService.showError("tailscalectl", "Tailscale not available")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (root.isConnected) {
|
toggleProcess.command = TailscaleLib.buildToggleCommand(root.isConnected)
|
||||||
toggleProcess.command = ["tailscale", "down"]
|
|
||||||
} else {
|
|
||||||
toggleProcess.command = ["tailscale", "up"]
|
|
||||||
}
|
|
||||||
toggleProcess.running = true
|
toggleProcess.running = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -141,7 +129,12 @@ PluginComponent {
|
||||||
ToastService.showError("tailscalectl", "No clipboard tool found")
|
ToastService.showError("tailscalectl", "No clipboard tool found")
|
||||||
return
|
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
|
copyProcess.running = true
|
||||||
ToastService.showInfo("Copied " + text + " to clipboard")
|
ToastService.showInfo("Copied " + text + " to clipboard")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue