feat(ags): persist bluetooth state
This commit is contained in:
parent
f972815389
commit
bba90cd8b6
1 changed files with 29 additions and 0 deletions
|
@ -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',
|
||||
|
|
Loading…
Reference in a new issue