(WIP) Code orginazation/refactoring and beging nework refactoring...

This commit is contained in:
Jas Singh
2024-06-29 03:36:57 -07:00
parent 78496ae98a
commit 5ddf5c240d
18 changed files with 1109 additions and 984 deletions

View File

@@ -0,0 +1,39 @@
const renderWapStaging = (self, stagedDevice) => {
self.hook(stagedDevice, ({ value }) => {
return (self.child = Widget.Button({
class_name: "network-element-item",
child: Widget.Box({
hpack: "start",
children: [
Widget.Icon({
class_name: "network-ethernet-icon",
icon: `${stagedDevice["iconName"]}`,
}),
Widget.Box({
class_name: "connection-container",
vertical: true,
children: [
Widget.Label({
class_name: "active-connection",
hpack: "start",
truncate: "end",
wrap: true,
label: stagedDevice.ssid,
}),
Widget.Revealer({
revealChild: stagedDevice.active,
child: Widget.Label({
hpack: "start",
class_name: "connection-status dim",
label: "Connected",
}),
}),
],
}),
],
}),
}));
});
};
export { renderWapStaging };

View File

@@ -0,0 +1,61 @@
const renderWAPs = (self, network) => {
self.hook(network, () => {
const WAPs = network.wifi.access_points;
console.log("WAPs");
console.log(JSON.stringify(WAPs, null, 2));
const filteredWAPs = WAPs.filter((ap) => ap.ssid !== "Unknown").sort(
(a, b) => {
return b.strength - a.strength;
},
);
if (filteredWAPs.length <= 0) {
return (self.child = Widget.Label({
class_name: "waps-not-found dim",
expand: true,
hpack: "center",
vpack: "center",
label: "No Wi-Fi Networks Found",
}));
}
return (self.children = filteredWAPs.map((ap) => {
return Widget.Button({
class_name: "network-element-item",
child: Widget.Box({
hpack: "start",
children: [
Widget.Icon({
class_name: "network-ethernet-icon",
icon: `${ap["iconName"]}`,
}),
Widget.Box({
class_name: "connection-container",
vertical: true,
children: [
Widget.Label({
class_name: "active-connection",
hpack: "start",
truncate: "end",
wrap: true,
label: ap.ssid,
}),
Widget.Revealer({
revealChild: ap.active,
child: Widget.Label({
hpack: "start",
class_name: "connection-status dim",
label: "Connected",
}),
}),
],
}),
],
}),
});
}));
});
};
export { renderWAPs };

View File

@@ -0,0 +1,45 @@
const network = await Service.import("network");
import { renderWAPs } from "./WirelessAPs.js";
import { renderWapStaging } from "./APStaging.js";
const Staging = Variable("none");
const Wifi = () => {
return Widget.Box({
class_name: "menu-section-container wifi",
vertical: true,
children: [
Widget.Box({
class_name: "menu-label-container",
hpack: "fill",
child: Widget.Label({
class_name: "menu-label",
hexpand: true,
hpack: "center",
label: "Wi-Fi",
}),
}),
Widget.Box({
class_name: "menu-items-section",
vertical: true,
children: [
Widget.Box({
class_name: "wap-staging",
setup: (self) => {
renderWapStaging(self, Staging);
},
}),
Widget.Box({
class_name: "available-waps",
vertical: true,
setup: (self) => {
renderWAPs(self, network);
},
}),
],
}),
],
});
};
export { Wifi };