mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-21 04:00:10 +00:00
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:
parent
76312ea7e8
commit
9516424cae
3 changed files with 14 additions and 8 deletions
|
|
@ -167,10 +167,13 @@ export async function main(args: string[]) {
|
||||||
// Process @file arguments
|
// Process @file arguments
|
||||||
const { initialMessage, initialAttachments } = prepareInitialMessage(parsed);
|
const { initialMessage, initialAttachments } = prepareInitialMessage(parsed);
|
||||||
|
|
||||||
|
// Determine if we're in interactive mode (needed for theme watcher)
|
||||||
|
const isInteractive = !parsed.print && parsed.mode === undefined;
|
||||||
|
|
||||||
// Initialize theme (before any TUI rendering)
|
// Initialize theme (before any TUI rendering)
|
||||||
const settingsManager = new SettingsManager();
|
const settingsManager = new SettingsManager();
|
||||||
const themeName = settingsManager.getTheme();
|
const themeName = settingsManager.getTheme();
|
||||||
initTheme(themeName);
|
initTheme(themeName, isInteractive);
|
||||||
|
|
||||||
// Setup session manager
|
// Setup session manager
|
||||||
const sessionManager = new SessionManager(parsed.continue && !parsed.resume, parsed.session);
|
const sessionManager = new SessionManager(parsed.continue && !parsed.resume, parsed.session);
|
||||||
|
|
@ -196,7 +199,6 @@ export async function main(args: string[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine mode and output behavior
|
// Determine mode and output behavior
|
||||||
const isInteractive = !parsed.print && parsed.mode === undefined;
|
|
||||||
const mode = parsed.mode || "text";
|
const mode = parsed.mode || "text";
|
||||||
const shouldPrintMessages = isInteractive;
|
const shouldPrintMessages = isInteractive;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1164,7 +1164,7 @@ export class InteractiveMode {
|
||||||
const selector = new ThemeSelectorComponent(
|
const selector = new ThemeSelectorComponent(
|
||||||
currentTheme,
|
currentTheme,
|
||||||
(themeName) => {
|
(themeName) => {
|
||||||
const result = setTheme(themeName);
|
const result = setTheme(themeName, true);
|
||||||
this.settingsManager.setTheme(themeName);
|
this.settingsManager.setTheme(themeName);
|
||||||
this.ui.invalidate();
|
this.ui.invalidate();
|
||||||
done();
|
done();
|
||||||
|
|
@ -1179,7 +1179,7 @@ export class InteractiveMode {
|
||||||
this.ui.requestRender();
|
this.ui.requestRender();
|
||||||
},
|
},
|
||||||
(themeName) => {
|
(themeName) => {
|
||||||
const result = setTheme(themeName);
|
const result = setTheme(themeName, true);
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
this.ui.invalidate();
|
this.ui.invalidate();
|
||||||
this.ui.requestRender();
|
this.ui.requestRender();
|
||||||
|
|
|
||||||
|
|
@ -455,12 +455,14 @@ let currentThemeName: string | undefined;
|
||||||
let themeWatcher: fs.FSWatcher | undefined;
|
let themeWatcher: fs.FSWatcher | undefined;
|
||||||
let onThemeChangeCallback: (() => void) | undefined;
|
let onThemeChangeCallback: (() => void) | undefined;
|
||||||
|
|
||||||
export function initTheme(themeName?: string): void {
|
export function initTheme(themeName?: string, enableWatcher: boolean = false): void {
|
||||||
const name = themeName ?? getDefaultTheme();
|
const name = themeName ?? getDefaultTheme();
|
||||||
currentThemeName = name;
|
currentThemeName = name;
|
||||||
try {
|
try {
|
||||||
theme = loadTheme(name);
|
theme = loadTheme(name);
|
||||||
|
if (enableWatcher) {
|
||||||
startThemeWatcher();
|
startThemeWatcher();
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Theme is invalid - fall back to dark theme silently
|
// Theme is invalid - fall back to dark theme silently
|
||||||
currentThemeName = "dark";
|
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;
|
currentThemeName = name;
|
||||||
try {
|
try {
|
||||||
theme = loadTheme(name);
|
theme = loadTheme(name);
|
||||||
|
if (enableWatcher) {
|
||||||
startThemeWatcher();
|
startThemeWatcher();
|
||||||
|
}
|
||||||
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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue