Added logic to select only one file.

This commit is contained in:
Zachary Elliott 2024-08-02 21:27:14 -06:00
parent 145de02733
commit b54b5ff19a
4 changed files with 34 additions and 1 deletions

View File

@ -1014,6 +1014,16 @@ export const browseFiles =
});
};
export const browseFile =
(filters = []) =>
(dispatch, getState) => {
const { ipcRenderer } = window;
return new Promise((resolve, reject) => {
ipcRenderer.invoke('renderer:browse-file', filters).then(resolve).catch(reject);
});
};
export const updateBrunoConfig = (brunoConfig, collectionUid) => (dispatch, getState) => {
const state = getState();

View File

@ -698,7 +698,6 @@ export const refreshUidsInItem = (item) => {
each(get(item, 'request.params'), (param) => (param.uid = uuid()));
each(get(item, 'request.body.multipartForm'), (param) => (param.uid = uuid()));
each(get(item, 'request.body.formUrlEncoded'), (param) => (param.uid = uuid()));
each(get(item, 'request.body.rawFile'), (param) => (param.uid = uuid()));
return item;
};

View File

@ -11,6 +11,7 @@ const {
isDirectory,
browseDirectory,
browseFiles,
browseFile,
createDirectory,
searchForBruFiles,
sanitizeDirectoryName
@ -50,6 +51,17 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
}
});
// browse directory for one file
ipcMain.handle('renderer:browse-file', async (event, pathname, request, filters) => {
try {
const filePath = await browseFile(mainWindow, filters);
return filePath;
} catch (error) {
return Promise.reject(error);
}
});
// create collection
ipcMain.handle(
'renderer:create-collection',

View File

@ -116,6 +116,17 @@ const browseFiles = async (win, filters) => {
return filePaths.map((path) => normalizeAndResolvePath(path)).filter((path) => isFile(path));
};
const browseFile = async (win, filters) => {
const { filePath } = await dialog.showOpenDialog(win, {
properties: ['openFile'],
filters
});
if(!filePath) {
return null;
}
}
const chooseFileToSave = async (win, preferredFileName = '') => {
const { filePath } = await dialog.showSaveDialog(win, {
defaultPath: preferredFileName
@ -161,6 +172,7 @@ module.exports = {
createDirectory,
browseDirectory,
browseFiles,
browseFile,
chooseFileToSave,
searchForFiles,
searchForBruFiles,