refactor: update terminal session limits and improve layout saving

- Refactored session limit checks in terminal settings to use constants for minimum and maximum session values.
- Enhanced terminal layout saving mechanism with debouncing to prevent excessive writes during rapid changes.
- Updated error messages to reflect new session limit constants.
This commit is contained in:
SuperComboGamer
2025-12-20 23:02:31 -05:00
parent 195b98e688
commit 2b1a7660b6
4 changed files with 25 additions and 7 deletions

View File

@@ -627,12 +627,26 @@ export function TerminalView() {
}
}, [currentProject?.path, saveTerminalLayout, getPersistedTerminalLayout, clearTerminalState, addTerminalTab, serverUrl]);
// Save terminal layout whenever it changes (debounced via the effect)
// Save terminal layout whenever it changes (debounced to prevent excessive writes)
// Also save when tabs become empty so closed terminals stay closed on refresh
const saveLayoutTimeoutRef = useRef<NodeJS.Timeout | null>(null);
useEffect(() => {
if (currentProject?.path && !isRestoringLayoutRef.current) {
saveTerminalLayout(currentProject.path);
// Debounce saves to prevent excessive localStorage writes during rapid changes
if (saveLayoutTimeoutRef.current) {
clearTimeout(saveLayoutTimeoutRef.current);
}
saveLayoutTimeoutRef.current = setTimeout(() => {
saveTerminalLayout(currentProject.path);
saveLayoutTimeoutRef.current = null;
}, 500); // 500ms debounce
}
return () => {
if (saveLayoutTimeoutRef.current) {
clearTimeout(saveLayoutTimeoutRef.current);
}
};
}, [terminalState.tabs, currentProject?.path, saveTerminalLayout]);
// Handle password authentication