forked from Shinonome/dots-hyprland
sidebar: wifi: auth
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
import Widget from 'resource:///com/github/Aylur/ags/widget.js';
|
import Widget from 'resource:///com/github/Aylur/ags/widget.js';
|
||||||
import Network from "resource:///com/github/Aylur/ags/service/network.js";
|
import Network from "resource:///com/github/Aylur/ags/service/network.js";
|
||||||
import * as Utils from 'resource:///com/github/Aylur/ags/utils.js';
|
import * as Utils from 'resource:///com/github/Aylur/ags/utils.js';
|
||||||
const { Box, Button, Icon, Label, Revealer, Scrollable, Slider, Stack } = Widget;
|
const { Box, Button, Entry, Icon, Label, Revealer, Scrollable, Slider, Stack } = Widget;
|
||||||
const { execAsync, exec } = Utils;
|
const { execAsync, exec } = Utils;
|
||||||
import { MaterialIcon } from '../../.commonwidgets/materialicon.js';
|
import { MaterialIcon } from '../../.commonwidgets/materialicon.js';
|
||||||
import { setupCursorHover } from '../../.widgetutils/cursorhover.js';
|
import { setupCursorHover } from '../../.widgetutils/cursorhover.js';
|
||||||
@@ -18,57 +18,172 @@ const MATERIAL_SYMBOL_SIGNAL_STRENGTH = {
|
|||||||
'network-wireless-signal-none-symbolic': "signal_wifi_0_bar",
|
'network-wireless-signal-none-symbolic': "signal_wifi_0_bar",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let connectAttempt = '';
|
||||||
|
|
||||||
const WifiNetwork = (accessPoint) => {
|
const WifiNetwork = (accessPoint) => {
|
||||||
console.log(accessPoint)
|
|
||||||
const networkStrength = MaterialIcon(MATERIAL_SYMBOL_SIGNAL_STRENGTH[accessPoint.iconName], 'hugerass')
|
const networkStrength = MaterialIcon(MATERIAL_SYMBOL_SIGNAL_STRENGTH[accessPoint.iconName], 'hugerass')
|
||||||
const connectedCheckmark = Revealer({
|
const networkName = Box({
|
||||||
transition: 'slide_left',
|
vertical: true,
|
||||||
transitionDuration: userOptions.animations.durationSmall,
|
children: [
|
||||||
revealChild: accessPoint.active,
|
Label({
|
||||||
child: MaterialIcon('check', 'large'),
|
hpack: 'start',
|
||||||
})
|
label: accessPoint.ssid
|
||||||
|
}),
|
||||||
|
accessPoint.active ? Label({
|
||||||
|
hpack: 'start',
|
||||||
|
className: 'txt-smaller txt-subtext',
|
||||||
|
label: "Selected",
|
||||||
|
}) : null,
|
||||||
|
]
|
||||||
|
});
|
||||||
return Button({
|
return Button({
|
||||||
onClicked: () => execAsync(`nmcli device wifi connect ${accessPoint.bssid}`).catch(e => {
|
onClicked: accessPoint.active ? () => { } : () => execAsync(`nmcli device wifi connect ${accessPoint.bssid}`).catch(e => {
|
||||||
Utils.notify({
|
Utils.notify({
|
||||||
summary: "Network",
|
summary: "Network",
|
||||||
body: e,
|
body: e,
|
||||||
actions: {
|
actions: { "Open network manager": () => execAsync("nm-connection-editor").catch(print) }
|
||||||
"Open network manager": () => execAsync("nm-connection-editor").catch(print)
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}).catch(e => console.error(e)),
|
}).catch(e => console.error(e)),
|
||||||
child: Box({
|
child: Box({
|
||||||
className: 'sidebar-wifinetworks-network spacing-h-10',
|
className: 'sidebar-wifinetworks-network spacing-h-10',
|
||||||
children: [
|
children: [
|
||||||
networkStrength,
|
networkStrength,
|
||||||
Label({ label: accessPoint.ssid }),
|
networkName,
|
||||||
Box({ hexpand: true }),
|
Box({ hexpand: true }),
|
||||||
connectedCheckmark,
|
accessPoint.active ? MaterialIcon('check', 'large') : null,
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
setup: setupCursorHover,
|
setup: accessPoint.active ? () => { } : setupCursorHover,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
const CurrentNetwork = () => {
|
||||||
|
let authLock = false;
|
||||||
|
// console.log(Network.wifi);
|
||||||
|
const bottomSeparator = Box({
|
||||||
|
className: 'separator-line',
|
||||||
|
});
|
||||||
|
const networkName = Box({
|
||||||
|
vertical: true,
|
||||||
|
hexpand: true,
|
||||||
|
children: [
|
||||||
|
Label({
|
||||||
|
hpack: 'start',
|
||||||
|
className: 'txt-smaller txt-subtext',
|
||||||
|
label: "Current network",
|
||||||
|
}),
|
||||||
|
Label({
|
||||||
|
hpack: 'start',
|
||||||
|
label: Network.wifi?.ssid,
|
||||||
|
setup: (self) => self.hook(Network, (self) => {
|
||||||
|
if (authLock) return;
|
||||||
|
self.label = Network.wifi?.ssid;
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
]
|
||||||
|
});
|
||||||
|
const networkStatus = Box({
|
||||||
|
children: [Label({
|
||||||
|
vpack: 'center',
|
||||||
|
className: 'txt-subtext',
|
||||||
|
setup: (self) => self.hook(Network, (self) => {
|
||||||
|
if (authLock) return;
|
||||||
|
self.label = Network.wifi.state;
|
||||||
|
}),
|
||||||
|
})]
|
||||||
|
})
|
||||||
|
const networkAuth = Revealer({
|
||||||
|
transition: 'slide_down',
|
||||||
|
transitionDuration: userOptions.animations.durationLarge,
|
||||||
|
child: Box({
|
||||||
|
className: 'margin-top-10 spacing-v-5',
|
||||||
|
vertical: true,
|
||||||
|
children: [
|
||||||
|
Label({
|
||||||
|
className: 'margin-left-5',
|
||||||
|
hpack: 'start',
|
||||||
|
label: "Authentication",
|
||||||
|
}),
|
||||||
|
Entry({
|
||||||
|
className: 'sidebar-wifinetworks-auth-entry',
|
||||||
|
visibility: false, // Password dots
|
||||||
|
onAccept: (self) => {
|
||||||
|
authLock = false;
|
||||||
|
networkAuth.revealChild = false;
|
||||||
|
execAsync(`nmcli device wifi connect '${connectAttempt}' password '${self.text}'`)
|
||||||
|
.catch(print);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
]
|
||||||
|
}),
|
||||||
|
setup: (self) => self.hook(Network, (self) => {
|
||||||
|
if (Network.wifi.state == 'failed' || Network.wifi.state == 'need_auth') {
|
||||||
|
authLock = true;
|
||||||
|
connectAttempt = Network.wifi.ssid;
|
||||||
|
self.revealChild = true;
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
const actualContent = Box({
|
||||||
|
vertical: true,
|
||||||
|
className: 'spacing-v-10',
|
||||||
|
children: [
|
||||||
|
Box({
|
||||||
|
className: 'sidebar-wifinetworks-network',
|
||||||
|
vertical: true,
|
||||||
|
children: [
|
||||||
|
Box({
|
||||||
|
className: 'spacing-h-10',
|
||||||
|
children: [
|
||||||
|
MaterialIcon('language', 'hugerass'),
|
||||||
|
networkName,
|
||||||
|
networkStatus,
|
||||||
|
|
||||||
|
]
|
||||||
|
}),
|
||||||
|
networkAuth,
|
||||||
|
]
|
||||||
|
}),
|
||||||
|
bottomSeparator,
|
||||||
|
]
|
||||||
|
});
|
||||||
|
return Box({
|
||||||
|
vertical: true,
|
||||||
|
children: [Revealer({
|
||||||
|
transition: 'slide_down',
|
||||||
|
transitionDuration: userOptions.animations.durationLarge,
|
||||||
|
revealChild: Network.wifi,
|
||||||
|
child: actualContent,
|
||||||
|
})]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export default (props) => {
|
export default (props) => {
|
||||||
const networkList = Scrollable({
|
const networkList = Box({
|
||||||
vexpand: true,
|
vertical: true,
|
||||||
child: Box({
|
className: 'spacing-v-10',
|
||||||
attribute: {
|
children: [
|
||||||
'updateNetworks': (self) => {
|
Scrollable({
|
||||||
self.children = Network.wifi?.access_points?.map(n => WifiNetwork(n));
|
vexpand: true,
|
||||||
},
|
child: Box({
|
||||||
},
|
attribute: {
|
||||||
vertical: true,
|
'updateNetworks': (self) => {
|
||||||
className: 'spacing-v-5',
|
self.children = Network.wifi?.access_points?.map(n => WifiNetwork(n));
|
||||||
setup: (self) => self.hook(Network, self.attribute.updateNetworks),
|
},
|
||||||
})
|
},
|
||||||
|
vertical: true,
|
||||||
|
className: 'spacing-v-5',
|
||||||
|
setup: (self) => self.hook(Network, self.attribute.updateNetworks),
|
||||||
|
})
|
||||||
|
})
|
||||||
|
]
|
||||||
})
|
})
|
||||||
return Box({
|
return Box({
|
||||||
...props,
|
...props,
|
||||||
className: 'spacing-v-5',
|
className: 'spacing-v-10',
|
||||||
vertical: true,
|
vertical: true,
|
||||||
children: [
|
children: [
|
||||||
|
CurrentNetwork(),
|
||||||
networkList,
|
networkList,
|
||||||
// mainContent,
|
// mainContent,
|
||||||
// status,
|
// status,
|
||||||
|
|||||||
@@ -327,7 +327,7 @@ $sidebar_chat_textboxareaColor: mix($onSurfaceVariant, $surfaceVariant, 40%);
|
|||||||
@include full-rounding;
|
@include full-rounding;
|
||||||
@include element_decel;
|
@include element_decel;
|
||||||
background-color: $layer2;
|
background-color: $layer2;
|
||||||
color: $onSurfaceVariant;
|
color: $onLayer2;
|
||||||
margin: 0.341rem;
|
margin: 0.341rem;
|
||||||
padding: 0.205rem 0.545rem;
|
padding: 0.205rem 0.545rem;
|
||||||
}
|
}
|
||||||
@@ -518,7 +518,7 @@ $colorpicker_rounding: 0.341rem;
|
|||||||
.sidebar-chat-textarea {
|
.sidebar-chat-textarea {
|
||||||
@include normal-rounding;
|
@include normal-rounding;
|
||||||
background-color: $layer1;
|
background-color: $layer1;
|
||||||
color: $onSurfaceVariant;
|
color: $onLayer1;
|
||||||
padding: 0.682rem;
|
padding: 0.682rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -917,7 +917,23 @@ $waifu_image_overlay_transparency: 0.7;
|
|||||||
color: $onLayer2;
|
color: $onLayer2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.sidebar-wifinetworks-network:hover,
|
||||||
|
.sidebar-wifinetworks-network:focus {
|
||||||
|
background-color: $layer2Hover;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-wifinetworks-network:active {
|
||||||
|
background-color: $layer2Active;
|
||||||
|
}
|
||||||
|
|
||||||
.sidebar-wifinetworks-signal {
|
.sidebar-wifinetworks-signal {
|
||||||
@include symbolic-icon;
|
@include symbolic-icon;
|
||||||
font-size: 2.045rem;
|
font-size: 2.045rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sidebar-wifinetworks-auth-entry {
|
||||||
|
@include small-rounding;
|
||||||
|
background-color: $layer1;
|
||||||
|
color: $onLayer1;
|
||||||
|
padding: 0.682rem;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user