2023-11-21 01:29:46 -05:00
|
|
|
import App from 'resource:///com/github/Aylur/ags/app.js';
|
2023-10-31 08:32:40 -04:00
|
|
|
import Bluetooth from 'resource:///com/github/Aylur/ags/service/bluetooth.js';
|
2023-11-21 01:29:46 -05:00
|
|
|
import Network from 'resource:///com/github/Aylur/ags/service/network.js';
|
|
|
|
import Variable from 'resource:///com/github/Aylur/ags/variable.js';
|
|
|
|
|
2023-11-09 02:19:18 -05:00
|
|
|
import { Box, Icon, Label, Revealer } from 'resource:///com/github/Aylur/ags/widget.js';
|
2023-10-31 08:32:40 -04:00
|
|
|
import { execAsync } from 'resource:///com/github/Aylur/ags/utils.js';
|
2023-09-12 14:22:21 -04:00
|
|
|
|
2023-11-13 16:19:09 -05:00
|
|
|
import { SpeakerIcon, MicIcon } from '../misc/audio-icons.js';
|
2023-11-21 01:29:46 -05:00
|
|
|
import EventBox from '../misc/cursorbox.js';
|
2023-11-09 02:19:18 -05:00
|
|
|
import Separator from '../misc/separator.js';
|
2023-09-12 14:22:21 -04:00
|
|
|
|
2023-12-04 15:39:12 -05:00
|
|
|
import { NetworkMenu } from './network.js';
|
2023-12-05 11:35:40 -05:00
|
|
|
import { BluetoothMenu } from './bluetooth.js';
|
2023-12-04 15:39:12 -05:00
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
const SPACING = 28;
|
|
|
|
|
2023-10-02 12:06:35 -04:00
|
|
|
|
2023-11-09 02:19:18 -05:00
|
|
|
const ButtonStates = [];
|
2023-10-17 13:47:02 -04:00
|
|
|
const GridButton = ({
|
2023-11-21 01:29:46 -05:00
|
|
|
command = () => { /**/ },
|
|
|
|
secondaryCommand = () => { /**/ },
|
2023-12-05 11:35:40 -05:00
|
|
|
onOpen = () => { /**/ },
|
2023-10-20 23:11:21 -04:00
|
|
|
icon,
|
2023-11-09 02:19:18 -05:00
|
|
|
indicator,
|
|
|
|
menu,
|
|
|
|
} = {}) => {
|
|
|
|
const Activated = Variable(false);
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-11-09 02:19:18 -05:00
|
|
|
ButtonStates.push(Activated);
|
2023-10-20 23:11:21 -04:00
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
// Allow setting icon dynamically or statically
|
2023-11-09 02:19:18 -05:00
|
|
|
if (typeof icon === 'string') {
|
|
|
|
icon = Icon({
|
|
|
|
className: 'grid-label',
|
2023-11-21 01:29:46 -05:00
|
|
|
icon,
|
|
|
|
connections: [[Activated, (self) => {
|
|
|
|
self.setCss(`color: ${Activated.value ?
|
|
|
|
'rgba(189, 147, 249, 0.8)' :
|
|
|
|
'unset'};`);
|
2023-11-09 02:19:18 -05:00
|
|
|
}]],
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
icon = Icon({
|
|
|
|
className: 'grid-label',
|
|
|
|
connections: [
|
|
|
|
icon,
|
2023-11-21 01:29:46 -05:00
|
|
|
[Activated, (self) => {
|
|
|
|
self.setCss(`color: ${Activated.value ?
|
|
|
|
'rgba(189, 147, 249, 0.8)' :
|
|
|
|
'unset'};`);
|
2023-11-09 02:19:18 -05:00
|
|
|
}],
|
|
|
|
],
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (indicator) {
|
|
|
|
indicator = Label({
|
|
|
|
className: 'sub-label',
|
|
|
|
justification: 'left',
|
|
|
|
truncate: 'end',
|
|
|
|
maxWidthChars: 12,
|
|
|
|
connections: [indicator],
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (menu) {
|
|
|
|
menu = Revealer({
|
|
|
|
transition: 'slide_down',
|
|
|
|
child: menu,
|
|
|
|
binds: [['revealChild', Activated, 'value']],
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
const widget = Box({
|
|
|
|
vertical: true,
|
|
|
|
children: [
|
|
|
|
Box({
|
|
|
|
className: 'grid-button',
|
|
|
|
children: [
|
2023-10-20 23:11:21 -04:00
|
|
|
|
2023-11-09 02:19:18 -05:00
|
|
|
EventBox({
|
|
|
|
className: 'left-part',
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-11-09 02:19:18 -05:00
|
|
|
onPrimaryClickRelease: () => {
|
2023-11-21 01:29:46 -05:00
|
|
|
if (Activated.value) {
|
2023-11-09 02:19:18 -05:00
|
|
|
secondaryCommand();
|
2023-11-21 01:29:46 -05:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
command();
|
|
|
|
}
|
2023-11-09 02:19:18 -05:00
|
|
|
},
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-11-09 02:19:18 -05:00
|
|
|
child: icon,
|
|
|
|
}),
|
|
|
|
|
|
|
|
EventBox({
|
|
|
|
className: 'right-part',
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-11-09 02:19:18 -05:00
|
|
|
onPrimaryClickRelease: () => {
|
2023-11-21 01:29:46 -05:00
|
|
|
ButtonStates.forEach((state) => {
|
|
|
|
if (state !== Activated) {
|
2023-11-09 02:19:18 -05:00
|
|
|
state.value = false;
|
2023-11-21 01:29:46 -05:00
|
|
|
}
|
2023-11-09 02:19:18 -05:00
|
|
|
});
|
|
|
|
Activated.value = !Activated.value;
|
|
|
|
},
|
2023-11-21 01:29:46 -05:00
|
|
|
|
|
|
|
onHover: (self) => {
|
2023-11-09 02:19:18 -05:00
|
|
|
if (menu) {
|
|
|
|
const rowMenu = self.get_parent().get_parent()
|
|
|
|
.get_parent().get_parent().children[1];
|
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
const isSetup = rowMenu.get_children()
|
|
|
|
.find((ch) => ch === menu);
|
|
|
|
|
|
|
|
if (!isSetup) {
|
2023-11-09 02:19:18 -05:00
|
|
|
rowMenu.add(menu);
|
|
|
|
rowMenu.show_all();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-11-09 02:19:18 -05:00
|
|
|
child: Icon({
|
2023-11-21 01:29:46 -05:00
|
|
|
icon: `${App.configDir }/icons/down-large.svg`,
|
|
|
|
className: 'grid-chev',
|
|
|
|
|
|
|
|
connections: [[Activated, (self) => {
|
2023-11-09 02:19:18 -05:00
|
|
|
let deg = 270;
|
2023-11-21 01:29:46 -05:00
|
|
|
|
|
|
|
if (Activated.value) {
|
2023-11-09 02:19:18 -05:00
|
|
|
deg = menu ? 360 : 450;
|
2023-12-05 11:35:40 -05:00
|
|
|
onOpen(menu);
|
2023-11-21 01:29:46 -05:00
|
|
|
}
|
|
|
|
self.setCss(`
|
|
|
|
-gtk-icon-transform: rotate(${deg}deg);
|
|
|
|
`);
|
2023-11-09 02:19:18 -05:00
|
|
|
}]],
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
|
|
|
|
],
|
2023-10-20 23:11:21 -04:00
|
|
|
}),
|
2023-11-09 02:19:18 -05:00
|
|
|
indicator,
|
|
|
|
],
|
|
|
|
});
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-11-09 02:19:18 -05:00
|
|
|
return widget;
|
|
|
|
};
|
2023-10-20 23:11:21 -04:00
|
|
|
|
2023-11-09 02:19:18 -05:00
|
|
|
const Row = ({ buttons } = {}) => {
|
|
|
|
const widget = Box({
|
|
|
|
vertical: true,
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-11-09 02:19:18 -05:00
|
|
|
children: [
|
|
|
|
Box({
|
|
|
|
className: 'button-row',
|
|
|
|
hpack: 'center',
|
|
|
|
}),
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-12-05 11:35:40 -05:00
|
|
|
Box({ vertical: true }),
|
2023-11-09 02:19:18 -05:00
|
|
|
],
|
|
|
|
});
|
2023-09-12 14:22:21 -04:00
|
|
|
|
2023-11-09 02:19:18 -05:00
|
|
|
for (let i = 0; i < buttons.length; ++i) {
|
2023-11-21 01:29:46 -05:00
|
|
|
if (i === buttons.length - 1) {
|
2023-11-09 02:19:18 -05:00
|
|
|
widget.children[0].add(buttons[i]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
widget.children[0].add(buttons[i]);
|
2023-11-21 01:29:46 -05:00
|
|
|
widget.children[0].add(Separator(SPACING));
|
2023-11-09 02:19:18 -05:00
|
|
|
}
|
|
|
|
}
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-11-09 02:19:18 -05:00
|
|
|
return widget;
|
|
|
|
};
|
|
|
|
|
|
|
|
const FirstRow = () => Row({
|
|
|
|
buttons: [
|
2023-10-20 23:11:21 -04:00
|
|
|
|
|
|
|
GridButton({
|
|
|
|
command: () => Network.toggleWifi(),
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
secondaryCommand: () => {
|
2023-12-05 11:35:40 -05:00
|
|
|
// TODO: connection editor
|
2023-10-20 23:11:21 -04:00
|
|
|
},
|
2023-11-21 01:29:46 -05:00
|
|
|
|
|
|
|
icon: [Network, (icon) => {
|
|
|
|
icon.icon = Network.wifi?.iconName;
|
|
|
|
}],
|
|
|
|
|
|
|
|
indicator: [Network, (self) => {
|
|
|
|
self.label = Network.wifi?.ssid || Network.wired?.internet;
|
|
|
|
}],
|
2023-11-09 02:19:18 -05:00
|
|
|
|
2023-12-04 15:39:12 -05:00
|
|
|
menu: NetworkMenu(),
|
2023-12-05 11:35:40 -05:00
|
|
|
onOpen: () => Network.wifi.scan(),
|
2023-10-20 23:11:21 -04:00
|
|
|
}),
|
|
|
|
|
2023-12-05 11:35:40 -05:00
|
|
|
// TODO: do vpn
|
2023-10-20 23:11:21 -04:00
|
|
|
GridButton({
|
|
|
|
command: () => {
|
2023-12-05 11:35:40 -05:00
|
|
|
//
|
2023-10-20 23:11:21 -04:00
|
|
|
},
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
secondaryCommand: () => {
|
2023-12-05 11:35:40 -05:00
|
|
|
//
|
2023-10-20 23:11:21 -04:00
|
|
|
},
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-12-05 11:35:40 -05:00
|
|
|
icon: 'airplane-mode-disabled-symbolic',
|
2023-10-20 23:11:21 -04:00
|
|
|
}),
|
|
|
|
|
|
|
|
GridButton({
|
2023-12-05 11:35:40 -05:00
|
|
|
command: () => Bluetooth.toggle(),
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
secondaryCommand: () => {
|
2023-12-05 11:35:40 -05:00
|
|
|
// TODO: bluetooth connection editor
|
2023-10-20 23:11:21 -04:00
|
|
|
},
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-12-05 11:35:40 -05:00
|
|
|
icon: [Bluetooth, (self) => {
|
|
|
|
if (Bluetooth.enabled) {
|
|
|
|
self.icon = Bluetooth.connectedDevices[0] ?
|
|
|
|
Bluetooth.connectedDevices[0].iconName :
|
|
|
|
'bluetooth-active-symbolic';
|
2023-11-21 01:29:46 -05:00
|
|
|
}
|
|
|
|
else {
|
2023-12-05 11:35:40 -05:00
|
|
|
self.icon = 'bluetooth-disabled-symbolic';
|
2023-11-21 01:29:46 -05:00
|
|
|
}
|
2023-12-05 11:35:40 -05:00
|
|
|
}],
|
|
|
|
|
|
|
|
indicator: [Bluetooth, (self) => {
|
|
|
|
self.label = Bluetooth.connectedDevices[0] ?
|
|
|
|
`${Bluetooth.connectedDevices[0]}` :
|
|
|
|
'Disconnected';
|
|
|
|
}, 'notify::connected-devices'],
|
|
|
|
|
|
|
|
menu: BluetoothMenu(),
|
|
|
|
onOpen: (menu) => {
|
|
|
|
execAsync(`bluetoothctl scan ${menu.revealChild ?
|
|
|
|
'on' :
|
|
|
|
'off'}`);
|
|
|
|
},
|
2023-10-20 23:11:21 -04:00
|
|
|
}),
|
|
|
|
|
|
|
|
],
|
2023-09-12 14:22:21 -04:00
|
|
|
});
|
|
|
|
|
2023-11-09 02:19:18 -05:00
|
|
|
const SecondRow = () => Row({
|
|
|
|
buttons: [
|
2023-10-20 23:11:21 -04:00
|
|
|
GridButton({
|
|
|
|
command: () => {
|
2023-11-21 01:29:46 -05:00
|
|
|
execAsync(['pactl', 'set-sink-mute',
|
|
|
|
'@DEFAULT_SINK@', 'toggle']).catch(print);
|
2023-10-20 23:11:21 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
secondaryCommand: () => {
|
|
|
|
execAsync(['bash', '-c', 'pavucontrol'])
|
|
|
|
.catch(print);
|
|
|
|
},
|
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
icon: [SpeakerIcon, (self) => {
|
2023-11-13 16:19:09 -05:00
|
|
|
self.icon = SpeakerIcon.value;
|
|
|
|
}],
|
2023-10-20 23:11:21 -04:00
|
|
|
}),
|
|
|
|
|
|
|
|
GridButton({
|
|
|
|
command: () => {
|
2023-11-21 01:29:46 -05:00
|
|
|
execAsync(['pactl', 'set-source-mute',
|
|
|
|
'@DEFAULT_SOURCE@', 'toggle']).catch(print);
|
2023-10-20 23:11:21 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
secondaryCommand: () => {
|
|
|
|
execAsync(['bash', '-c', 'pavucontrol'])
|
|
|
|
.catch(print);
|
|
|
|
},
|
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
icon: [MicIcon, (self) => {
|
2023-11-13 16:19:09 -05:00
|
|
|
self.icon = MicIcon.value;
|
|
|
|
}],
|
2023-10-20 23:11:21 -04:00
|
|
|
}),
|
|
|
|
|
|
|
|
GridButton({
|
|
|
|
command: () => {
|
2023-12-06 15:04:52 -05:00
|
|
|
execAsync(['lock']).catch(print);
|
2023-10-20 23:11:21 -04:00
|
|
|
},
|
|
|
|
secondaryCommand: () => App.openWindow('powermenu'),
|
2023-11-09 02:19:18 -05:00
|
|
|
icon: 'system-lock-screen-symbolic',
|
2023-10-20 23:11:21 -04:00
|
|
|
}),
|
|
|
|
],
|
2023-09-12 14:22:21 -04:00
|
|
|
});
|
|
|
|
|
2023-10-17 13:47:02 -04:00
|
|
|
export default () => Box({
|
2023-10-20 23:11:21 -04:00
|
|
|
className: 'button-grid',
|
|
|
|
vertical: true,
|
2023-11-06 18:37:23 -05:00
|
|
|
hpack: 'center',
|
2023-10-20 23:11:21 -04:00
|
|
|
children: [
|
|
|
|
FirstRow(),
|
2023-11-09 02:19:18 -05:00
|
|
|
Separator(10, { vertical: true }),
|
2023-10-20 23:11:21 -04:00
|
|
|
SecondRow(),
|
|
|
|
],
|
2023-09-12 14:22:21 -04:00
|
|
|
});
|