mirror of
https://github.com/usebruno/bruno.git
synced 2025-08-23 09:11:22 +02:00
Review changes and minor-refactoring in Reveal in Finder
feature
This commit is contained in:
@@ -6,7 +6,7 @@ import { useDrag, useDrop } from 'react-dnd';
|
|||||||
import { IconChevronRight, IconDots } from '@tabler/icons';
|
import { IconChevronRight, IconDots } from '@tabler/icons';
|
||||||
import { useSelector, useDispatch } from 'react-redux';
|
import { useSelector, useDispatch } from 'react-redux';
|
||||||
import { addTab, focusTab } from 'providers/ReduxStore/slices/tabs';
|
import { addTab, focusTab } from 'providers/ReduxStore/slices/tabs';
|
||||||
import { moveItem, revealInFinder, sendRequest } from 'providers/ReduxStore/slices/collections/actions';
|
import { moveItem, showInFolder, sendRequest } from 'providers/ReduxStore/slices/collections/actions';
|
||||||
import { collectionFolderClicked } from 'providers/ReduxStore/slices/collections';
|
import { collectionFolderClicked } from 'providers/ReduxStore/slices/collections';
|
||||||
import Dropdown from 'components/Dropdown';
|
import Dropdown from 'components/Dropdown';
|
||||||
import NewRequest from 'components/Sidebar/NewRequest';
|
import NewRequest from 'components/Sidebar/NewRequest';
|
||||||
@@ -220,9 +220,10 @@ const CollectionItem = ({ item, collection, searchText }) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleReveal = () => {
|
const handleShowInFolder = () => {
|
||||||
dispatch(revealInFinder(item.pathname)).catch((error) => {
|
dispatch(showInFolder(item.pathname)).catch((error) => {
|
||||||
toast.error('Error revealing file:', error);
|
console.error('Error opening the folder', error);
|
||||||
|
toast.error('Error opening the folder');
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -377,17 +378,15 @@ const CollectionItem = ({ item, collection, searchText }) => {
|
|||||||
Generate Code
|
Generate Code
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{!isFolder && (
|
<div
|
||||||
<div
|
className="dropdown-item"
|
||||||
className="dropdown-item"
|
onClick={(e) => {
|
||||||
onClick={(e) => {
|
dropdownTippyRef.current.hide();
|
||||||
dropdownTippyRef.current.hide();
|
handleShowInFolder();
|
||||||
handleReveal();
|
}}
|
||||||
}}
|
>
|
||||||
>
|
Show in Folder
|
||||||
Reveal in Finder
|
</div>
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
<div
|
<div
|
||||||
className="dropdown-item delete-item"
|
className="dropdown-item delete-item"
|
||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
|
@@ -1220,11 +1220,9 @@ export const mountCollection = ({ collectionUid, collectionPathname, brunoConfig
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const revealInFinder = (collectionPath) => () => {
|
export const showInFolder = (collectionPath) => () => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const { ipcRenderer } = window;
|
const { ipcRenderer } = window;
|
||||||
|
ipcRenderer.invoke('renderer:show-in-folder', collectionPath).then(resolve).catch(reject);
|
||||||
ipcRenderer.invoke('renderer:reveal-in-finder', collectionPath).then(resolve).catch(reject);
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -3,7 +3,6 @@ const fs = require('fs');
|
|||||||
const fsExtra = require('fs-extra');
|
const fsExtra = require('fs-extra');
|
||||||
const os = require('os');
|
const os = require('os');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const { exec } = require('child_process');
|
|
||||||
const { ipcMain, shell, dialog, app } = require('electron');
|
const { ipcMain, shell, dialog, app } = require('electron');
|
||||||
const { envJsonToBru, bruToJson, jsonToBruViaWorker, jsonToCollectionBru, bruToJsonViaWorker } = require('../bru');
|
const { envJsonToBru, bruToJson, jsonToBruViaWorker, jsonToCollectionBru, bruToJsonViaWorker } = require('../bru');
|
||||||
|
|
||||||
@@ -911,40 +910,17 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
|
|||||||
watcher.addWatcher(mainWindow, collectionPathname, collectionUid, brunoConfig, false, shouldLoadCollectionAsync);
|
watcher.addWatcher(mainWindow, collectionPathname, collectionUid, brunoConfig, false, shouldLoadCollectionAsync);
|
||||||
});
|
});
|
||||||
|
|
||||||
ipcMain.handle('renderer:reveal-in-finder', async (event, filePath) => {
|
ipcMain.handle('renderer:show-in-folder', async (event, filePath) => {
|
||||||
try {
|
try {
|
||||||
if (!filePath) {
|
if (!filePath) {
|
||||||
throw new Error('File path is required.');
|
throw new Error('File path is required');
|
||||||
}
|
}
|
||||||
|
shell.showItemInFolder(filePath);
|
||||||
const resolvedPath = path.resolve(filePath);
|
|
||||||
|
|
||||||
if (!fs.existsSync(resolvedPath)) {
|
|
||||||
throw new Error('The specified file does not exist.');
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(process.platform, "process.platform")
|
|
||||||
|
|
||||||
switch (process.platform) {
|
|
||||||
case 'darwin': // macOS
|
|
||||||
shell.showItemInFolder(resolvedPath);
|
|
||||||
break;
|
|
||||||
case 'win32': // Windows
|
|
||||||
shell.showItemInFolder(resolvedPath);
|
|
||||||
break;
|
|
||||||
case 'linux': // Linux
|
|
||||||
exec(`xdg-open "${resolvedPath}"`);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new Error('Unsupported platform.');
|
|
||||||
}
|
|
||||||
|
|
||||||
return { success: true };
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error in reveal-in-finder:', error);
|
console.error('Error in show-in-folder: ', error);
|
||||||
return { success: false, message: error.message };
|
throw error;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const registerMainEventHandlers = (mainWindow, watcher, lastOpenedCollections) => {
|
const registerMainEventHandlers = (mainWindow, watcher, lastOpenedCollections) => {
|
||||||
|
Reference in New Issue
Block a user