Skip to content

Commit f7c7cb3

Browse files
committed
[Feature] VPN Configuration from end-4#614
but also make it toggleable
1 parent ba47289 commit f7c7cb3

File tree

5 files changed

+163
-1
lines changed

5 files changed

+163
-1
lines changed

.config/ags/modules/.commonwidgets/statusicons.js

+11
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,16 @@ const WeatherWidget = () =>
535535
}),
536536
});
537537

538+
const VPNIndicator = () => Widget.Revealer({
539+
child: MaterialIcon('lock', 'norm'),
540+
transition: 'slide_left',
541+
revealChild: false,
542+
transitionDuration: userOptions.animations.durationSmall,
543+
setup: (self) => self.hook(Network.vpn, (self) => {
544+
self.revealChild = (Network.vpn.activatedConnections.length > 0);
545+
})
546+
});
547+
538548
export const StatusIcons = (props = {}, monitor = 0) =>
539549
Widget.Box({
540550
...props,
@@ -552,6 +562,7 @@ export const StatusIcons = (props = {}, monitor = 0) =>
552562
...(userOptions.weather.enabled ? [WeatherWidget()] : []),
553563
Utilities(),
554564
BarGroup({ child: BarBattery() }),
565+
...(userOptions.bar.vpn ? [VPNIndicator()] : []),
555566
],
556567
}),
557568
});

.config/ags/modules/.configuration/user_options.js

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ let configOptions = {
4040
settings: 'XDG_CURRENT_DESKTOP="gnome" gnome-control-center',
4141
taskManager: "gnome-system-monitor",
4242
terminal: "foot", // This is only for shell actions
43+
'vpn': "XDG_CURRENT_DESKTOP=\"gnome\" gnome-control-center network",
4344
},
4445
battery: {
4546
low: 20,
@@ -208,6 +209,7 @@ let configOptions = {
208209
// Change Order to reorder, remove to hide
209210
// Options: "snip", "picker", "keyboard"
210211
utilities: ["picker"],
212+
vpn: false, // true to enable
211213
},
212214
keybinds: {
213215
// Format: Mod1+Mod2+key. CaSe SeNsItIvE!
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
import Widget from 'resource:///com/github/Aylur/ags/widget.js';
2+
import Network from "resource:///com/github/Aylur/ags/service/network.js";
3+
import * as Utils from 'resource:///com/github/Aylur/ags/utils.js';
4+
import { MaterialIcon } from '../../.commonwidgets/materialicon.js';
5+
import { ConfigToggle } from '../../.commonwidgets/configwidgets.js';
6+
import { setupCursorHover } from '../../.widgetutils/cursorhover.js';
7+
8+
const { execAsync } = Utils;
9+
const { Box, Button, Icon, Label, Scrollable, Stack } = Widget;
10+
11+
const USE_SYMBOLIC_ICONS = true;
12+
13+
const VPNConfig = (vpn) => {
14+
console.log(vpn.state);
15+
16+
const vpnIcon = Icon({
17+
vpack: 'center',
18+
className: 'sidebar-vpn-appicon',
19+
tooltipText: vpn.id,
20+
setup: (self) => self.hook(vpn, (self) => {
21+
self.icon = `${vpn.iconName}${USE_SYMBOLIC_ICONS ? '-symbolic' : ''}`;
22+
})
23+
});
24+
25+
const vpnName = Box({
26+
vpack: 'center',
27+
hexpand: true,
28+
vertical: true,
29+
children: [
30+
Label({
31+
setup: (self) => self.hook(vpn, (self) => {
32+
self.label = vpn.id;
33+
}),
34+
label: vpn.id,
35+
xalign: 0,
36+
truncate: 'end',
37+
className: 'txt-small',
38+
maxWidthChars: 1,
39+
})
40+
]
41+
});
42+
43+
const vpnConnectButton = ConfigToggle({
44+
desc: 'Toggle connection',
45+
vpack: 'center',
46+
initValue: (vpn.state === 'connected'),
47+
expandWidget: false,
48+
onChange: (self, newValue) => {
49+
vpn.setConnection(newValue);
50+
},
51+
extraSetup: (self) => self.hook(vpn, (self) => {
52+
Utils.timeout(200, () => self.enabled.value = (vpn.state === 'connected'));
53+
})
54+
});
55+
56+
return Box({
57+
className: 'spacing-h-10 sidebar-vpn-config',
58+
children: [
59+
vpnIcon,
60+
vpnName,
61+
Box({
62+
className: 'spacing-h-5',
63+
children: [
64+
vpnConnectButton,
65+
]
66+
})
67+
]
68+
});
69+
}
70+
71+
export default (props) => {
72+
const emptyContent = Box({
73+
homogeneous: true,
74+
children: [
75+
Box({
76+
vpack: "center",
77+
vertical: true,
78+
className: 'txt spacing-v-10',
79+
children: [
80+
Box({
81+
vertical: true,
82+
className: 'spacing-v-5 txt-subtext',
83+
children: [
84+
MaterialIcon('vpn_key_off', 'gigantic'),
85+
Label({ label: 'No VPN configured', className: 'txt-small' })
86+
]
87+
})
88+
]
89+
})
90+
]
91+
});
92+
93+
const vpnList = Scrollable({
94+
vexpand: true,
95+
child: Box({
96+
vertical: true,
97+
className: 'spacing-v-5',
98+
attribute: {
99+
'updateVPNList': (self) => {
100+
self.children = Network.vpn.connections.map(vpn => VPNConfig(vpn));
101+
}
102+
},
103+
setup: (self) => self
104+
.hook(Network.vpn, self.attribute.updateVPNList, 'connection-added')
105+
.hook(Network.vpn, self.attribute.updateVPNList, 'connection-removed')
106+
})
107+
});
108+
109+
const mainContent = Stack({
110+
children: {
111+
'list': vpnList,
112+
'empty': emptyContent,
113+
},
114+
setup: (self) => self.hook(Network, (self) => {
115+
self.shown = (Network.vpn.connections.length > 0 ? 'list' : 'empty');
116+
})
117+
});
118+
119+
const bottomBar = Box({
120+
homogeneous: true,
121+
children: [
122+
Button({
123+
label: 'More',
124+
hpack: 'center',
125+
setup: setupCursorHover,
126+
className: 'txt-small txt sidebar-centermodules-bottombar-button',
127+
onClicked: () => {
128+
execAsync(['bash', '-c', `${userOptions.apps.vpn}`, '&']);
129+
closeEverything();
130+
},
131+
})
132+
]
133+
});
134+
135+
return Box({
136+
...props,
137+
vertical: true,
138+
className: 'spacing-v-5',
139+
children: [
140+
mainContent,
141+
bottomBar
142+
],
143+
});
144+
}

.config/ags/modules/sideright/sideright.js

+6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { getDistroIcon } from '../.miscutils/system.js';
2626
import { MaterialIcon } from '../.commonwidgets/materialicon.js';
2727
import { ExpandingIconTabContainer } from '../.commonwidgets/tabcontainer.js';
2828
import { checkKeybind } from '../.widgetutils/keybind.js';
29+
import ModuleVPN from "./centermodules/vpn.js";
2930

3031
const centerWidgets = [
3132
{
@@ -54,6 +55,11 @@ const centerWidgets = [
5455
materialIcon: 'tune',
5556
contentWidget: ModuleConfigure,
5657
},
58+
...(userOptions.bar.vpn ? [{
59+
name: "VPN",
60+
materialIcon: 'lock',
61+
contentWidget: ModuleVPN,
62+
}] : []),
5763
];
5864

5965
const timeRow = Box({

.config/hypr/hyprland/rules.conf

-1
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,3 @@ layerrule = blur, indicator*
7676
layerrule = ignorealpha 0.6, indicator*
7777
layerrule = blur, osk
7878
layerrule = ignorealpha 0.6, osk
79-

0 commit comments

Comments
 (0)