The Electron BrowserWindow to attach the dialog to
The suggested file path to initialize the dialog with
Array of file filters to limit selection options
Promise resolving to selected file path or undefined if canceled
// Show dialog to save CSV file
const filePath = await promptForExportLocation(
mainWindow,
join(ensureExportDir(), 'export.csv'),
[{ name: 'CSV Files', extensions: ['csv'] }]
);
if (filePath) {
// User selected a path
writeDataToFile(filePath, data);
} else {
// User canceled the dialog
showCancelMessage();
}
export async function promptForExportLocation(
mainWindow: BrowserWindow,
defaultPath: string,
filters: Electron.FileFilter[],
): Promise<string | undefined> {
const result = await dialog.showSaveDialog(mainWindow, {
defaultPath,
filters,
properties: ["createDirectory"],
});
return result.canceled ? undefined : result.filePath;
}
Prompts the user to select a file location for export
Displays a native save dialog allowing the user to choose where to save an exported file. This function provides a consistent way to handle file selection across all export functions in the module.
The dialog is configured to: