diff --git a/tailscalectl/TailscaleWidget.qml b/tailscalectl/TailscaleWidget.qml index 235ffc0..705070e 100644 --- a/tailscalectl/TailscaleWidget.qml +++ b/tailscalectl/TailscaleWidget.qml @@ -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") }