mirror of
https://github.com/nimbold/Firelink.git
synced 2026-08-05 17:08:26 +00:00
feat(locations): remember last Add-window directory
Remember manually selected Add-window folders during the current session, with a persisted Locations toggle and cross-platform path handling.\n\nRefs #23
This commit is contained in:
@@ -14,6 +14,7 @@ import {
|
||||
formatDerivedCategoryPath,
|
||||
normalizeCategorySubfolder,
|
||||
normalizeDownloadLocationSettings,
|
||||
resolveInitialAddWindowLocation,
|
||||
resolveCategoryDestination,
|
||||
subfolderFromDerivedCategoryPath
|
||||
} from './downloadLocations';
|
||||
@@ -24,6 +25,25 @@ describe('download locations', () => {
|
||||
expect(downloadLocationEquals('/Users/Test', 'Movie.MP4', '/users/test', 'movie.mp4', 'macos')).toBe(false);
|
||||
expect(downloadLocationEquals('/home/Test', 'Movie.MP4', '/home/test', 'movie.mp4', 'linux')).toBe(false);
|
||||
});
|
||||
|
||||
it('uses a remembered Add-window directory only when the setting is enabled', () => {
|
||||
expect(resolveInitialAddWindowLocation(
|
||||
'D:\\Downloads',
|
||||
true,
|
||||
'D:\\Course_Videos'
|
||||
)).toEqual({ path: 'D:\\Course_Videos', isManual: true });
|
||||
|
||||
expect(resolveInitialAddWindowLocation(
|
||||
'D:\\Downloads',
|
||||
false,
|
||||
'D:\\Course_Videos'
|
||||
)).toEqual({ path: 'D:\\Downloads', isManual: false });
|
||||
});
|
||||
|
||||
it('falls back to the normalized base folder when no directory was remembered', () => {
|
||||
expect(resolveInitialAddWindowLocation(' ', true, null))
|
||||
.toEqual({ path: '~/Downloads', isManual: false });
|
||||
});
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
@@ -48,6 +48,26 @@ interface LegacyDownloadLocationSettings {
|
||||
downloadDirectories?: unknown;
|
||||
}
|
||||
|
||||
export interface AddWindowLocationSuggestion {
|
||||
path: string;
|
||||
isManual: boolean;
|
||||
}
|
||||
|
||||
export const resolveInitialAddWindowLocation = (
|
||||
baseDownloadFolder: string,
|
||||
rememberLastUsedDownloadDirectory: boolean,
|
||||
lastUsedDownloadDirectory: string | null
|
||||
): AddWindowLocationSuggestion => {
|
||||
const rememberedPath = rememberLastUsedDownloadDirectory
|
||||
? lastUsedDownloadDirectory?.trim()
|
||||
: undefined;
|
||||
const basePath = baseDownloadFolder.trim() || '~/Downloads';
|
||||
return {
|
||||
path: rememberedPath || basePath,
|
||||
isManual: Boolean(rememberedPath)
|
||||
};
|
||||
};
|
||||
|
||||
const stringRecord = (value: unknown): Record<string, string> => {
|
||||
if (!value || typeof value !== 'object') return {};
|
||||
return Object.fromEntries(
|
||||
|
||||
Reference in New Issue
Block a user