From 1f731072ac7e0bef369eedabfb396a41331e6ef2 Mon Sep 17 00:00:00 2001
From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>
Date: Fri, 17 Jan 2025 14:55:50 +1100
Subject: networks: make popup window
---
src/modules/popdowns/index.tsx | 2 +
src/modules/popdowns/networks.tsx | 97 +++++++++++++++++++++++++++++++++++++++
2 files changed, 99 insertions(+)
create mode 100644 src/modules/popdowns/networks.tsx
(limited to 'src/modules/popdowns')
diff --git a/src/modules/popdowns/index.tsx b/src/modules/popdowns/index.tsx
index ee6208d..44668a8 100644
--- a/src/modules/popdowns/index.tsx
+++ b/src/modules/popdowns/index.tsx
@@ -1,4 +1,5 @@
import BluetoothDevices from "./bluetoothdevices";
+import Networks from "./networks";
import Notifications from "./notifications";
import Updates from "./updates";
@@ -6,6 +7,7 @@ export default () => {
;
;
;
+ ;
return null;
};
diff --git a/src/modules/popdowns/networks.tsx b/src/modules/popdowns/networks.tsx
new file mode 100644
index 0000000..0e9fe2f
--- /dev/null
+++ b/src/modules/popdowns/networks.tsx
@@ -0,0 +1,97 @@
+import { bind, execAsync, Variable } from "astal";
+import { Gtk } from "astal/gtk3";
+import AstalNetwork from "gi://AstalNetwork";
+import PopdownWindow from "../../widgets/popdownwindow";
+
+const Network = (accessPoint: AstalNetwork.AccessPoint) => (
+
+
+
+);
+
+const List = () => {
+ const { wifi } = AstalNetwork.get_default();
+ const children = Variable.derive([bind(wifi, "accessPoints"), bind(wifi, "activeAccessPoint")], (aps, ac) =>
+ aps
+ .filter(a => a.ssid)
+ .sort((a, b) => (a === ac ? -1 : b.strength - a.strength))
+ .map(Network)
+ );
+
+ return (
+ children.drop()}>
+ {bind(children)}
+
+ );
+};
+
+export default () => {
+ const network = AstalNetwork.get_default();
+ const label = Variable("");
+
+ const update = () => {
+ if (network.primary === AstalNetwork.Primary.WIFI) label.set(network.wifi.ssid ?? "Disconnected");
+ else if (network.primary === AstalNetwork.Primary.WIRED) label.set(`Ethernet (${network.wired.speed})`);
+ else label.set("No Wifi");
+ };
+ network.connect("notify::primary", update);
+ network.get_wifi()?.connect("notify::ssid", update);
+ network.get_wired()?.connect("notify::speed", update);
+ update();
+
+ return (
+ a.length)}
+ countLabel={bind(label)}
+ headerButtons={[
+ {
+ label: bind(network.wifi, "enabled").as(p => (p ? "Disable" : "Enable")),
+ onClicked: () => (network.wifi.enabled = !network.wifi.enabled),
+ },
+ {
+ label: "Scan",
+ onClicked: () => network.wifi.scan(),
+ enabled: bind(network.wifi, "scanning"),
+ },
+ ]}
+ emptyIcon="wifi_off"
+ emptyLabel={bind(network.wifi, "enabled").as(p => (p ? "No available networks" : "Wifi is off"))}
+ list={
}
+ />
+ );
+};
--
cgit v1.2.3-freya