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-15 19:28:37 -07:00
|
|
|
layerNamespacePlugin: "tailscalectl"
|
|
|
|
|
popoutWidth: 360
|
|
|
|
|
popoutHeight: 200
|
|
|
|
|
|
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-15 19:14:49 -07:00
|
|
|
} catch (e) {
|
|
|
|
|
root.isConnected = false
|
2026-05-15 19:19:01 -07:00
|
|
|
root.tailscaleIP = ""
|
|
|
|
|
root.currentExitNode = ""
|
|
|
|
|
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-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-15 19:28:37 -07:00
|
|
|
popoutContent: Component {
|
|
|
|
|
PopoutComponent {
|
|
|
|
|
id: popout
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
Column {
|
|
|
|
|
width: parent.width
|
|
|
|
|
height: parent.height - popout.headerHeight - popout.detailsHeight - Theme.spacingXL
|
|
|
|
|
anchors.top: parent.top
|
|
|
|
|
anchors.topMargin: Theme.spacingM
|
|
|
|
|
spacing: Theme.spacingM
|
|
|
|
|
|
|
|
|
|
Row {
|
|
|
|
|
width: parent.width
|
|
|
|
|
spacing: Theme.spacingS
|
2026-05-17 21:11:14 +00:00
|
|
|
anchors.left: parent.left
|
|
|
|
|
anchors.right: parent.right
|
|
|
|
|
anchors.leftMargin: Theme.spacingM
|
|
|
|
|
anchors.rightMargin: Theme.spacingM
|
|
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
|
|
|
|
hoverEnabled: true
|
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
|
width: toggleIcon.implicitWidth
|
|
|
|
|
height: toggleIcon.implicitHeight
|
|
|
|
|
onClicked: toggleTailscale()
|
|
|
|
|
|
|
|
|
|
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-15 19:10:50 -07:00
|
|
|
horizontalBarPill: Component {
|
2026-05-17 21:18:02 +00:00
|
|
|
Row {
|
|
|
|
|
id: contentRow
|
|
|
|
|
spacing: Theme.spacingS
|
|
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
|
|
|
|
acceptedButtons: Qt.RightButton
|
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
|
width: hIcon.implicitWidth
|
|
|
|
|
height: hIcon.implicitHeight
|
|
|
|
|
onClicked: toggleTailscale()
|
2026-05-15 19:14:49 -07:00
|
|
|
|
|
|
|
|
DankIcon {
|
2026-05-17 21:18:02 +00:00
|
|
|
id: hIcon
|
2026-05-15 19:14:49 -07:00
|
|
|
name: root.isConnected ? "vpn_key" : "vpn_key_off"
|
|
|
|
|
size: Theme.iconSize
|
|
|
|
|
color: root.isConnected ? Theme.primary : Theme.surfaceText
|
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-05-15 19:10:50 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
verticalBarPill: Component {
|
2026-05-17 21:18:02 +00:00
|
|
|
Column {
|
|
|
|
|
id: contentColumn
|
|
|
|
|
spacing: Theme.spacingXS
|
|
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
|
|
|
|
acceptedButtons: Qt.RightButton
|
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
|
width: vIcon.implicitWidth
|
|
|
|
|
height: vIcon.implicitHeight
|
|
|
|
|
onClicked: toggleTailscale()
|
2026-05-15 19:14:49 -07:00
|
|
|
|
|
|
|
|
DankIcon {
|
2026-05-17 21:18:02 +00:00
|
|
|
id: vIcon
|
2026-05-15 19:14:49 -07:00
|
|
|
name: root.isConnected ? "vpn_key" : "vpn_key_off"
|
|
|
|
|
size: Theme.iconSize
|
|
|
|
|
color: root.isConnected ? Theme.primary : Theme.surfaceText
|
|
|
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-05-15 19:10:50 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|