mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-15 02:54:06 +02:00
30 lines
892 B
TypeScript
30 lines
892 B
TypeScript
import { openFileDialog } from '@app/services/fileDialogService';
|
|
import { pendingFilePathMappings } from '@app/services/pendingFilePathMappings';
|
|
import { getDocumentFileDialogFilter } from '@app/utils/fileDialogUtils';
|
|
|
|
interface OpenFilesFromDiskOptions {
|
|
multiple?: boolean;
|
|
filters?: Array<{
|
|
name: string;
|
|
extensions: string[];
|
|
}>;
|
|
onFallbackOpen?: () => void;
|
|
}
|
|
|
|
export async function openFilesFromDisk(options: OpenFilesFromDiskOptions = {}): Promise<File[]> {
|
|
const filesWithPaths = await openFileDialog({
|
|
multiple: options.multiple ?? true,
|
|
filters: options.filters ?? getDocumentFileDialogFilter()
|
|
});
|
|
|
|
if (filesWithPaths.length > 0) {
|
|
for (const { quickKey, path } of filesWithPaths) {
|
|
pendingFilePathMappings.set(quickKey, path);
|
|
}
|
|
return filesWithPaths.map((entry) => entry.file);
|
|
}
|
|
|
|
options.onFallbackOpen?.();
|
|
return [];
|
|
}
|