💥 fix(control-center/tiles): couldn't enable network after disabling
now it's fixed!
This commit is contained in:
@@ -11,7 +11,7 @@ import { Notifications } from "../../../../modules/notifications";
|
|||||||
|
|
||||||
|
|
||||||
const { WIFI, WIRED } = AstalNetwork.Primary,
|
const { WIFI, WIRED } = AstalNetwork.Primary,
|
||||||
{ CONNECTED, CONNECTING } = AstalNetwork.Internet;
|
{ CONNECTED, CONNECTING, DISCONNECTED } = AstalNetwork.Internet;
|
||||||
|
|
||||||
const wiredInternet = secureBaseBinding<AstalNetwork.Wired>(
|
const wiredInternet = secureBaseBinding<AstalNetwork.Wired>(
|
||||||
createBinding(AstalNetwork.get_default(), "wired"),
|
createBinding(AstalNetwork.get_default(), "wired"),
|
||||||
@@ -115,28 +115,30 @@ export const TileNetwork = () =>
|
|||||||
return tr("disconnected");
|
return tr("disconnected");
|
||||||
})}
|
})}
|
||||||
onToggled={(self, state) => {
|
onToggled={(self, state) => {
|
||||||
|
const wifi = AstalNetwork.get_default().wifi,
|
||||||
|
wired = AstalNetwork.get_default().wired;
|
||||||
|
|
||||||
switch(AstalNetwork.get_default().primary) {
|
switch(AstalNetwork.get_default().primary) {
|
||||||
case WIFI:
|
case WIFI:
|
||||||
AstalNetwork.get_default().wifi.set_enabled(state);
|
wifi.set_enabled(state);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case WIRED:
|
case WIRED:
|
||||||
(state ?
|
setNetworking(state);
|
||||||
execAsync("nmcli n off")
|
|
||||||
: execAsync("nmcli n on")
|
|
||||||
).catch(e => {
|
|
||||||
Notifications.getDefault().sendNotification({
|
|
||||||
appName: "network",
|
|
||||||
summary: "Couldn't turn off network",
|
|
||||||
body: `Turning off networking with nmcli failed: ${
|
|
||||||
e?.message ?? "(no error message)"}`
|
|
||||||
});
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(wired && wired.internet === DISCONNECTED) {
|
||||||
|
setNetworking(true);
|
||||||
|
return;
|
||||||
|
} else if(wifi && !wifi.enabled) {
|
||||||
|
wifi.set_enabled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("no network device available to enable...");
|
||||||
|
|
||||||
// disable if no device available
|
// disable if no device available
|
||||||
if(!AstalNetwork.get_default().wired && !AstalNetwork.get_default().wifi)
|
|
||||||
self.state = false;
|
self.state = false;
|
||||||
}}
|
}}
|
||||||
/>;
|
/>;
|
||||||
@@ -152,3 +154,17 @@ function internetToTranslatedString(internet: AstalNetwork.Internet): string {
|
|||||||
|
|
||||||
return tr("disconnected");
|
return tr("disconnected");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setNetworking(state: boolean): void {
|
||||||
|
(!state ?
|
||||||
|
execAsync("nmcli n off")
|
||||||
|
: execAsync("nmcli n on")
|
||||||
|
).catch(e => {
|
||||||
|
Notifications.getDefault().sendNotification({
|
||||||
|
appName: "network",
|
||||||
|
summary: "Couldn't turn off network",
|
||||||
|
body: `Turning off networking with nmcli failed${
|
||||||
|
e?.message !== undefined ? `: ${e?.message}` : ""}`
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user