mirror of
https://github.com/usebruno/bruno.git
synced 2025-02-08 14:02:09 +01:00
Feature: Reveal in Finder (#3698)
* feat: Reveal in Finder * added support for linux
This commit is contained in:
parent
b7fda331dc
commit
8f241a32ae
@ -6,7 +6,7 @@ import { useDrag, useDrop } from 'react-dnd';
|
||||
import { IconChevronRight, IconDots } from '@tabler/icons';
|
||||
import { useSelector, useDispatch } from 'react-redux';
|
||||
import { addTab, focusTab } from 'providers/ReduxStore/slices/tabs';
|
||||
import { moveItem, sendRequest } from 'providers/ReduxStore/slices/collections/actions';
|
||||
import { moveItem, revealInFinder, sendRequest } from 'providers/ReduxStore/slices/collections/actions';
|
||||
import { collectionFolderClicked } from 'providers/ReduxStore/slices/collections';
|
||||
import Dropdown from 'components/Dropdown';
|
||||
import NewRequest from 'components/Sidebar/NewRequest';
|
||||
@ -220,6 +220,12 @@ const CollectionItem = ({ item, collection, searchText }) => {
|
||||
}
|
||||
};
|
||||
|
||||
const handleReveal = () => {
|
||||
dispatch(revealInFinder(item.pathname)).catch((error) => {
|
||||
toast.error('Error revealing file:', error);
|
||||
});
|
||||
};
|
||||
|
||||
const requestItems = sortRequestItems(filter(item.items, (i) => isItemARequest(i)));
|
||||
const folderItems = sortFolderItems(filter(item.items, (i) => isItemAFolder(i)));
|
||||
|
||||
@ -371,6 +377,17 @@ const CollectionItem = ({ item, collection, searchText }) => {
|
||||
Generate Code
|
||||
</div>
|
||||
)}
|
||||
{!isFolder && (
|
||||
<div
|
||||
className="dropdown-item"
|
||||
onClick={(e) => {
|
||||
dropdownTippyRef.current.hide();
|
||||
handleReveal();
|
||||
}}
|
||||
>
|
||||
Reveal in Finder
|
||||
</div>
|
||||
)}
|
||||
<div
|
||||
className="dropdown-item delete-item"
|
||||
onClick={(e) => {
|
||||
|
@ -1219,3 +1219,12 @@ export const mountCollection = ({ collectionUid, collectionPathname, brunoConfig
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const revealInFinder = (collectionPath) => () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const { ipcRenderer } = window;
|
||||
|
||||
ipcRenderer.invoke('renderer:reveal-in-finder', collectionPath).then(resolve).catch(reject);
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -3,6 +3,7 @@ const fs = require('fs');
|
||||
const fsExtra = require('fs-extra');
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
const { exec } = require('child_process');
|
||||
const { ipcMain, shell, dialog, app } = require('electron');
|
||||
const { envJsonToBru, bruToJson, jsonToBruViaWorker, jsonToCollectionBru, bruToJsonViaWorker } = require('../bru');
|
||||
|
||||
@ -909,6 +910,41 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
|
||||
|
||||
watcher.addWatcher(mainWindow, collectionPathname, collectionUid, brunoConfig, false, shouldLoadCollectionAsync);
|
||||
});
|
||||
|
||||
ipcMain.handle('renderer:reveal-in-finder', async (event, filePath) => {
|
||||
try {
|
||||
if (!filePath) {
|
||||
throw new Error('File path is required.');
|
||||
}
|
||||
|
||||
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) {
|
||||
console.error('Error in reveal-in-finder:', error);
|
||||
return { success: false, message: error.message };
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const registerMainEventHandlers = (mainWindow, watcher, lastOpenedCollections) => {
|
||||
|
Loading…
Reference in New Issue
Block a user