2023-10-02 12:06:35 -04:00
|
|
|
import { Network, Bluetooth, Audio, App, Utils, Widget } from '../../imports.js';
|
|
|
|
const { Box, CenterBox, Label, Icon } = Widget;
|
|
|
|
const { execAsync } = Utils;
|
|
|
|
const { openWindow } = App;
|
2023-09-12 14:22:21 -04:00
|
|
|
|
|
|
|
import { EventBox } from '../misc/cursorbox.js';
|
|
|
|
|
2023-10-02 12:06:35 -04:00
|
|
|
|
2023-09-12 14:22:21 -04:00
|
|
|
const GridButton = ({ command = () => {}, secondaryCommand = () => {}, icon } = {}) => Box({
|
|
|
|
className: 'grid-button',
|
|
|
|
children: [
|
|
|
|
|
|
|
|
EventBox({
|
|
|
|
className: 'left-part',
|
|
|
|
onPrimaryClickRelease: () => command(),
|
|
|
|
child: icon,
|
|
|
|
}),
|
|
|
|
|
|
|
|
EventBox({
|
|
|
|
className: 'right-part',
|
|
|
|
onPrimaryClickRelease: () => secondaryCommand(),
|
|
|
|
child: Label({
|
|
|
|
label: " ",
|
|
|
|
className: 'grid-chev',
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
const FirstRow = Box({
|
|
|
|
className: 'button-row',
|
|
|
|
halign: 'center',
|
|
|
|
style: 'margin-top: 15px; margin-bottom: 7px;',
|
|
|
|
children: [
|
|
|
|
|
|
|
|
GridButton({
|
|
|
|
command: () => Network.toggleWifi(),
|
2023-09-26 11:46:03 -04:00
|
|
|
secondaryCommand: () => execAsync(['bash', '-c', 'nm-connection-editor']).catch(print),
|
2023-09-12 14:22:21 -04:00
|
|
|
icon: Icon({
|
|
|
|
className: 'grid-label',
|
|
|
|
connections: [[Network, icon => {
|
|
|
|
if (Network.wifi.enabled) {
|
|
|
|
icon.icon = 'network-wireless-connected-symbolic';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
icon.icon = 'network-wireless-offline-symbolic';
|
|
|
|
}
|
|
|
|
}, 'changed']],
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
|
|
|
|
GridButton({
|
2023-09-26 11:46:03 -04:00
|
|
|
command: () => execAsync(['bash', '-c', '$AGS_PATH/qs-toggles.sh blue-toggle']).catch(print),
|
|
|
|
secondaryCommand: () => execAsync(['bash', '-c', 'blueberry']).catch(print),
|
2023-09-12 14:22:21 -04:00
|
|
|
icon: Icon({
|
|
|
|
className: 'grid-label',
|
|
|
|
connections: [[Bluetooth, icon => {
|
|
|
|
if (Bluetooth.enabled) {
|
|
|
|
icon.icon = 'bluetooth-active-symbolic';
|
2023-09-26 11:46:03 -04:00
|
|
|
execAsync(['bash', '-c', 'echo > $HOME/.config/.bluetooth']).catch(print);
|
2023-09-12 14:22:21 -04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
icon.icon = 'bluetooth-disabled-symbolic';
|
2023-09-26 11:46:03 -04:00
|
|
|
execAsync(['bash', '-c', 'echo > $HOME/.config/.bluetooth']).catch(print);
|
2023-09-12 14:22:21 -04:00
|
|
|
}
|
|
|
|
}, 'changed']],
|
|
|
|
})
|
|
|
|
}),
|
|
|
|
|
|
|
|
GridButton({
|
2023-09-26 11:46:03 -04:00
|
|
|
command: () => execAsync(['bash', '-c', '$AGS_PATH/qs-toggles.sh toggle-radio']).catch(print),
|
|
|
|
secondaryCommand: () => execAsync(['notify-send', 'set this up moron']).catch(print),
|
2023-09-12 14:22:21 -04:00
|
|
|
icon: Icon({
|
|
|
|
className: 'grid-label',
|
|
|
|
connections: [[Network, icon => {
|
|
|
|
if (Network.wifi.enabled) {
|
|
|
|
icon.icon = 'airplane-mode-disabled-symbolic';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
icon.icon = 'airplane-mode-symbolic';
|
|
|
|
}
|
|
|
|
}, 'changed']],
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
const SubRow = CenterBox({
|
|
|
|
halign: 'start',
|
|
|
|
children: [
|
|
|
|
|
|
|
|
Label({
|
|
|
|
className: 'sub-label',
|
|
|
|
truncate: 'end',
|
|
|
|
maxWidthChars: 12,
|
|
|
|
connections: [[Network, label => {
|
|
|
|
label.label = Network.wifi.ssid;
|
|
|
|
}, 'changed']],
|
|
|
|
}),
|
|
|
|
|
|
|
|
Label({
|
|
|
|
className: 'sub-label',
|
|
|
|
truncate: 'end',
|
|
|
|
maxWidthChars: 12,
|
|
|
|
connections: [[Bluetooth, label => {
|
2023-09-26 11:46:03 -04:00
|
|
|
label.label = Bluetooth.connectedDevices[0] ? String(Bluetooth.connectedDevices[0]) :
|
|
|
|
'Disconnected';
|
2023-09-12 14:22:21 -04:00
|
|
|
}, 'changed']],
|
|
|
|
}),
|
|
|
|
|
|
|
|
Label({
|
|
|
|
className: '',
|
|
|
|
truncate: 'end',
|
|
|
|
maxWidthChars: 12,
|
|
|
|
/*connections: [[Network, label => {
|
|
|
|
label.label = Network.wifi.ssid;
|
|
|
|
}, 'changed']],*/
|
|
|
|
}),
|
|
|
|
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
const items = {
|
|
|
|
101: 'audio-volume-overamplified-symbolic',
|
|
|
|
67: 'audio-volume-high-symbolic',
|
|
|
|
34: 'audio-volume-medium-symbolic',
|
|
|
|
1: 'audio-volume-low-symbolic',
|
|
|
|
0: 'audio-volume-muted-symbolic',
|
|
|
|
};
|
|
|
|
|
|
|
|
const itemsMic = {
|
|
|
|
2: 'audio-input-microphone-high-symbolic',
|
|
|
|
1: 'audio-input-microphone-muted-symbolic',
|
|
|
|
0: 'audio-input-microphone-muted-symbolic',
|
|
|
|
};
|
|
|
|
|
|
|
|
const SecondRow = Box({
|
|
|
|
className: 'button-row',
|
|
|
|
halign: 'center',
|
|
|
|
style: 'margin-top: 7px; margin-bottom: 15px;',
|
|
|
|
children: [
|
|
|
|
|
|
|
|
GridButton({
|
2023-09-26 11:46:03 -04:00
|
|
|
command: () => execAsync(['swayosd-client', '--output-volume', 'mute-toggle']).catch(print),
|
|
|
|
secondaryCommand: () => execAsync(['bash', '-c', 'pavucontrol']).catch(print),
|
2023-09-12 14:22:21 -04:00
|
|
|
icon: Icon({
|
|
|
|
className: 'grid-label',
|
|
|
|
connections: [[Audio, icon => {
|
|
|
|
if (Audio.speaker) {
|
2023-10-02 12:06:35 -04:00
|
|
|
if (Audio.speaker.stream.isMuted) {
|
2023-09-12 14:22:21 -04:00
|
|
|
icon.icon = items[0];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const vol = Audio.speaker.volume * 100;
|
|
|
|
for (const threshold of [-1, 0, 33, 66, 100]) {
|
|
|
|
if (vol > threshold + 1) {
|
|
|
|
icon.icon = items[threshold + 1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 'speaker-changed']],
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
|
|
|
|
GridButton({
|
2023-09-26 11:46:03 -04:00
|
|
|
command: () => execAsync(['swayosd-client', '--input-volume', 'mute-toggle']).catch(print),
|
|
|
|
secondaryCommand: () => execAsync(['bash', '-c', 'pavucontrol']).catch(print),
|
2023-09-12 14:22:21 -04:00
|
|
|
icon: Icon({
|
|
|
|
className: 'grid-label',
|
|
|
|
connections: [[Audio, icon => {
|
|
|
|
if (Audio.microphone) {
|
2023-10-02 12:06:35 -04:00
|
|
|
if (Audio.microphone.stream.isMuted) {
|
2023-09-12 14:22:21 -04:00
|
|
|
icon.icon = itemsMic[0];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const vol = Audio.microphone.volume * 100;
|
|
|
|
for (const threshold of [-1, 0, 1]) {
|
|
|
|
if (vol > threshold + 1) {
|
|
|
|
icon.icon = itemsMic[threshold + 1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 'microphone-changed']],
|
|
|
|
})
|
|
|
|
}),
|
|
|
|
|
|
|
|
GridButton({
|
2023-09-26 11:46:03 -04:00
|
|
|
command: () => execAsync(['bash', '-c', '$LOCK_PATH/lock.sh']).catch(print),
|
|
|
|
secondaryCommand: () => openWindow('powermenu'),
|
2023-09-12 14:22:21 -04:00
|
|
|
icon: Label({
|
|
|
|
className: 'grid-label',
|
|
|
|
label: " ",
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
export const ButtonGrid = Box({
|
|
|
|
className: 'button-grid',
|
|
|
|
vertical: true,
|
|
|
|
halign: 'center',
|
|
|
|
children: [
|
|
|
|
FirstRow,
|
|
|
|
SubRow,
|
|
|
|
SecondRow,
|
|
|
|
],
|
|
|
|
});
|