From bba90cd8b6e88a7868af4cf0fa406a39558e50c2 Mon Sep 17 00:00:00 2001 From: matt1432 Date: Thu, 7 Dec 2023 14:02:28 -0500 Subject: [PATCH] feat(ags): persist bluetooth state --- devices/wim/config/ags/js/setup.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/devices/wim/config/ags/js/setup.js b/devices/wim/config/ags/js/setup.js index 48f3249..18d1420 100644 --- a/devices/wim/config/ags/js/setup.js +++ b/devices/wim/config/ags/js/setup.js @@ -1,5 +1,7 @@ import App from 'resource:///com/github/Aylur/ags/app.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 Pointers from '../services/pointers.js'; @@ -14,6 +16,33 @@ export default () => { globalThis.Tablet = Tablet; 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({ name: 'openAppLauncher', gesture: 'UD',