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 _copyText: ""
|
2026-05-22 21:35:07 +00:00
|
|
|
|
property int _copyIndex: 0
|
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-23 04:41:40 +00:00
|
|
|
|
var action = root.isConnected ? "disconnect" : "connect";
|
|
|
|
|
|
var detail = toggleProcess.stderr.text.trim();
|
2026-05-24 20:57:49 +00:00
|
|
|
|
ToastService.showError("tailscalectl", I18n.tr(TailscaleLib.formatError(action, detail)));
|
2026-05-18 20:53:32 +00:00
|
|
|
|
}
|
2026-05-23 04:41:40 +00:00
|
|
|
|
root.refreshStatus();
|
2026-05-15 19:14:49 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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) {
|
2026-05-24 20:57:49 +00:00
|
|
|
|
ToastService.showInfo(I18n.tr(TailscaleLib.getStrings().copied).arg(root._copyText))
|
2026-05-21 06:37:14 +00:00
|
|
|
|
} else {
|
2026-05-22 21:35:07 +00:00
|
|
|
|
root._copyIndex += 1
|
|
|
|
|
|
root._runNextCopy()
|
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-22 20:46:37 +00:00
|
|
|
|
// Command is set dynamically by setExitNode()
|
|
|
|
|
|
|
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) {
|
2026-05-23 04:41:40 +00:00
|
|
|
|
var detail = exitNodeProcess.stderr.text.trim();
|
2026-05-24 20:57:49 +00:00
|
|
|
|
ToastService.showError("tailscalectl", I18n.tr(TailscaleLib.formatError("set", detail)));
|
2026-05-21 06:37:14 +00:00
|
|
|
|
}
|
2026-05-23 04:41:40 +00:00
|
|
|
|
root.refreshStatus();
|
2026-05-18 05:08:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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-24 20:57:49 +00:00
|
|
|
|
ToastService.showError("tailscalectl", I18n.tr(TailscaleLib.formatError("status")))
|
2026-05-15 19:14:49 -07:00
|
|
|
|
}
|
2026-05-22 06:34:08 +00:00
|
|
|
|
|
2026-05-23 04:41:40 +00:00
|
|
|
|
const cmd = TailscaleLib.commandForPendingAction(statusCheck._pendingAction, root.isConnected);
|
|
|
|
|
|
if (cmd) {
|
|
|
|
|
|
toggleProcess.command = cmd;
|
|
|
|
|
|
toggleProcess.running = true;
|
2026-05-22 06:34:08 +00:00
|
|
|
|
}
|
2026-05-23 04:41:40 +00:00
|
|
|
|
statusCheck._pendingAction = null;
|
2026-05-15 19:14:49 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function toggleTailscale() {
|
2026-05-23 04:41:40 +00:00
|
|
|
|
statusCheck._pendingAction = "toggle";
|
|
|
|
|
|
statusCheck.running = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function refreshStatus() {
|
|
|
|
|
|
statusCheck.running = true;
|
2026-05-15 19:14:49 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-18 18:27:41 +00:00
|
|
|
|
function setExitNode(hostname) {
|
2026-05-22 20:46:37 +00:00
|
|
|
|
const cmd = TailscaleLib.makeExitNodeCommand(hostname)
|
|
|
|
|
|
if (!cmd) {
|
2026-05-24 20:57:49 +00:00
|
|
|
|
ToastService.showError("tailscalectl", I18n.tr(TailscaleLib.getStrings().invalidExitNodeHostname))
|
2026-05-22 20:46:37 +00:00
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
exitNodeProcess.command = cmd
|
2026-05-18 18:27:41 +00:00
|
|
|
|
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
|
2026-05-22 21:35:07 +00:00
|
|
|
|
root._copyIndex = 0
|
|
|
|
|
|
root._runNextCopy()
|
2026-05-21 06:37:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-22 21:35:07 +00:00
|
|
|
|
function _runNextCopy() {
|
|
|
|
|
|
const cmds = TailscaleLib.getClipboardCommands(root._copyText)
|
|
|
|
|
|
if (root._copyIndex >= cmds.length) {
|
2026-05-24 20:57:49 +00:00
|
|
|
|
ToastService.showError("tailscalectl", I18n.tr(TailscaleLib.formatError("clipboard")))
|
2026-05-20 19:37:08 +00:00
|
|
|
|
return
|
|
|
|
|
|
}
|
2026-05-22 21:35:07 +00:00
|
|
|
|
copyProcess.command = cmds[root._copyIndex]
|
2026-05-17 23:00:22 +00:00
|
|
|
|
copyProcess.running = true
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-15 19:28:37 -07:00
|
|
|
|
popoutContent: Component {
|
|
|
|
|
|
PopoutComponent {
|
2026-05-24 20:57:49 +00:00
|
|
|
|
headerText: I18n.tr(TailscaleLib.getStrings().header)
|
|
|
|
|
|
detailsText: root.isConnected ? I18n.tr(TailscaleLib.getStrings().connected) : I18n.tr(TailscaleLib.getStrings().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-24 20:57:49 +00:00
|
|
|
|
text: I18n.tr(TailscaleLib.getStrings().exitNodePrefix) + (root.currentExitNode || I18n.tr(TailscaleLib.getStrings().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-22 20:46:37 +00:00
|
|
|
|
}
|