|
| 1 | +# Daemon Lifecycle |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +AGS runs as a single bundled process started at boot. All components are loaded into one process with shared resources for instant UI display and efficient usage. |
| 6 | + |
| 7 | +## Boot process |
| 8 | + |
| 9 | +1. Hyprland starts and runs `~/.config/ags/start-daemons.sh` |
| 10 | +2. Script waits for Hyprland to be ready |
| 11 | +3. Launches `ags run config-bundled.tsx` |
| 12 | +4. Components initialize in a single process |
| 13 | +5. Windows are pre-created (hidden) for instant display |
| 14 | + |
| 15 | +## Startup script (`start-daemons.sh`) |
| 16 | + |
| 17 | +Purpose: manage the bundled AGS process lifecycle. |
| 18 | + |
| 19 | +Features: |
| 20 | + |
| 21 | +- Waits for Hyprland to be ready before starting |
| 22 | +- Checks if bundled process is already running |
| 23 | +- Provides colored console output and logging |
| 24 | +- Logs to `/tmp/ags-daemons.log` for debugging |
| 25 | + |
| 26 | +Usage: |
| 27 | + |
| 28 | +```bash |
| 29 | +exec-once = uwsm app -- ~/.config/ags/start-daemons.sh |
| 30 | +~/.config/ags/start-daemons.sh |
| 31 | +cat /tmp/ags-daemons.log |
| 32 | +ags list |
| 33 | +``` |
| 34 | + |
| 35 | +Configuration (top of `start-daemons.sh`): |
| 36 | + |
| 37 | +```bash |
| 38 | +WAIT_FOR_HYPRLAND=true |
| 39 | +HYPRLAND_TIMEOUT=4 |
| 40 | +``` |
| 41 | + |
| 42 | +## Communication pattern |
| 43 | + |
| 44 | +Components communicate via the `globalThis` namespace. |
| 45 | + |
| 46 | +Component side (TypeScript in `lib/` files): |
| 47 | + |
| 48 | +```tsx |
| 49 | +globalThis.myComponent = { |
| 50 | + show: () => myWindow.show(), |
| 51 | + hide: () => myWindow.hide(), |
| 52 | + toggle: () => myWindow.visible ? myWindow.hide() : myWindow.show(), |
| 53 | +}; |
| 54 | + |
| 55 | +const myWindow = ( |
| 56 | + <window name="my-window" namespace="ags-myapp" visible={false}> |
| 57 | + {/* content */} |
| 58 | + </window> |
| 59 | +); |
| 60 | +``` |
| 61 | + |
| 62 | +Main config (`config-bundled.tsx`): |
| 63 | + |
| 64 | +```tsx |
| 65 | +import "gi://Astal?version=4.0"; |
| 66 | +import app from "ags/gtk4/app"; |
| 67 | + |
| 68 | +import "./lib/confirm-dialog.tsx"; |
| 69 | +import "./lib/keyboard-switcher.tsx"; |
| 70 | +import "./lib/volume-indicator.tsx"; |
| 71 | +import "./lib/start-menu.tsx"; |
| 72 | +import "./lib/window-switcher.tsx"; |
| 73 | + |
| 74 | +app.start({ |
| 75 | + instanceName: "ags-bundled", |
| 76 | + requestHandler(argv: string[], res: (response: string) => void) { |
| 77 | + try { |
| 78 | + const data = JSON.parse(argv.join(" ")); |
| 79 | + const component = globalThis[data.window]; |
| 80 | + |
| 81 | + if (component && typeof component[data.action] === "function") { |
| 82 | + component[data.action](); |
| 83 | + res("success"); |
| 84 | + } else { |
| 85 | + res("unknown window or action"); |
| 86 | + } |
| 87 | + } catch (e) { |
| 88 | + res(`error: ${e}`); |
| 89 | + } |
| 90 | + }, |
| 91 | +}); |
| 92 | +``` |
| 93 | + |
| 94 | +Client side (shell): |
| 95 | + |
| 96 | +```bash |
| 97 | +ags request -i ags-bundled '{"window":"start-menu","action":"toggle"}' |
| 98 | +bind = $mainMod, X, exec, ags request -i ags-bundled '{"window":"start-menu","action":"toggle"}' |
| 99 | +``` |
0 commit comments