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);
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-12 01:53:38 +03:00
|
|
|
// 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()) {
|
2026-06-12 01:53:38 +03:00
|
|
|
useDirectoryStore.getState().setDirectory(savedDirectory, { showOverlay: false });
|
2025-12-07 19:32:53 +02:00
|
|
|
}
|
|
|
|
|
};
|