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-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-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-15 19:19:01 -07:00
|
|
|
Timer {
|
|
|
|
|
interval: 5000
|
|
|
|
|
running: true
|
|
|
|
|
repeat: true
|
|
|
|
|
onTriggered: statusCheck.running = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Component.onCompleted: statusCheck.running = true
|
2026-05-15 19:14:49 -07:00
|
|
|
|
|
|
|
|
Process {
|
|
|
|
|
id: toggleProcess
|
|
|
|
|
|
|
|
|
|
onExited: (code, status) => {
|
|
|
|
|
statusCheck.running = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Process {
|
|
|
|
|
id: statusCheck
|
|
|
|
|
|
|
|
|
|
command: ["tailscale", "status", "--json"]
|
|
|
|
|
|
|
|
|
|
stdout: StdioCollector {
|
|
|
|
|
onStreamFinished: {
|
|
|
|
|
try {
|
|
|
|
|
const data = JSON.parse(this.text)
|
|
|
|
|
root.isConnected = data.BackendState === "Running"
|
2026-05-15 19:19:01 -07:00
|
|
|
root.tailscaleIP = (data.Self?.TailscaleIPs?.[0]) || ""
|
|
|
|
|
root.currentExitNode = data.CurrentExitNode?.HostName || ""
|
2026-05-17 21:59:59 +00:00
|
|
|
root.peers = Object.keys(data.Peers || {}).map(function(key) {
|
|
|
|
|
var p = data.Peers[key]
|
|
|
|
|
return {
|
|
|
|
|
hostname: p.HostName || key,
|
|
|
|
|
ip: (p.TailscaleIPs && p.TailscaleIPs.length) ? p.TailscaleIPs[0] : "",
|
|
|
|
|
online: p.Online || false
|
|
|
|
|
}
|
|
|
|
|
})
|
2026-05-15 19:14:49 -07:00
|
|
|
} catch (e) {
|
|
|
|
|
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-15 19:19:01 -07:00
|
|
|
ToastService.showError("tailscalectl", "Failed to parse Tailscale status")
|
2026-05-15 19:14:49 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onExited: (code, status) => {
|
|
|
|
|
if (code !== 0) {
|
|
|
|
|
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-15 19:14:49 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function toggleTailscale() {
|
|
|
|
|
if (root.isConnected) {
|
|
|
|
|
toggleProcess.command = ["tailscale", "down"]
|
|
|
|
|
} else {
|
|
|
|
|
toggleProcess.command = ["tailscale", "up"]
|
|
|
|
|
}
|
|
|
|
|
toggleProcess.running = true
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-17 21:59:59 +00:00
|
|
|
function copyToClipboard(text) {
|
|
|
|
|
Quickshell.execDetached(["sh", "-c", "echo -n '" + text + "' | wl-copy"])
|
|
|
|
|
ToastService.showInfo("tailscalectl", "Copied: " + text)
|
|
|
|
|
}
|
|
|
|
|
|
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-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
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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-15 19:28:37 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-17 21:23:01 +00:00
|
|
|
MouseArea {
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
acceptedButtons: Qt.RightButton
|
|
|
|
|
propagateComposedEvents: true
|
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
|
|
|
}
|