• 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:

    • Start at the provided default path
    • Filter files by the specified types
    • Allow directory creation during navigation
    • Return undefined if canceled by user

    Parameters

    • mainWindow: BrowserWindow

      The Electron BrowserWindow to attach the dialog to

    • defaultPath: string

      The suggested file path to initialize the dialog with

    • filters: FileFilter[]

      Array of file filters to limit selection options

    Returns Promise<undefined | string>

    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;
    }