diff --git a/modules/bar/states/Network/NetworkState.qml b/modules/bar/states/Network/NetworkState.qml new file mode 100644 index 0000000..96df7ce --- /dev/null +++ b/modules/bar/states/Network/NetworkState.qml @@ -0,0 +1,37 @@ +pragma Singleton +import QtQuick +import Quickshell +import Quickshell.Io + +QtObject { + id: root + + property string status: "..." + property bool running: false + + // Timer property + property Timer networkTimer: Timer { + interval: 10000 + repeat: true + running: true + onTriggered: networkScript.running = true + } + + // Process property + property Process networkScript: Process { + running: true + command: ["sh", "-c", Quickshell.env("HOME") + "/.config/quickshell/modules/bar/scripts/Network.sh"] + + stdout: StdioCollector { + onStreamFinished: { + root.status = this.text.trim() + console.log("Network status:", root.status) + } + } + } + + Component.onCompleted: { + networkScript.start() + networkTimer.start() + } +} \ No newline at end of file diff --git a/modules/bar/states/Network/qmldir b/modules/bar/states/Network/qmldir new file mode 100644 index 0000000..1ee04fa --- /dev/null +++ b/modules/bar/states/Network/qmldir @@ -0,0 +1 @@ +singleton NetworkState NetworkState.qml \ No newline at end of file diff --git a/modules/bar/widgets/Network.qml b/modules/bar/widgets/Network.qml index 61547df..b9f84f6 100644 --- a/modules/bar/widgets/Network.qml +++ b/modules/bar/widgets/Network.qml @@ -3,6 +3,7 @@ import Quickshell import Quickshell.Hyprland import Quickshell.Io import "../../../colors" +import "../states/Network" as Global MouseArea { id: networkButton @@ -13,7 +14,8 @@ MouseArea { cursorShape: Qt.PointingHandCursor onClicked: { - networkStatus.running = true + Global.NetworkState.networkScript.start() + // networkStatus.running = true } Rectangle { @@ -26,30 +28,31 @@ MouseArea { Text { id: networkText + text: Global.NetworkState.status anchors.centerIn: parent font.pixelSize: 26 font.family: "Nerd Font" color: networkButton.containsMouse ? Colors.tertiary_fg : networkText.text === "󰤭 /󱐤" ? Colors.error : Colors.primary } - Process { - id: networkStatus - command: ["sh", "-c", Quickshell.env("HOME") + "/.config/quickshell/modules/bar/scripts/Network.sh"] - running: true + // Process { + // id: networkStatus + // command: ["sh", "-c", Quickshell.env("HOME") + "/.config/quickshell/modules/bar/scripts/Network.sh"] + // running: true - stdout: StdioCollector { - onStreamFinished: { - networkText.text = this.text.trim() - // console.log("networkScript networkText:", this.text.trim()) - } - } - } + // stdout: StdioCollector { + // onStreamFinished: { + // networkText.text = this.text.trim() + // // console.log("networkScript networkText:", this.text.trim()) + // } + // } + // } - Timer { - interval: 10000 - running: true - repeat: true - onTriggered: networkStatus.running = true - } + // Timer { + // interval: 10000 + // running: true + // repeat: true + // onTriggered: networkStatus.running = true + // } } } \ No newline at end of file