diff --git a/default/pi/agent/extensions/omarchy-system-theme.ts b/default/pi/agent/extensions/omarchy-system-theme.ts new file mode 100644 index 00000000..18c6fef6 --- /dev/null +++ b/default/pi/agent/extensions/omarchy-system-theme.ts @@ -0,0 +1,41 @@ +/** + * Syncs pi's light/dark theme with the active Omarchy theme. + * + * Omarchy light themes include: + * ~/.config/omarchy/current/theme/light.mode + */ + +import { existsSync } from "node:fs"; +import { join } from "node:path"; +import type { ExtensionAPI } from "@mariozechner/pi-coding-agent"; + +const home = process.env.HOME ?? ""; +const lightModePath = join(home, ".config/omarchy/current/theme/light.mode"); + +function omarchyPiTheme(): "light" | "dark" { + return existsSync(lightModePath) ? "light" : "dark"; +} + +export default function (pi: ExtensionAPI) { + let intervalId: ReturnType | null = null; + + pi.on("session_start", (_event, ctx) => { + let currentTheme = omarchyPiTheme(); + ctx.ui.setTheme(currentTheme); + + intervalId = setInterval(() => { + const nextTheme = omarchyPiTheme(); + if (nextTheme !== currentTheme) { + currentTheme = nextTheme; + ctx.ui.setTheme(currentTheme); + } + }, 2000); + }); + + pi.on("session_shutdown", () => { + if (intervalId) { + clearInterval(intervalId); + intervalId = null; + } + }); +} diff --git a/install/config/all.sh b/install/config/all.sh index 39d5c6d1..72effc32 100644 --- a/install/config/all.sh +++ b/install/config/all.sh @@ -24,6 +24,7 @@ run_logged $OMARCHY_INSTALL/config/unmount-fuse.sh run_logged $OMARCHY_INSTALL/config/sudoless-asdcontrol.sh run_logged $OMARCHY_INSTALL/config/input-group.sh run_logged $OMARCHY_INSTALL/config/omarchy-ai-skill.sh +run_logged $OMARCHY_INSTALL/config/pi.sh run_logged $OMARCHY_INSTALL/config/omarchy-toggles.sh run_logged $OMARCHY_INSTALL/config/kernel-modules-hook.sh run_logged $OMARCHY_INSTALL/config/powerprofilesctl-rules.sh diff --git a/install/config/pi.sh b/install/config/pi.sh new file mode 100644 index 00000000..4afefecb --- /dev/null +++ b/install/config/pi.sh @@ -0,0 +1,2 @@ +mkdir -p ~/.pi/agent/extensions +cp "$OMARCHY_PATH/default/pi/agent/extensions/omarchy-system-theme.ts" ~/.pi/agent/extensions/ diff --git a/migrations/1778151386.sh b/migrations/1778151386.sh new file mode 100644 index 00000000..5f9fb388 --- /dev/null +++ b/migrations/1778151386.sh @@ -0,0 +1,4 @@ +echo "Add Omarchy pi system theme extension" + +mkdir -p "$HOME/.pi/agent/extensions" +cp "$OMARCHY_PATH/default/pi/agent/extensions/omarchy-system-theme.ts" "$HOME/.pi/agent/extensions/"