forked from Shinonome/dots-hyprland
wifi networks: hide network actions when not connected
This commit is contained in:
@@ -37,29 +37,29 @@ const WifiNetwork = (accessPoint) => {
|
|||||||
]
|
]
|
||||||
});
|
});
|
||||||
return Button({
|
return Button({
|
||||||
onClicked: accessPoint.active ? () => {} : () => {
|
onClicked: accessPoint.active ? () => { } : () => {
|
||||||
connectAttempt = accessPoint.ssid;
|
connectAttempt = accessPoint.ssid;
|
||||||
networkAuthSSID.label = `Connecting to: ${connectAttempt}`;
|
networkAuthSSID.label = `Connecting to: ${connectAttempt}`;
|
||||||
|
|
||||||
// Check if the SSID is stored
|
// Check if the SSID is stored
|
||||||
execAsync(['nmcli', '-g', 'NAME', 'connection', 'show'])
|
execAsync(['nmcli', '-g', 'NAME', 'connection', 'show'])
|
||||||
.then((savedConnections) => {
|
.then((savedConnections) => {
|
||||||
const savedSSIDs = savedConnections.split('\n');
|
const savedSSIDs = savedConnections.split('\n');
|
||||||
|
|
||||||
if (!savedSSIDs.includes(connectAttempt)) { // SSID not saved: show password input
|
if (!savedSSIDs.includes(connectAttempt)) { // SSID not saved: show password input
|
||||||
if (networkAuth) {
|
if (networkAuth) {
|
||||||
networkAuth.revealChild = true;
|
networkAuth.revealChild = true;
|
||||||
|
}
|
||||||
|
} else { // If SSID is saved, hide password input
|
||||||
|
if (networkAuth) {
|
||||||
|
networkAuth.revealChild = false;
|
||||||
|
}
|
||||||
|
// Connect
|
||||||
|
execAsync(['nmcli', 'device', 'wifi', 'connect', connectAttempt])
|
||||||
|
.catch(print);
|
||||||
}
|
}
|
||||||
} else { // If SSID is saved, hide password input
|
})
|
||||||
if (networkAuth) {
|
.catch(print);
|
||||||
networkAuth.revealChild = false;
|
|
||||||
}
|
|
||||||
// Connect
|
|
||||||
execAsync(['nmcli', 'device', 'wifi', 'connect', connectAttempt])
|
|
||||||
.catch(print);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(print);
|
|
||||||
|
|
||||||
},
|
},
|
||||||
child: Box({
|
child: Box({
|
||||||
@@ -185,7 +185,7 @@ const CurrentNetwork = () => {
|
|||||||
authLock = false;
|
authLock = false;
|
||||||
// Delete SSID connection before attempting to reconnect
|
// Delete SSID connection before attempting to reconnect
|
||||||
execAsync(['nmcli', 'connection', 'delete', connectAttempt])
|
execAsync(['nmcli', 'connection', 'delete', connectAttempt])
|
||||||
.catch(() => {}); // Ignore error if SSID not found
|
.catch(() => { }); // Ignore error if SSID not found
|
||||||
|
|
||||||
execAsync(['nmcli', 'device', 'wifi', 'connect', connectAttempt, 'password', self.text])
|
execAsync(['nmcli', 'device', 'wifi', 'connect', connectAttempt, 'password', self.text])
|
||||||
.then(() => {
|
.then(() => {
|
||||||
@@ -216,17 +216,14 @@ const CurrentNetwork = () => {
|
|||||||
|
|
||||||
if (activeSSID) {
|
if (activeSSID) {
|
||||||
execAsync(['nmcli', 'connection', 'delete', activeSSID])
|
execAsync(['nmcli', 'connection', 'delete', activeSSID])
|
||||||
.then(() => notify(`Forgot network: ${activeSSID}`))
|
.catch(err => Utils.notify(`Failed to forget network: ${err}`));
|
||||||
.catch(err => notify(`Failed to forget network: ${err}`));
|
|
||||||
} else {
|
|
||||||
notify('No active network to forget');
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(err => notify(`Error: ${err}`));
|
.catch(print);
|
||||||
},
|
},
|
||||||
setup: setupCursorHover,
|
setup: setupCursorHover,
|
||||||
});
|
});
|
||||||
const settingsButton = Button({
|
const propertiesButton = Button({
|
||||||
label: 'Properties',
|
label: 'Properties',
|
||||||
className: 'txt sidebar-wifinetworks-network-button',
|
className: 'txt sidebar-wifinetworks-network-button',
|
||||||
hexpand: true,
|
hexpand: true,
|
||||||
@@ -242,14 +239,22 @@ const CurrentNetwork = () => {
|
|||||||
},
|
},
|
||||||
setup: setupCursorHover,
|
setup: setupCursorHover,
|
||||||
});
|
});
|
||||||
const networkProp = Box({
|
const networkProp = Revealer({
|
||||||
className: 'spacing-h-10',
|
transition: 'slide_down',
|
||||||
homogeneous: true,
|
transitionDuration: userOptions.animations.durationLarge,
|
||||||
children: [
|
child: Box({
|
||||||
settingsButton,
|
className: 'spacing-h-10',
|
||||||
forgetButton,
|
homogeneous: true,
|
||||||
],
|
children: [
|
||||||
setup: setupCursorHover,
|
propertiesButton,
|
||||||
|
forgetButton,
|
||||||
|
],
|
||||||
|
setup: setupCursorHover,
|
||||||
|
}),
|
||||||
|
setup: (self) => self.hook(Network, (self) => {
|
||||||
|
if (Network.wifi?.ssid === '') self.revealChild = false;
|
||||||
|
else self.revealChild = true;
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
networkAuth = Revealer({
|
networkAuth = Revealer({
|
||||||
transition: 'slide_down',
|
transition: 'slide_down',
|
||||||
@@ -266,9 +271,9 @@ const CurrentNetwork = () => {
|
|||||||
setup: (self) => self.hook(Network, (self) => {
|
setup: (self) => self.hook(Network, (self) => {
|
||||||
execAsync(['nmcli', '-g', 'NAME', 'connection', 'show'])
|
execAsync(['nmcli', '-g', 'NAME', 'connection', 'show'])
|
||||||
.then((savedConnections) => {
|
.then((savedConnections) => {
|
||||||
const savedSSIDs = savedConnections.split('\n');
|
const savedSSIDs = savedConnections.split('\n');
|
||||||
if (Network.wifi.state == 'failed' ||
|
if (Network.wifi.state == 'failed' ||
|
||||||
(Network.wifi.state == 'need_auth' && !savedSSIDs.includes(Network.wifi.ssid))) {
|
(Network.wifi.state == 'need_auth' && !savedSSIDs.includes(Network.wifi.ssid))) {
|
||||||
authLock = true;
|
authLock = true;
|
||||||
connectAttempt = Network.wifi.ssid;
|
connectAttempt = Network.wifi.ssid;
|
||||||
self.revealChild = true;
|
self.revealChild = true;
|
||||||
@@ -283,7 +288,7 @@ const CurrentNetwork = () => {
|
|||||||
}, 20000); // 20 seconds timeout
|
}, 20000); // 20 seconds timeout
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
).catch(print);
|
).catch(print);
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
const actualContent = Box({
|
const actualContent = Box({
|
||||||
|
|||||||
Reference in New Issue
Block a user