feat(ags): persist bluetooth state

This commit is contained in:
matt1432 2023-12-07 14:02:28 -05:00
parent f972815389
commit bba90cd8b6

View file

@ -1,5 +1,7 @@
import App from 'resource:///com/github/Aylur/ags/app.js'; import App from 'resource:///com/github/Aylur/ags/app.js';
import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js'; import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js';
import Bluetooth from 'resource:///com/github/Aylur/ags/service/bluetooth.js';
import { execAsync, readFileAsync, timeout } from 'resource:///com/github/Aylur/ags/utils.js';
import Brightness from '../services/brightness.js'; import Brightness from '../services/brightness.js';
import Pointers from '../services/pointers.js'; import Pointers from '../services/pointers.js';
@ -14,6 +16,33 @@ export default () => {
globalThis.Tablet = Tablet; globalThis.Tablet = Tablet;
globalThis.closeAll = closeAll; globalThis.closeAll = closeAll;
// Persist Bluetooth state
const bluetoothStateFile = '/home/matt/.cache/ags/.bluetooth';
const stateCmd = () => ['bash', '-c',
`echo ${Bluetooth.enabled} > ${bluetoothStateFile}`];
const monitorState = () => {
Bluetooth.connect('notify::enabled', () => {
execAsync(stateCmd()).catch(print);
});
};
// On launch
readFileAsync(bluetoothStateFile)
.then((content) => {
Bluetooth.enabled = JSON.parse(content);
timeout(1000, () => {
monitorState();
});
})
.catch(() => {
execAsync(stateCmd())
.then(() => {
monitorState();
})
.catch(print);
});
TouchGestures.addGesture({ TouchGestures.addGesture({
name: 'openAppLauncher', name: 'openAppLauncher',
gesture: 'UD', gesture: 'UD',