Implemented strict linting standards and prettier formatting config. (#248)

* Implemented strict linting standards and prettier formatting config.

* More linter fixes and type updates.

* More linter updates and type fixes

* Remove noisy comments

* Linter and type updates

* Linter, formatting and type updates.

* Linter updates

* Type updates

* Type updates

* fixed all linter errors

* Fixed all linting, formatting and type issues.

* Resolve merge conflicts.
This commit is contained in:
Jas Singh
2024-09-14 16:20:05 -07:00
committed by GitHub
parent ff13e3dd3c
commit 2c72cc66d8
222 changed files with 13141 additions and 8433 deletions

View File

@@ -1,52 +1,54 @@
const network = await Service.import("network");
import { BoxWidget } from 'lib/types/widget';
const Ethernet = () => {
const network = await Service.import('network');
const Ethernet = (): BoxWidget => {
return Widget.Box({
class_name: "menu-section-container ethernet",
class_name: 'menu-section-container ethernet',
vertical: true,
children: [
Widget.Box({
class_name: "menu-label-container",
hpack: "fill",
class_name: 'menu-label-container',
hpack: 'fill',
child: Widget.Label({
class_name: "menu-label",
class_name: 'menu-label',
hexpand: true,
hpack: "start",
label: "Ethernet",
hpack: 'start',
label: 'Ethernet',
}),
}),
Widget.Box({
class_name: "menu-items-section",
class_name: 'menu-items-section',
vertical: true,
child: Widget.Box({
class_name: "menu-content",
class_name: 'menu-content',
vertical: true,
setup: (self) => {
self.hook(network, () => {
return (self.child = Widget.Box({
class_name: "network-element-item",
class_name: 'network-element-item',
child: Widget.Box({
hpack: "start",
hpack: 'start',
children: [
Widget.Icon({
class_name: `network-icon ethernet ${network.wired.state === "activated" ? "active" : ""}`,
class_name: `network-icon ethernet ${network.wired.state === 'activated' ? 'active' : ''}`,
tooltip_text: network.wired.internet,
icon: `${network.wired["icon_name"]}`,
icon: `${network.wired['icon_name']}`,
}),
Widget.Box({
class_name: "connection-container",
class_name: 'connection-container',
vertical: true,
children: [
Widget.Label({
class_name: "active-connection",
hpack: "start",
truncate: "end",
class_name: 'active-connection',
hpack: 'start',
truncate: 'end',
wrap: true,
label: `Ethernet Connection ${network.wired.state !== "unknown" && typeof network.wired?.speed === "number" ? `(${network.wired?.speed / 1000} Gbps)` : ""}`,
label: `Ethernet Connection ${network.wired.state !== 'unknown' && typeof network.wired?.speed === 'number' ? `(${network.wired?.speed / 1000} Gbps)` : ''}`,
}),
Widget.Label({
hpack: "start",
class_name: "connection-status dim",
hpack: 'start',
class_name: 'connection-status dim',
label:
network.wired.internet.charAt(0).toUpperCase() +
network.wired.internet.slice(1),

View File

@@ -1,19 +1,21 @@
import DropdownMenu from "../DropdownMenu.js";
import { Ethernet } from "./ethernet/index.js";
import { Wifi } from "./wifi/index.js";
import Window from 'types/widgets/window.js';
import DropdownMenu from '../DropdownMenu.js';
import { Ethernet } from './ethernet/index.js';
import { Wifi } from './wifi/index.js';
import { Attribute, Child } from 'lib/types/widget.js';
export default () => {
return DropdownMenu({
name: "networkmenu",
transition: "crossfade",
child: Widget.Box({
class_name: "menu-items network",
child: Widget.Box({
vertical: true,
hexpand: true,
class_name: "menu-items-container network",
children: [Ethernet(), Wifi()],
}),
}),
});
export default (): Window<Child, Attribute> => {
return DropdownMenu({
name: 'networkmenu',
transition: 'crossfade',
child: Widget.Box({
class_name: 'menu-items network',
child: Widget.Box({
vertical: true,
hexpand: true,
class_name: 'menu-items-container network',
children: [Ethernet(), Wifi()],
}),
}),
});
};

View File

@@ -1,23 +1,23 @@
const getWifiIcon = (iconName: string) => {
const deviceIconMap = [
["network-wireless-acquiring", "󰤩"],
["network-wireless-connected", "󰤨"],
["network-wireless-encrypted", "󰤪"],
["network-wireless-hotspot", "󰤨"],
["network-wireless-no-route", "󰤩"],
["network-wireless-offline", "󰤮"],
["network-wireless-signal-excellent", "󰤨"],
["network-wireless-signal-good", "󰤥"],
["network-wireless-signal-ok", "󰤢"],
["network-wireless-signal-weak", "󰤟"],
["network-wireless-signal-none", "󰤯"],
import { WifiIcon } from 'lib/types/network';
const getWifiIcon = (iconName: string): WifiIcon => {
const deviceIconMap: [string, WifiIcon][] = [
['network-wireless-acquiring', '󰤩'],
['network-wireless-connected', '󰤨'],
['network-wireless-encrypted', '󰤪'],
['network-wireless-hotspot', '󰤨'],
['network-wireless-no-route', '󰤩'],
['network-wireless-offline', '󰤮'],
['network-wireless-signal-excellent', '󰤨'],
['network-wireless-signal-good', '󰤥'],
['network-wireless-signal-ok', '󰤢'],
['network-wireless-signal-weak', '󰤟'],
['network-wireless-signal-none', '󰤯'],
];
const foundMatch = deviceIconMap.find((icon) =>
RegExp(icon[0]).test(iconName.toLowerCase()),
);
const foundMatch = deviceIconMap.find((icon) => RegExp(icon[0]).test(iconName.toLowerCase()));
return foundMatch ? foundMatch[1] : "󰤨";
return foundMatch ? foundMatch[1] : '󰤨';
};
export { getWifiIcon };

View File

@@ -1,18 +1,26 @@
import { Network } from "types/service/network";
import { Variable } from "types/variable";
import { AccessPoint } from "lib/types/network";
const renderWapStaging = (self: any, network: Network, staging: Variable<AccessPoint>, connecting: Variable<string>) => {
Utils.merge([network.bind("wifi"), staging.bind("value")], () => {
import { Network } from 'types/service/network';
import { Variable } from 'types/variable';
import { AccessPoint } from 'lib/types/network';
import Box from 'types/widgets/box';
import { Attribute, Child } from 'lib/types/widget';
const renderWapStaging = (
self: Box<Child, Attribute>,
network: Network,
staging: Variable<AccessPoint>,
connecting: Variable<string>,
): void => {
Utils.merge([network.bind('wifi'), staging.bind('value')], () => {
if (!Object.keys(staging.value).length) {
return (self.child = Widget.Box());
}
return (self.child = Widget.Box({
class_name: "network-element-item staging",
class_name: 'network-element-item staging',
vertical: true,
children: [
Widget.Box({
hpack: "fill",
hpack: 'fill',
hexpand: true,
children: [
Widget.Icon({
@@ -20,74 +28,70 @@ const renderWapStaging = (self: any, network: Network, staging: Variable<AccessP
icon: `${staging.value.iconName}`,
}),
Widget.Box({
class_name: "connection-container",
class_name: 'connection-container',
hexpand: true,
vertical: true,
children: [
Widget.Label({
class_name: "active-connection",
hpack: "start",
truncate: "end",
class_name: 'active-connection',
hpack: 'start',
truncate: 'end',
wrap: true,
label: staging.value.ssid,
}),
],
}),
Widget.Revealer({
hpack: "end",
reveal_child: connecting
.bind("value")
.as((c) => staging.value.bssid === c),
hpack: 'end',
reveal_child: connecting.bind('value').as((c) => staging.value.bssid === c),
child: Widget.Spinner({
class_name: "spinner wap",
class_name: 'spinner wap',
}),
}),
],
}),
Widget.Box({
class_name: "network-password-input-container",
hpack: "fill",
class_name: 'network-password-input-container',
hpack: 'fill',
hexpand: true,
children: [
Widget.Entry({
hpack: "start",
hpack: 'start',
hexpand: true,
visibility: false,
class_name: "network-password-input",
placeholder_text: "enter password",
class_name: 'network-password-input',
placeholder_text: 'enter password',
onAccept: (selfInp) => {
connecting.value = staging.value.bssid || "";
connecting.value = staging.value.bssid || '';
Utils.execAsync(
`nmcli dev wifi connect ${staging.value.bssid} password ${selfInp.text}`,
)
.catch((err) => {
connecting.value = "";
console.error(
`Failed to connect to wifi: ${staging.value.ssid}... ${err}`,
);
connecting.value = '';
console.error(`Failed to connect to wifi: ${staging.value.ssid}... ${err}`);
Utils.notify({
summary: "Network",
summary: 'Network',
body: err,
timeout: 5000,
});
})
.then(() => {
connecting.value = "";
connecting.value = '';
staging.value = {} as AccessPoint;
});
selfInp.text = "";
selfInp.text = '';
},
}),
Widget.Button({
hpack: "end",
class_name: "close-network-password-input-button",
hpack: 'end',
class_name: 'close-network-password-input-button',
on_primary_click: () => {
connecting.value = "";
connecting.value = '';
staging.value = {} as AccessPoint;
},
child: Widget.Icon({
class_name: "close-network-password-input-icon",
icon: "window-close-symbolic",
class_name: 'close-network-password-input-icon',
icon: 'window-close-symbolic',
}),
}),
],

View File

@@ -1,36 +1,41 @@
import { Network } from "types/service/network.js";
import { AccessPoint, WifiStatus } from "lib/types/network.js";
import { Variable } from "types/variable.js";
import { getWifiIcon } from "../utils.js";
import { WIFI_STATUS_MAP } from "globals/network.js";
const renderWAPs = (self: any, network: Network, staging: Variable<AccessPoint>, connecting: Variable<string>) => {
const getIdBySsid = (ssid: string, nmcliOutput: string) => {
const lines = nmcliOutput.trim().split("\n");
import { Network } from 'types/service/network.js';
import { AccessPoint, WifiStatus } from 'lib/types/network.js';
import { Variable } from 'types/variable.js';
import { getWifiIcon } from '../utils.js';
import { WIFI_STATUS_MAP } from 'globals/network.js';
import { Attribute, Child } from 'lib/types/widget.js';
import Box from 'types/widgets/box.js';
const renderWAPs = (
self: Box<Child, Attribute>,
network: Network,
staging: Variable<AccessPoint>,
connecting: Variable<string>,
): void => {
const getIdBySsid = (ssid: string, nmcliOutput: string): string | undefined => {
const lines = nmcliOutput.trim().split('\n');
for (const line of lines) {
const columns = line.trim().split(/\s{2,}/);
if (columns[0].includes(ssid)) {
return columns[1];
}
}
return null;
};
const isValidWifiStatus = (status: string): status is WifiStatus => {
return status in WIFI_STATUS_MAP;
};
const getWifiStatus = () => {
const getWifiStatus = (): string => {
const wifiState = network.wifi.state?.toLowerCase();
if (wifiState && isValidWifiStatus(wifiState)) {
return WIFI_STATUS_MAP[wifiState];
}
return WIFI_STATUS_MAP["unknown"];
}
return WIFI_STATUS_MAP['unknown'];
};
self.hook(network, () => {
Utils.merge([staging.bind("value"), connecting.bind("value")], () => {
Utils.merge([staging.bind('value'), connecting.bind('value')], () => {
// NOTE: Sometimes the network service will yield a "this._device is undefined" when
// trying to access the "access_points" property. So we must validate that
// it's not 'undefined'
@@ -38,12 +43,10 @@ const renderWAPs = (self: any, network: Network, staging: Variable<AccessPoint>,
// Also this is an AGS bug that needs to be fixed
// TODO: Remove @ts-ignore once AGS bug is fixed
// @ts-ignore
let WAPs = network.wifi._device !== undefined
? network.wifi["access_points"]
: [];
// @ts-expect-error to fix AGS bug
let WAPs = network.wifi._device !== undefined ? network.wifi['access_points'] : [];
const dedupeWAPs = () => {
const dedupeWAPs = (): AccessPoint[] => {
const dedupMap: Record<string, AccessPoint> = {};
WAPs.forEach((item: AccessPoint) => {
if (item.ssid !== null && !Object.hasOwnProperty.call(dedupMap, item.ssid)) {
@@ -56,7 +59,7 @@ const renderWAPs = (self: any, network: Network, staging: Variable<AccessPoint>,
WAPs = dedupeWAPs();
const isInStaging = (wap: AccessPoint) => {
const isInStaging = (wap: AccessPoint): boolean => {
if (Object.keys(staging.value).length === 0) {
return false;
}
@@ -64,15 +67,15 @@ const renderWAPs = (self: any, network: Network, staging: Variable<AccessPoint>,
return wap.bssid === staging.value.bssid;
};
const isDisconnecting = (wap: AccessPoint) => {
const isDisconnecting = (wap: AccessPoint): boolean => {
if (wap.ssid === network.wifi.ssid) {
return network.wifi.state.toLowerCase() === "deactivating";
return network.wifi.state.toLowerCase() === 'deactivating';
}
return false;
};
const filteredWAPs = WAPs.filter((ap: AccessPoint) => {
return ap.ssid !== "Unknown" && !isInStaging(ap);
return ap.ssid !== 'Unknown' && !isInStaging(ap);
}).sort((a: AccessPoint, b: AccessPoint) => {
if (network.wifi.ssid === a.ssid) {
return -1;
@@ -87,11 +90,11 @@ const renderWAPs = (self: any, network: Network, staging: Variable<AccessPoint>,
if (filteredWAPs.length <= 0 && Object.keys(staging.value).length === 0) {
return (self.child = Widget.Label({
class_name: "waps-not-found dim",
class_name: 'waps-not-found dim',
expand: true,
hpack: "center",
vpack: "center",
label: "No Wi-Fi Networks Found",
hpack: 'center',
vpack: 'center',
label: 'No Wi-Fi Networks Found',
}));
}
return (self.children = filteredWAPs.map((ap: AccessPoint) => {
@@ -103,61 +106,57 @@ const renderWAPs = (self: any, network: Network, staging: Variable<AccessPoint>,
return;
}
connecting.value = ap.bssid || "";
connecting.value = ap.bssid || '';
Utils.execAsync(`nmcli device wifi connect ${ap.bssid}`)
.then(() => {
connecting.value = "";
connecting.value = '';
staging.value = {} as AccessPoint;
})
.catch((err) => {
if (
err
.toLowerCase()
.includes("secrets were required, but not provided")
) {
if (err.toLowerCase().includes('secrets were required, but not provided')) {
staging.value = ap;
} else {
Utils.notify({
summary: "Network",
summary: 'Network',
body: err,
timeout: 5000,
});
}
connecting.value = "";
connecting.value = '';
});
},
class_name: "network-element-item",
class_name: 'network-element-item',
child: Widget.Box({
hexpand: true,
children: [
Widget.Box({
hpack: "start",
hpack: 'start',
hexpand: true,
children: [
Widget.Label({
vpack: "start",
class_name: `network-icon wifi ${ap.ssid === network.wifi.ssid ? "active" : ""} txt-icon`,
label: getWifiIcon(`${ap["iconName"]}`),
vpack: 'start',
class_name: `network-icon wifi ${ap.ssid === network.wifi.ssid ? 'active' : ''} txt-icon`,
label: getWifiIcon(`${ap['iconName']}`),
}),
Widget.Box({
class_name: "connection-container",
vpack: "center",
class_name: 'connection-container',
vpack: 'center',
vertical: true,
children: [
Widget.Label({
vpack: "center",
class_name: "active-connection",
hpack: "start",
truncate: "end",
vpack: 'center',
class_name: 'active-connection',
hpack: 'start',
truncate: 'end',
wrap: true,
label: ap.ssid,
}),
Widget.Revealer({
revealChild: ap.ssid === network.wifi.ssid,
child: Widget.Label({
hpack: "start",
class_name: "connection-status dim",
label: getWifiStatus()
hpack: 'start',
class_name: 'connection-status dim',
label: getWifiStatus(),
}),
}),
],
@@ -165,48 +164,48 @@ const renderWAPs = (self: any, network: Network, staging: Variable<AccessPoint>,
],
}),
Widget.Revealer({
hpack: "end",
vpack: "start",
reveal_child:
ap.bssid === connecting.value || isDisconnecting(ap),
hpack: 'end',
vpack: 'start',
reveal_child: ap.bssid === connecting.value || isDisconnecting(ap),
child: Widget.Spinner({
vpack: "start",
class_name: "spinner wap",
vpack: 'start',
class_name: 'spinner wap',
}),
}),
],
}),
}),
Widget.Revealer({
vpack: "start",
vpack: 'start',
reveal_child: ap.bssid !== connecting.value && ap.active,
child: Widget.Button({
tooltip_text: "Delete/Forget Network",
class_name: "menu-icon-button network disconnect",
tooltip_text: 'Delete/Forget Network',
class_name: 'menu-icon-button network disconnect',
on_primary_click: () => {
connecting.value = ap.bssid || "";
Utils.execAsync("nmcli connection show --active").then(() => {
Utils.execAsync("nmcli connection show --active").then(
(res) => {
const connectionId = getIdBySsid(ap.ssid || "", res);
connecting.value = ap.bssid || '';
Utils.execAsync('nmcli connection show --active').then(() => {
Utils.execAsync('nmcli connection show --active').then((res) => {
const connectionId = getIdBySsid(ap.ssid || '', res);
Utils.execAsync(
`nmcli connection delete ${connectionId} "${ap.ssid}"`,
)
.then(() => (connecting.value = ""))
.catch((err) => {
connecting.value = "";
console.error(
`Error while forgetting "${ap.ssid}": ${err}`,
);
});
},
);
if (connectionId === undefined) {
console.error(
`Error while forgetting "${ap.ssid}": Connection ID not found`,
);
return;
}
Utils.execAsync(`nmcli connection delete ${connectionId} "${ap.ssid}"`)
.then(() => (connecting.value = ''))
.catch((err) => {
connecting.value = '';
console.error(`Error while forgetting "${ap.ssid}": ${err}`);
});
});
});
},
child: Widget.Label({
class_name: "txt-icon delete-network",
label: "󰚃",
class_name: 'txt-icon delete-network',
label: '󰚃',
}),
}),
}),

View File

@@ -1,64 +1,63 @@
const network = await Service.import("network");
import { renderWAPs } from "./WirelessAPs.js";
import { renderWapStaging } from "./APStaging.js";
import { AccessPoint } from "lib/types/network.js";
const network = await Service.import('network');
import { renderWAPs } from './WirelessAPs.js';
import { renderWapStaging } from './APStaging.js';
import { AccessPoint } from 'lib/types/network.js';
import { BoxWidget } from 'lib/types/widget.js';
const Staging = Variable({} as AccessPoint);
const Connecting = Variable("");
const Connecting = Variable('');
const searchInProgress = Variable(false);
const startRotation = () => {
const startRotation = (): void => {
searchInProgress.value = true;
setTimeout(() => {
searchInProgress.value = false;
}, 5 * 1000);
};
const Wifi = () => {
const Wifi = (): BoxWidget => {
return Widget.Box({
class_name: "menu-section-container wifi",
class_name: 'menu-section-container wifi',
vertical: true,
children: [
Widget.Box({
class_name: "menu-label-container",
hpack: "fill",
class_name: 'menu-label-container',
hpack: 'fill',
children: [
Widget.Label({
class_name: "menu-label",
class_name: 'menu-label',
hexpand: true,
hpack: "start",
label: "Wi-Fi",
hpack: 'start',
label: 'Wi-Fi',
}),
Widget.Button({
vpack: "center",
hpack: "end",
class_name: "menu-icon-button search network",
vpack: 'center',
hpack: 'end',
class_name: 'menu-icon-button search network',
on_primary_click: () => {
startRotation();
network.wifi.scan();
},
child: Widget.Icon({
class_name: searchInProgress
.bind("value")
.as((v) => (v ? "spinning" : "")),
icon: "view-refresh-symbolic",
class_name: searchInProgress.bind('value').as((v) => (v ? 'spinning' : '')),
icon: 'view-refresh-symbolic',
}),
}),
],
}),
Widget.Box({
class_name: "menu-items-section",
class_name: 'menu-items-section',
vertical: true,
children: [
Widget.Box({
class_name: "wap-staging",
class_name: 'wap-staging',
setup: (self) => {
renderWapStaging(self, network, Staging, Connecting);
},
}),
Widget.Box({
class_name: "available-waps",
class_name: 'available-waps',
vertical: true,
setup: (self) => {
renderWAPs(self, network, Staging, Connecting);