Fix setTheme not triggering rerender, improve mac-system-theme example

This commit is contained in:
Mario Zechner 2026-01-09 00:32:41 +01:00
parent e5e944475d
commit 37378fb346
3 changed files with 17 additions and 3 deletions

View file

@ -2,6 +2,11 @@
## [Unreleased] ## [Unreleased]
### Fixed
- `setTheme()` now triggers a full rerender so previously rendered components update with the new theme colors
- `mac-system-theme.ts` example now polls every 2 seconds and uses `osascript` for real-time macOS appearance detection
## [0.39.0] - 2026-01-08 ## [0.39.0] - 2026-01-08
### Breaking Changes ### Breaking Changes

View file

@ -10,10 +10,13 @@ import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
function isDarkMode(): boolean { function isDarkMode(): boolean {
try { try {
execSync("defaults read -g AppleInterfaceStyle", { encoding: "utf-8" }); const result = execSync(
return true; // Returns "Dark" if dark mode "osascript -e 'tell application \"System Events\" to tell appearance preferences to return dark mode'",
{ encoding: "utf-8" },
);
return result.trim() === "true";
} catch { } catch {
return false; // Throws if light mode return false;
} }
} }

View file

@ -621,6 +621,9 @@ export function setTheme(name: string, enableWatcher: boolean = false): { succes
if (enableWatcher) { if (enableWatcher) {
startThemeWatcher(); startThemeWatcher();
} }
if (onThemeChangeCallback) {
onThemeChangeCallback();
}
return { success: true }; return { success: true };
} catch (error) { } catch (error) {
// Theme is invalid - fall back to dark theme // Theme is invalid - fall back to dark theme
@ -638,6 +641,9 @@ export function setThemeInstance(themeInstance: Theme): void {
theme = themeInstance; theme = themeInstance;
currentThemeName = "<in-memory>"; currentThemeName = "<in-memory>";
stopThemeWatcher(); // Can't watch a direct instance stopThemeWatcher(); // Can't watch a direct instance
if (onThemeChangeCallback) {
onThemeChangeCallback();
}
} }
export function onThemeChange(callback: () => void): void { export function onThemeChange(callback: () => void): void {