2023-10-31 08:32:40 -04:00
|
|
|
import { Box, Label } from 'resource:///com/github/Aylur/ags/widget.js';
|
2023-12-07 15:28:58 -05:00
|
|
|
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
|
|
|
|
2023-12-07 15:28:58 -05:00
|
|
|
const HeartState = Variable('');
|
|
|
|
const heartFile = `${get_home_dir()}/.cache/ags/.heart`;
|
2023-10-02 12:06:35 -04:00
|
|
|
|
2023-12-07 15:28:58 -05:00
|
|
|
const stateCmd = () => ['bash', '-c',
|
|
|
|
`echo ${HeartState.value === ''} > ${heartFile}`];
|
|
|
|
const monitorState = () => {
|
|
|
|
HeartState.connect('changed', () => {
|
|
|
|
execAsync(stateCmd()).catch(print);
|
|
|
|
});
|
|
|
|
};
|
2023-10-17 13:47:02 -04:00
|
|
|
|
2023-12-07 15:28:58 -05:00
|
|
|
// On launch
|
|
|
|
readFileAsync(heartFile).then((content) => {
|
|
|
|
HeartState.value = JSON.parse(content) ? '' : '';
|
|
|
|
monitorState();
|
|
|
|
}).catch(() => {
|
|
|
|
execAsync(stateCmd()).then(() => {
|
|
|
|
monitorState();
|
|
|
|
}).catch(print);
|
|
|
|
});
|
2023-10-17 13:47:02 -04:00
|
|
|
|
2023-09-04 22:27:34 -04:00
|
|
|
|
2023-12-07 15:28:58 -05:00
|
|
|
export default () => {
|
|
|
|
return EventBox({
|
|
|
|
onPrimaryClickRelease: () => {
|
|
|
|
HeartState.value = HeartState.value === '' ? '' : '';
|
|
|
|
},
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-12-07 15:28:58 -05:00
|
|
|
child: Box({
|
|
|
|
className: 'heart-toggle',
|
|
|
|
|
|
|
|
child: Label({
|
|
|
|
binds: [['label', HeartState, 'value']],
|
|
|
|
}),
|
2023-10-20 23:11:21 -04:00
|
|
|
}),
|
2023-12-07 15:28:58 -05:00
|
|
|
});
|
|
|
|
};
|