nixos-configs/devices/wim/config/ags/js/setup.js

85 lines
2.4 KiB
JavaScript
Raw Normal View History

import App from 'resource:///com/github/Aylur/ags/app.js';
import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js';
2023-12-07 14:02:28 -05:00
import Bluetooth from 'resource:///com/github/Aylur/ags/service/bluetooth.js';
import { execAsync, readFileAsync, timeout } from 'resource:///com/github/Aylur/ags/utils.js';
const { get_home_dir } = imports.gi.GLib;
import Brightness from '../services/brightness.js';
import Pointers from '../services/pointers.js';
import Tablet from '../services/tablet.js';
2023-11-05 01:34:13 -05:00
import TouchGestures from '../services/touch-gestures.js';
import closeAll from './misc/closer.js';
export default () => {
2023-11-10 23:51:50 -05:00
globalThis.Brightness = Brightness;
globalThis.Pointers = Pointers;
2023-11-10 23:51:50 -05:00
globalThis.Tablet = Tablet;
globalThis.closeAll = closeAll;
2023-12-07 14:02:28 -05:00
// Persist Bluetooth state
const bluetoothFile = `${get_home_dir()}/.cache/ags/.bluetooth`;
2023-12-07 14:02:28 -05:00
const stateCmd = () => ['bash', '-c',
`echo ${Bluetooth.enabled} > ${bluetoothFile}`];
2023-12-07 14:02:28 -05:00
const monitorState = () => {
Bluetooth.connect('notify::enabled', () => {
execAsync(stateCmd()).catch(print);
});
};
// On launch
readFileAsync(bluetoothFile).then((content) => {
Bluetooth.enabled = JSON.parse(content);
timeout(1000, () => {
monitorState();
2023-12-07 14:02:28 -05:00
});
}).catch(() => {
execAsync(stateCmd()).then(() => {
monitorState();
}).catch(print);
});
2023-12-07 14:02:28 -05:00
TouchGestures.addGesture({
name: 'openAppLauncher',
gesture: 'UD',
edge: 'T',
command: () => App.openWindow('applauncher'),
});
2023-11-05 01:34:13 -05:00
TouchGestures.addGesture({
name: 'oskOn',
gesture: 'DU',
edge: 'B',
command: 'busctl call --user sm.puri.OSK0 /sm/puri/OSK0 sm.puri.OSK0 ' +
'SetVisible b true',
2023-11-05 01:34:13 -05:00
});
TouchGestures.addGesture({
name: 'oskOff',
gesture: 'UD',
edge: 'B',
command: 'busctl call --user sm.puri.OSK0 /sm/puri/OSK0 sm.puri.OSK0 ' +
'SetVisible b false',
2023-11-05 01:34:13 -05:00
});
TouchGestures.addGesture({
name: 'swipeSpotify1',
gesture: 'LR',
edge: 'L',
command: () => Hyprland.sendMessage(
'dispatch togglespecialworkspace spot',
),
2023-11-05 01:34:13 -05:00
});
TouchGestures.addGesture({
name: 'swipeSpotify2',
gesture: 'RL',
edge: 'L',
command: () => Hyprland.sendMessage(
'dispatch togglespecialworkspace spot',
),
2023-11-05 01:34:13 -05:00
});
};