2026-05-15 19:10:50 -07:00
|
|
|
|
import QtQuick
|
2026-05-15 19:28:37 -07:00
|
|
|
|
import QtQuick.Layouts
|
2026-05-15 19:10:50 -07:00
|
|
|
|
import qs.Common
|
|
|
|
|
|
import qs.Services
|
|
|
|
|
|
import qs.Widgets
|
|
|
|
|
|
import qs.Modules.Plugins
|
2026-05-15 19:14:49 -07:00
|
|
|
|
import Quickshell.Io
|
2026-05-18 18:27:41 +00:00
|
|
|
|
import "./lib.js" as TailscaleLib
|
2026-05-15 19:10:50 -07:00
|
|
|
|
|
|
|
|
|
|
PluginComponent {
|
|
|
|
|
|
id: root
|
|
|
|
|
|
|
2026-05-15 19:14:49 -07:00
|
|
|
|
property bool isConnected: false
|
2026-05-15 19:19:01 -07:00
|
|
|
|
property string tailscaleIP: ""
|
|
|
|
|
|
property string currentExitNode: ""
|
2026-05-17 21:59:59 +00:00
|
|
|
|
property var peers: []
|
2026-05-21 06:37:14 +00:00
|
|
|
|
property string cachedClipboardTool: ""
|
|
|
|
|
|
property string _copyText: ""
|
|
|
|
|
|
property string _copyCurrentTool: ""
|
|
|
|
|
|
property int _copyAttempted: 0
|
2026-05-22 10:19:48 +00:00
|
|
|
|
property bool _pendingToggle: false // transient one-shot for post-action verification (to be removed in first-principles refactor)
|
2026-05-15 19:19:01 -07:00
|
|
|
|
|
2026-05-15 19:28:37 -07:00
|
|
|
|
layerNamespacePlugin: "tailscalectl"
|
|
|
|
|
|
popoutWidth: 360
|
2026-05-17 21:59:59 +00:00
|
|
|
|
popoutHeight: 400
|
2026-05-15 19:28:37 -07:00
|
|
|
|
|
2026-05-18 05:08:15 +00:00
|
|
|
|
Component.onCompleted: {
|
2026-05-22 10:19:56 +00:00
|
|
|
|
// Initial status fetch on load. Subsequent fetches are on-demand (popout open, explicit refresh, or post-action verification).
|
2026-05-21 06:37:14 +00:00
|
|
|
|
statusCheck.running = true
|
2026-05-18 05:08:15 +00:00
|
|
|
|
}
|
2026-05-15 19:14:49 -07:00
|
|
|
|
|
|
|
|
|
|
Process {
|
|
|
|
|
|
id: toggleProcess
|
|
|
|
|
|
|
2026-05-21 06:37:14 +00:00
|
|
|
|
stderr: StdioCollector {}
|
|
|
|
|
|
|
2026-05-15 19:14:49 -07:00
|
|
|
|
onExited: (code, status) => {
|
2026-05-18 20:53:32 +00:00
|
|
|
|
if (code !== 0) {
|
2026-05-21 20:58:47 +00:00
|
|
|
|
var action = root.isConnected ? "disconnect" : "connect"
|
2026-05-21 06:37:14 +00:00
|
|
|
|
var detail = toggleProcess.stderr.text.trim().slice(0, 120)
|
|
|
|
|
|
ToastService.showError("tailscalectl", TailscaleLib.errorMessage(action) + (detail ? " — " + detail : ""))
|
2026-05-18 20:53:32 +00:00
|
|
|
|
}
|
2026-05-15 19:14:49 -07:00
|
|
|
|
statusCheck.running = true
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-17 23:00:22 +00:00
|
|
|
|
Process {
|
|
|
|
|
|
id: copyProcess
|
|
|
|
|
|
|
2026-05-21 06:37:14 +00:00
|
|
|
|
stderr: StdioCollector {}
|
2026-05-18 18:27:41 +00:00
|
|
|
|
|
|
|
|
|
|
onExited: (code, status) => {
|
2026-05-21 06:37:14 +00:00
|
|
|
|
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)
|
|
|
|
|
|
root._executeCopy()
|
|
|
|
|
|
} else {
|
|
|
|
|
|
var detail = copyProcess.stderr.text.trim().slice(0, 120)
|
|
|
|
|
|
ToastService.showError("tailscalectl", "No clipboard tool found" + (detail ? " — " + detail : ""))
|
|
|
|
|
|
}
|
2026-05-18 18:27:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-18 05:08:15 +00:00
|
|
|
|
Process {
|
2026-05-21 06:37:14 +00:00
|
|
|
|
id: exitNodeProcess
|
2026-05-18 05:08:15 +00:00
|
|
|
|
|
2026-05-21 06:37:14 +00:00
|
|
|
|
stderr: StdioCollector {}
|
2026-05-18 05:08:15 +00:00
|
|
|
|
|
|
|
|
|
|
onExited: (code, status) => {
|
2026-05-21 06:37:14 +00:00
|
|
|
|
if (code !== 0) {
|
|
|
|
|
|
var detail = exitNodeProcess.stderr.text.trim().slice(0, 120)
|
|
|
|
|
|
ToastService.showError("tailscalectl", TailscaleLib.errorMessage("set") + (detail ? " — " + detail : ""))
|
|
|
|
|
|
}
|
2026-05-18 05:08:15 +00:00
|
|
|
|
statusCheck.running = true
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-15 19:14:49 -07:00
|
|
|
|
Process {
|
|
|
|
|
|
id: statusCheck
|
|
|
|
|
|
|
|
|
|
|
|
command: ["tailscale", "status", "--json"]
|
|
|
|
|
|
|
2026-05-21 20:58:47 +00:00
|
|
|
|
stdout: StdioCollector {}
|
|
|
|
|
|
|
|
|
|
|
|
onExited: (code, status) => {
|
|
|
|
|
|
if (code === 0) {
|
|
|
|
|
|
const state = TailscaleLib.parseStatusResult(statusCheck.stdout.text)
|
2026-05-20 19:37:08 +00:00
|
|
|
|
root.isConnected = state.isConnected
|
|
|
|
|
|
root.tailscaleIP = state.tailscaleIP
|
|
|
|
|
|
root.currentExitNode = state.currentExitNode
|
|
|
|
|
|
root.peers = state.peers
|
2026-05-21 20:58:47 +00:00
|
|
|
|
} else {
|
2026-05-15 19:14:49 -07:00
|
|
|
|
root.isConnected = false
|
2026-05-15 19:19:01 -07:00
|
|
|
|
root.tailscaleIP = ""
|
|
|
|
|
|
root.currentExitNode = ""
|
2026-05-17 21:59:59 +00:00
|
|
|
|
root.peers = []
|
2026-05-21 07:02:48 +00:00
|
|
|
|
ToastService.showError("tailscalectl", TailscaleLib.errorMessage("status"))
|
2026-05-15 19:14:49 -07:00
|
|
|
|
}
|
2026-05-22 06:34:08 +00:00
|
|
|
|
|
2026-05-22 10:19:48 +00:00
|
|
|
|
// Post-action verification: if a toggle was requested, use the fresh state we just received.
|
2026-05-22 06:34:08 +00:00
|
|
|
|
if (root._pendingToggle) {
|
|
|
|
|
|
root._pendingToggle = false
|
|
|
|
|
|
toggleProcess.command = TailscaleLib.buildToggleCommand(root.isConnected)
|
|
|
|
|
|
toggleProcess.running = true
|
|
|
|
|
|
}
|
2026-05-15 19:14:49 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function toggleTailscale() {
|
2026-05-22 10:19:48 +00:00
|
|
|
|
// Post-action verification: force a fresh status check, then act on the real ground truth.
|
2026-05-22 06:34:08 +00:00
|
|
|
|
root._pendingToggle = true
|
|
|
|
|
|
statusCheck.running = true
|
2026-05-15 19:14:49 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-18 18:27:41 +00:00
|
|
|
|
function setExitNode(hostname) {
|
|
|
|
|
|
exitNodeProcess.command = TailscaleLib.makeExitNodeCommand(hostname)
|
|
|
|
|
|
exitNodeProcess.running = true
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-17 23:00:22 +00:00
|
|
|
|
function copyToClipboard(text) {
|
2026-05-21 06:37:14 +00:00
|
|
|
|
root._copyText = text
|
|
|
|
|
|
root._copyAttempted = 0
|
|
|
|
|
|
if (root.cachedClipboardTool) {
|
|
|
|
|
|
root._copyCurrentTool = root.cachedClipboardTool
|
|
|
|
|
|
} else {
|
|
|
|
|
|
root._copyCurrentTool = TailscaleLib.allClipboardTools()[0]
|
2026-05-18 05:08:15 +00:00
|
|
|
|
}
|
2026-05-21 06:37:14 +00:00
|
|
|
|
root._executeCopy()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function _executeCopy() {
|
|
|
|
|
|
var cmd = TailscaleLib.buildCopyCommand(root._copyText, root._copyCurrentTool)
|
2026-05-20 19:37:08 +00:00
|
|
|
|
if (!cmd) {
|
|
|
|
|
|
ToastService.showError("tailscalectl", "Invalid clipboard command")
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
copyProcess.command = cmd
|
2026-05-17 23:00:22 +00:00
|
|
|
|
copyProcess.running = true
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-15 19:28:37 -07:00
|
|
|
|
popoutContent: Component {
|
|
|
|
|
|
PopoutComponent {
|
|
|
|
|
|
headerText: "Tailscale"
|
2026-05-17 21:11:14 +00:00
|
|
|
|
detailsText: root.isConnected ? "Connected" : "Disconnected"
|
2026-05-15 19:28:37 -07:00
|
|
|
|
showCloseButton: true
|
|
|
|
|
|
|
2026-05-17 21:32:46 +00:00
|
|
|
|
Item {
|
2026-05-17 21:59:59 +00:00
|
|
|
|
id: contentItem
|
2026-05-15 19:28:37 -07:00
|
|
|
|
width: parent.width
|
2026-05-17 21:59:59 +00:00
|
|
|
|
height: Theme.spacingM + statusRow.implicitHeight + Theme.spacingM + peerList.height + Theme.spacingM
|
2026-05-15 19:28:37 -07:00
|
|
|
|
|
|
|
|
|
|
Row {
|
2026-05-17 21:32:46 +00:00
|
|
|
|
id: statusRow
|
|
|
|
|
|
y: Theme.spacingM
|
2026-05-15 19:28:37 -07:00
|
|
|
|
width: parent.width
|
|
|
|
|
|
spacing: Theme.spacingS
|
2026-05-17 21:11:14 +00:00
|
|
|
|
anchors.left: parent.left
|
|
|
|
|
|
anchors.leftMargin: Theme.spacingM
|
2026-05-17 21:32:46 +00:00
|
|
|
|
anchors.right: parent.right
|
2026-05-17 21:11:14 +00:00
|
|
|
|
anchors.rightMargin: Theme.spacingM
|
|
|
|
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
|
|
|
|
|
hoverEnabled: true
|
|
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
|
|
width: toggleIcon.implicitWidth
|
|
|
|
|
|
height: toggleIcon.implicitHeight
|
2026-05-17 21:32:46 +00:00
|
|
|
|
onClicked: {
|
|
|
|
|
|
root.toggleTailscale()
|
|
|
|
|
|
}
|
2026-05-17 21:11:14 +00:00
|
|
|
|
|
|
|
|
|
|
DankIcon {
|
|
|
|
|
|
id: toggleIcon
|
|
|
|
|
|
name: root.isConnected ? "power" : "power_off"
|
|
|
|
|
|
size: Theme.iconSize
|
|
|
|
|
|
color: Theme.primary
|
|
|
|
|
|
anchors.centerIn: parent
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-05-15 19:28:37 -07:00
|
|
|
|
|
|
|
|
|
|
StyledText {
|
2026-05-17 21:11:14 +00:00
|
|
|
|
text: root.tailscaleIP || "—"
|
|
|
|
|
|
font.pixelSize: Theme.fontSizeSmall
|
|
|
|
|
|
color: Theme.primary
|
2026-05-15 19:28:37 -07:00
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Item { width: 1; height: 1; Layout.fillWidth: true }
|
|
|
|
|
|
|
|
|
|
|
|
StyledText {
|
2026-05-17 21:11:14 +00:00
|
|
|
|
text: "Exit node: " + (root.currentExitNode || "None")
|
2026-05-15 19:28:37 -07:00
|
|
|
|
font.pixelSize: Theme.fontSizeSmall
|
2026-05-17 21:11:14 +00:00
|
|
|
|
color: Theme.surfaceVariantText
|
2026-05-15 19:28:37 -07:00
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
|
|
}
|
2026-05-18 18:27:41 +00:00
|
|
|
|
|
|
|
|
|
|
MouseArea {
|
2026-05-22 06:33:33 +00:00
|
|
|
|
visible: TailscaleLib.shouldShowClearExitNode(root.currentExitNode)
|
2026-05-18 18:27:41 +00:00
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
|
|
|
|
|
hoverEnabled: true
|
|
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
|
|
width: clearExitNodeText.implicitWidth
|
|
|
|
|
|
height: clearExitNodeText.implicitHeight
|
|
|
|
|
|
onClicked: {
|
|
|
|
|
|
root.setExitNode("")
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
StyledText {
|
|
|
|
|
|
id: clearExitNodeText
|
|
|
|
|
|
text: "×"
|
|
|
|
|
|
font.pixelSize: Theme.fontSizeSmall
|
|
|
|
|
|
color: Theme.surfaceVariantText
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-05-15 19:28:37 -07:00
|
|
|
|
}
|
2026-05-17 21:59:59 +00:00
|
|
|
|
|
|
|
|
|
|
ListView {
|
|
|
|
|
|
id: peerList
|
|
|
|
|
|
y: Theme.spacingM + statusRow.implicitHeight + Theme.spacingM
|
|
|
|
|
|
width: parent.width - Theme.spacingM * 2
|
|
|
|
|
|
height: Math.min(root.peers.length * (Theme.fontSizeSmall + Theme.spacingXS), 200)
|
|
|
|
|
|
anchors.left: parent.left
|
|
|
|
|
|
anchors.leftMargin: Theme.spacingM
|
|
|
|
|
|
model: root.peers
|
|
|
|
|
|
interactive: true
|
|
|
|
|
|
boundsBehavior: Flickable.DragAndOvershootBounds
|
|
|
|
|
|
|
|
|
|
|
|
delegate: Item {
|
|
|
|
|
|
width: peerList.width
|
|
|
|
|
|
height: Theme.fontSizeSmall + Theme.spacingXS
|
|
|
|
|
|
|
|
|
|
|
|
Row {
|
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
spacing: Theme.spacingS
|
|
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
|
|
|
2026-05-17 23:00:22 +00:00
|
|
|
|
MouseArea {
|
|
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
|
|
|
|
|
hoverEnabled: true
|
|
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
|
|
width: peerHostnameText.implicitWidth
|
|
|
|
|
|
height: peerHostnameText.implicitHeight
|
|
|
|
|
|
onClicked: {
|
|
|
|
|
|
root.copyToClipboard(modelData.hostname)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
StyledText {
|
|
|
|
|
|
id: peerHostnameText
|
|
|
|
|
|
text: modelData.hostname
|
|
|
|
|
|
font.pixelSize: Theme.fontSizeSmall
|
|
|
|
|
|
color: modelData.online ? Theme.primary : Theme.surfaceVariantText
|
|
|
|
|
|
}
|
2026-05-17 21:59:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-17 23:00:22 +00:00
|
|
|
|
MouseArea {
|
|
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
|
|
|
|
|
hoverEnabled: true
|
|
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
|
|
width: peerIpText.implicitWidth
|
|
|
|
|
|
height: peerIpText.implicitHeight
|
|
|
|
|
|
onClicked: {
|
|
|
|
|
|
root.copyToClipboard(modelData.ip)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
StyledText {
|
|
|
|
|
|
id: peerIpText
|
|
|
|
|
|
text: modelData.ip
|
|
|
|
|
|
font.pixelSize: Theme.fontSizeSmall
|
|
|
|
|
|
color: Theme.surfaceVariantText
|
2026-05-18 18:27:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
|
|
visible: modelData.exitNode
|
|
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
|
|
|
|
|
hoverEnabled: true
|
|
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
|
|
width: exitNodeButton.implicitWidth
|
|
|
|
|
|
height: exitNodeButton.implicitHeight
|
|
|
|
|
|
onClicked: {
|
|
|
|
|
|
root.setExitNode(modelData.hostname)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
StyledText {
|
|
|
|
|
|
id: exitNodeButton
|
|
|
|
|
|
text: "↗"
|
|
|
|
|
|
font.pixelSize: Theme.fontSizeSmall
|
2026-05-22 06:33:33 +00:00
|
|
|
|
color: TailscaleLib.isActiveExitNode(root.currentExitNode, modelData.hostname) ? Theme.primary : Theme.surfaceVariantText
|
2026-05-17 23:00:22 +00:00
|
|
|
|
}
|
2026-05-17 21:59:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-05-15 19:28:37 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-17 21:23:01 +00:00
|
|
|
|
MouseArea {
|
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
acceptedButtons: Qt.RightButton
|
2026-05-17 21:32:46 +00:00
|
|
|
|
onClicked: {
|
|
|
|
|
|
root.toggleTailscale()
|
|
|
|
|
|
}
|
2026-05-17 21:23:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-15 19:10:50 -07:00
|
|
|
|
horizontalBarPill: Component {
|
2026-05-17 21:18:02 +00:00
|
|
|
|
Row {
|
|
|
|
|
|
spacing: Theme.spacingS
|
|
|
|
|
|
|
2026-05-17 21:23:01 +00:00
|
|
|
|
DankIcon {
|
|
|
|
|
|
name: root.isConnected ? "vpn_key" : "vpn_key_off"
|
|
|
|
|
|
size: Theme.iconSize
|
|
|
|
|
|
color: root.isConnected ? Theme.primary : Theme.surfaceText
|
2026-05-15 19:14:49 -07:00
|
|
|
|
}
|
2026-05-15 19:10:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
verticalBarPill: Component {
|
2026-05-17 21:18:02 +00:00
|
|
|
|
Column {
|
|
|
|
|
|
spacing: Theme.spacingXS
|
|
|
|
|
|
|
2026-05-17 21:23:01 +00:00
|
|
|
|
DankIcon {
|
|
|
|
|
|
name: root.isConnected ? "vpn_key" : "vpn_key_off"
|
|
|
|
|
|
size: Theme.iconSize
|
|
|
|
|
|
color: root.isConnected ? Theme.primary : Theme.surfaceText
|
2026-05-15 19:14:49 -07:00
|
|
|
|
}
|
2026-05-15 19:10:50 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-05-17 21:32:46 +00:00
|
|
|
|
}
|