Fix network menu to remove duplicate ssids
This commit is contained in:
@@ -30,8 +30,24 @@ const renderWAPs = (self, network, staging, connecting) => {
|
|||||||
[network.bind("wifi"), staging.bind("value"), connecting.bind("value")],
|
[network.bind("wifi"), staging.bind("value"), connecting.bind("value")],
|
||||||
() => {
|
() => {
|
||||||
// Sometimes the network service will yield a "this._device is undefined" when
|
// Sometimes the network service will yield a "this._device is undefined" when
|
||||||
// trying to access the "access_points" property. So we must check if it exists.
|
// trying to access the "access_points" property. So we must validate that
|
||||||
const WAPs = Object.hasOwnProperty.call(network.wifi, "access_points") ? network.wifi.access_points : [];
|
// it's not 'undefined'
|
||||||
|
let WAPs = network.wifi["access_points"] !== undefined
|
||||||
|
? network.wifi["access-points"]
|
||||||
|
: [];
|
||||||
|
|
||||||
|
const dedupeWAPs = () => {
|
||||||
|
const dedupMap = {};
|
||||||
|
WAPs.forEach((item) => {
|
||||||
|
if (!Object.hasOwnProperty.call(dedupMap, item.ssid)) {
|
||||||
|
dedupMap[item.ssid] = item;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return Object.keys(dedupMap).map(itm => dedupMap[itm]);
|
||||||
|
}
|
||||||
|
|
||||||
|
WAPs = dedupeWAPs();
|
||||||
|
|
||||||
const isInStaging = (wap) => {
|
const isInStaging = (wap) => {
|
||||||
if (Object.keys(staging.value).length === 0) {
|
if (Object.keys(staging.value).length === 0) {
|
||||||
@@ -49,7 +65,9 @@ const renderWAPs = (self, network, staging, connecting) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const filteredWAPs = WAPs.filter(
|
const filteredWAPs = WAPs.filter(
|
||||||
(ap) => ap.ssid !== "Unknown" && !isInStaging(ap),
|
(ap) => {
|
||||||
|
return ap.ssid !== "Unknown" && !isInStaging(ap)
|
||||||
|
},
|
||||||
).sort((a, b) => {
|
).sort((a, b) => {
|
||||||
if (network.wifi.ssid === a.ssid) {
|
if (network.wifi.ssid === a.ssid) {
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
@@ -5,6 +5,15 @@ import { renderWapStaging } from "./APStaging.js";
|
|||||||
const Staging = Variable({});
|
const Staging = Variable({});
|
||||||
const Connecting = Variable("");
|
const Connecting = Variable("");
|
||||||
|
|
||||||
|
const searchInProgress = Variable(false);
|
||||||
|
|
||||||
|
const startRotation = () => {
|
||||||
|
searchInProgress.value = true;
|
||||||
|
setTimeout(() => {
|
||||||
|
searchInProgress.value = false;
|
||||||
|
}, 5 * 1000);
|
||||||
|
};
|
||||||
|
|
||||||
const Wifi = () => {
|
const Wifi = () => {
|
||||||
return Widget.Box({
|
return Widget.Box({
|
||||||
class_name: "menu-section-container wifi",
|
class_name: "menu-section-container wifi",
|
||||||
@@ -13,12 +22,29 @@ const Wifi = () => {
|
|||||||
Widget.Box({
|
Widget.Box({
|
||||||
class_name: "menu-label-container",
|
class_name: "menu-label-container",
|
||||||
hpack: "fill",
|
hpack: "fill",
|
||||||
child: Widget.Label({
|
children: [
|
||||||
|
Widget.Label({
|
||||||
class_name: "menu-label",
|
class_name: "menu-label",
|
||||||
hexpand: true,
|
hexpand: true,
|
||||||
hpack: "start",
|
hpack: "start",
|
||||||
label: "Wi-Fi",
|
label: "Wi-Fi",
|
||||||
}),
|
}),
|
||||||
|
Widget.Button({
|
||||||
|
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",
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
],
|
||||||
}),
|
}),
|
||||||
Widget.Box({
|
Widget.Box({
|
||||||
class_name: "menu-items-section",
|
class_name: "menu-items-section",
|
||||||
|
|||||||
@@ -25,16 +25,6 @@
|
|||||||
button {
|
button {
|
||||||
margin-right: 0.5em;
|
margin-right: 0.5em;
|
||||||
&.search {
|
&.search {
|
||||||
@keyframes spin {
|
|
||||||
to { -gtk-icon-transform: rotate(1turn); }
|
|
||||||
}
|
|
||||||
|
|
||||||
image.spinning {
|
|
||||||
animation-name: spin;
|
|
||||||
animation-duration: 1s;
|
|
||||||
animation-timing-function: linear;
|
|
||||||
animation-iteration-count: infinite;
|
|
||||||
}
|
|
||||||
image {
|
image {
|
||||||
color: $text;
|
color: $text;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,13 +94,13 @@ tooltip label {
|
|||||||
background: $crust;
|
background: $crust;
|
||||||
border: .13em solid $surface0;
|
border: .13em solid $surface0;
|
||||||
border-radius: .7rem;
|
border-radius: .7rem;
|
||||||
min-width: 400px;
|
min-width: 275px;
|
||||||
color: $text;
|
color: $text;
|
||||||
}
|
}
|
||||||
|
|
||||||
.menu-items-container {
|
.menu-items-container {
|
||||||
border-radius: 0.4em;
|
border-radius: 0.4em;
|
||||||
min-width: 400px;
|
min-width: 275px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.menu-section-container {
|
.menu-section-container {
|
||||||
@@ -252,3 +252,14 @@ tooltip label {
|
|||||||
min-height: 0em;
|
min-height: 0em;
|
||||||
margin-top: 2.8em;
|
margin-top: 2.8em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@keyframes spin {
|
||||||
|
to { -gtk-icon-transform: rotate(1turn); }
|
||||||
|
}
|
||||||
|
|
||||||
|
image.spinning {
|
||||||
|
animation-name: spin;
|
||||||
|
animation-duration: 1s;
|
||||||
|
animation-timing-function: linear;
|
||||||
|
animation-iteration-count: infinite;
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,6 +9,14 @@
|
|||||||
color: $mauve;
|
color: $mauve;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.menu-icon-button.network {
|
||||||
|
margin: 1em;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
color: $mauve;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.network-icon {
|
.network-icon {
|
||||||
font-size: 1.3em;
|
font-size: 1.3em;
|
||||||
min-width: 1em;
|
min-width: 1em;
|
||||||
|
|||||||
Reference in New Issue
Block a user