Network module rework (#48)

* Fixes #45 - Reworked the network module to be more responsive and added ssid truncation configuration.

* Added truncation options in the defaults.
This commit is contained in:
Jas Singh
2024-07-30 21:51:36 -07:00
committed by GitHub
parent 26f61ed513
commit aae22bef5e
4 changed files with 47 additions and 50 deletions

View File

@@ -3,60 +3,53 @@ const network = await Service.import("network");
import options from "options"; import options from "options";
import { openMenu } from "../utils.js"; import { openMenu } from "../utils.js";
const { label: networkLabel, truncation, truncation_size } = options.bar.network;
const Network = () => { const Network = () => {
const wifiIndicator = [
Widget.Icon({
class_name: "bar-button-icon network",
icon: network.wifi.bind("icon_name"),
}),
Widget.Box({
children: Utils.merge(
[network.bind("wifi"), options.bar.network.label.bind("value")],
(wifi, showLabel) => {
if (!showLabel) {
return [];
}
return [
Widget.Label({
class_name: "bar-button-label network",
label: wifi.ssid ? `${wifi.ssid.substring(0, 7)}` : "--",
}),
]
},
)
})
];
const wiredIndicator = [
Widget.Icon({
class_name: "bar-button-icon network",
icon: network.wired.bind("icon_name"),
}),
Widget.Box({
children: Utils.merge(
[network.bind("wired"), options.bar.network.label.bind("value")],
(_, showLabel) => {
if (!showLabel) {
return [];
}
return [
Widget.Label({
class_name: "bar-button-label network",
label: "Wired",
}),
]
},
)
})
];
return { return {
component: Widget.Box({ component: Widget.Box({
vpack: "center", vpack: "center",
class_name: "bar-network", class_name: "bar-network",
children: network children: [
.bind("primary") Widget.Icon({
.as((w) => (w === "wired" ? wiredIndicator : wifiIndicator)), class_name: "bar-button-icon network",
icon: Utils.merge([
network.bind("primary"),
network.bind("wifi"),
network.bind("wired")
], (pmry, wfi, wrd) => {
if (pmry === "wired") {
return wrd.icon_name;
}
return wfi.icon_name;
})
}),
Widget.Box({
class_name: "bar-button-icon network",
child: Utils.merge([
network.bind("primary"),
network.bind("wifi"),
networkLabel.bind("value"),
truncation.bind("value"),
truncation_size.bind("value")
], (pmry, wfi, showLbl, trunc, tSize) => {
if (!showLbl) {
return Widget.Box();
}
if (pmry === "wired") {
return Widget.Label({
class_name: "bar-button-label network",
label: "Wired".substring(0, tSize),
})
}
return Widget.Label({
class_name: "bar-button-label network",
label: wfi.ssid ? `${trunc ? wfi.ssid.substring(0, tSize) : wfi.ssid}` : "--",
})
})
}),
]
}), }),
isVisible: true, isVisible: true,
boxClass: "network", boxClass: "network",

View File

@@ -39,7 +39,7 @@ const WeatherWidget = () => {
return theWeather.value = parsedWeather; return theWeather.value = parsedWeather;
} catch (error) { } catch (error) {
theWeather.value = DEFAULT_WEATHER; theWeather.value = DEFAULT_WEATHER;
console.error(`Failed to parse weather data: ${error}`); console.warn(`Failed to parse weather data: ${error}`);
} }
}) })
.catch((err) => { .catch((err) => {

View File

@@ -620,6 +620,8 @@ const options = mkOptions(OPTIONS, {
label: opt(true), label: opt(true),
}, },
network: { network: {
truncation: opt(true),
truncation_size: opt(7),
label: opt(true), label: opt(true),
}, },
bluetooth: { bluetooth: {

View File

@@ -51,6 +51,8 @@ export const BarSettings = () => {
Header('Network'), Header('Network'),
Option({ opt: options.bar.network.label, title: 'Show Network Name', type: 'boolean' }), Option({ opt: options.bar.network.label, title: 'Show Network Name', type: 'boolean' }),
Option({ opt: options.bar.network.truncation, title: 'Truncate Network Name', subtitle: 'Will truncate the network name to the specified size below.', type: 'boolean' }),
Option({ opt: options.bar.network.truncation_size, title: 'Truncation Size', type: 'number' }),
Option({ opt: options.theme.bar.buttons.network.spacing, title: 'Inner Spacing', subtitle: 'Spacing between the icon and the label inside the buttons.', type: 'string' }), Option({ opt: options.theme.bar.buttons.network.spacing, title: 'Inner Spacing', subtitle: 'Spacing between the icon and the label inside the buttons.', type: 'string' }),
Header('Bluetooth'), Header('Bluetooth'),