From 9a90d26e8109d9f43d76e1b9c0a7447004abb8df Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Wed, 9 Jul 2025 10:13:37 +0700 Subject: [PATCH] right sidebar: cloudflare warp --- .../modules/common/widgets/ButtonGroup.qml | 1 + .../modules/sidebarRight/SidebarRight.qml | 1 + .../quickToggles/CloudflareWarp.qml | 89 +++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 .config/quickshell/modules/sidebarRight/quickToggles/CloudflareWarp.qml diff --git a/.config/quickshell/modules/common/widgets/ButtonGroup.qml b/.config/quickshell/modules/common/widgets/ButtonGroup.qml index 5356535f4..4b8676f40 100644 --- a/.config/quickshell/modules/common/widgets/ButtonGroup.qml +++ b/.config/quickshell/modules/common/widgets/ButtonGroup.qml @@ -20,6 +20,7 @@ Rectangle { let total = 0; for (let i = 0; i < rowLayout.children.length; ++i) { const child = rowLayout.children[i]; + if (!child.visible) continue; total += child.baseWidth ?? child.implicitWidth ?? child.width; } return total + rowLayout.spacing * (rowLayout.children.length - 1); diff --git a/.config/quickshell/modules/sidebarRight/SidebarRight.qml b/.config/quickshell/modules/sidebarRight/SidebarRight.qml index 376687af3..71ce53dbd 100644 --- a/.config/quickshell/modules/sidebarRight/SidebarRight.qml +++ b/.config/quickshell/modules/sidebarRight/SidebarRight.qml @@ -179,6 +179,7 @@ Scope { NightLight {} GameMode {} IdleInhibitor {} + CloudflareWarp {} } // Center widget group diff --git a/.config/quickshell/modules/sidebarRight/quickToggles/CloudflareWarp.qml b/.config/quickshell/modules/sidebarRight/quickToggles/CloudflareWarp.qml new file mode 100644 index 000000000..7f6aba21b --- /dev/null +++ b/.config/quickshell/modules/sidebarRight/quickToggles/CloudflareWarp.qml @@ -0,0 +1,89 @@ +import "root:/modules/common" +import "root:/modules/common/widgets" +import "../" +import QtQuick +import Quickshell.Io +import Quickshell +import Quickshell.Hyprland + +QuickToggleButton { + id: root + toggled: false + visible: false + + contentItem: CustomIcon { + id: distroIcon + source: 'cloudflare-dns-symbolic' + + anchors.centerIn: parent + width: 12 + height: 12 + colorize: true + color: root.toggled ? Appearance.m3colors.m3onPrimary : Appearance.colors.colOnLayer1 + + Behavior on color { + animation: Appearance.animation.elementMoveFast.colorAnimation.createObject(this) + } + } + + onClicked: { + if (toggled) { + root.toggled = false + Quickshell.execDetached(["warp-cli", "disconnect"]) + } else { + root.toggled = true + Quickshell.execDetached(["warp-cli", "connect"]) + } + } + + Process { + id: connectProc + command: ["warp-cli", "connect"] + onExited: (exitCode, exitStatus) => { + console.log("Warp connection exited with code and status:", exitCode, exitStatus) + if (exitCode === 0) { + connectProc.running = true + } else { + console.error("Warp connection failed, please check your connection or try again later.") + } + } + } + + Process { + id: registrationProc + command: ["warp-cli", "registration", "new"] + onExited: (exitCode, exitStatus) => { + console.log("Warp registration exited with code and status:", exitCode, exitStatus) + if (exitCode === 0) { + connectProc.running = true + } else { + Quickshell.execDetached(["notify-send", "Cloudflare Warp", "Registration failed. Please inspect manually with the warp-cli command", "-a", "Shell"]) + } + } + } + + Process { + id: fetchActiveState + running: true + command: ["bash", "-c", "warp-cli status"] + stdout: StdioCollector { + id: warpStatusCollector + onStreamFinished: { + if (warpStatusCollector.text.length > 0) { + console.log("Showing warp") + root.visible = true + } + if (warpStatusCollector.text.includes("Unable")) { + registrationProc.running = true + } else if (warpStatusCollector.text.includes("Connected")) { + root.toggled = true + } else if (warpStatusCollector.text.includes("Disconnected")) { + root.toggled = false + } + } + } + } + StyledToolTip { + content: qsTr("Cloudflare WARP (1.1.1.1)") + } +}