nixos-configs/devices/wim/config/ags/js/bar/buttons/heart.js

47 lines
1.2 KiB
JavaScript
Raw Normal View History

import { Box, Label } from 'resource:///com/github/Aylur/ags/widget.js';
import { execAsync, readFileAsync } from 'resource:///com/github/Aylur/ags/utils.js';
import Variable from 'resource:///com/github/Aylur/ags/variable.js';
const { get_home_dir } = imports.gi.GLib;
2023-09-04 22:27:34 -04:00
2023-11-16 00:48:50 -05:00
import EventBox from '../../misc/cursorbox.js';
2023-09-04 22:27:34 -04:00
const HeartState = Variable('');
const heartFile = `${get_home_dir()}/.cache/ags/.heart`;
const stateCmd = () => ['bash', '-c',
`echo ${HeartState.value === ''} > ${heartFile}`];
const monitorState = () => {
HeartState.connect('changed', () => {
execAsync(stateCmd()).catch(print);
});
};
// On launch
readFileAsync(heartFile).then((content) => {
HeartState.value = JSON.parse(content) ? '' : '󰣐';
monitorState();
}).catch(() => {
execAsync(stateCmd()).then(() => {
monitorState();
}).catch(print);
});
2023-09-04 22:27:34 -04:00
export default () => {
return EventBox({
onPrimaryClickRelease: () => {
HeartState.value = HeartState.value === '' ? '󰣐' : '';
},
child: Box({
className: 'heart-toggle',
child: Label({
binds: [['label', HeartState, 'value']],
}),
}),
});
};