Files
openchamber/packages/ui/src/lib/directoryPersistence.ts
T

28 lines
1.0 KiB
TypeScript
Raw Normal View History

2026-01-16 14:43:53 +02:00
import { isVSCodeRuntime } from '@/lib/desktop';
2025-12-07 19:32:53 +02:00
import { useDirectoryStore } from '@/stores/useDirectoryStore';
export const applyPersistedDirectoryPreferences = async (): Promise<void> => {
if (typeof window === 'undefined') {
return;
}
let savedDirectory: string | null = null;
try {
savedDirectory = window.localStorage.getItem('lastDirectory');
} catch (error) {
console.warn('Failed to read saved directory preferences:', error);
}
// Home directory is intentionally NOT restored from localStorage here.
// The persisted value is only a boot-time cache already consumed by the
// directory store's initial state; replaying it through
// synchronizeHomeDirectory would persist a possibly stale value back into
// desktop settings, overriding the authoritative resolution
// (initializeHomeDirectory → /api/fs/home) that runs on every startup.
2025-12-07 19:32:53 +02:00
2026-01-16 14:43:53 +02:00
if (savedDirectory && !isVSCodeRuntime()) {
useDirectoryStore.getState().setDirectory(savedDirectory, { showOverlay: false });
2025-12-07 19:32:53 +02:00
}
};