fixes #161: disable theme watcher in print mode

The theme file watcher was keeping the Node.js process alive indefinitely
even in print mode where hot-reload is unnecessary. This fix adds an
enableWatcher parameter to initTheme() and setTheme() functions, and only
enables watchers in interactive mode.

- Modified initTheme() to accept enableWatcher parameter (default: false)
- Modified setTheme() to accept enableWatcher parameter (default: false)
- Updated main.ts to only enable watchers in interactive mode
- Updated InteractiveMode to enable watchers when changing themes
This commit is contained in:
Mario Zechner 2025-12-10 20:41:45 +01:00
parent 76312ea7e8
commit 9516424cae
3 changed files with 14 additions and 8 deletions

View file

@ -455,12 +455,14 @@ let currentThemeName: string | undefined;
let themeWatcher: fs.FSWatcher | undefined;
let onThemeChangeCallback: (() => void) | undefined;
export function initTheme(themeName?: string): void {
export function initTheme(themeName?: string, enableWatcher: boolean = false): void {
const name = themeName ?? getDefaultTheme();
currentThemeName = name;
try {
theme = loadTheme(name);
startThemeWatcher();
if (enableWatcher) {
startThemeWatcher();
}
} catch (error) {
// Theme is invalid - fall back to dark theme silently
currentThemeName = "dark";
@ -469,11 +471,13 @@ export function initTheme(themeName?: string): void {
}
}
export function setTheme(name: string): { success: boolean; error?: string } {
export function setTheme(name: string, enableWatcher: boolean = false): { success: boolean; error?: string } {
currentThemeName = name;
try {
theme = loadTheme(name);
startThemeWatcher();
if (enableWatcher) {
startThemeWatcher();
}
return { success: true };
} catch (error) {
// Theme is invalid - fall back to dark theme