Skip to content
This repository has been archived by the owner on Jan 6, 2025. It is now read-only.

Commit

Permalink
feat: Add Button to open data directory to RpcControlBox
Browse files Browse the repository at this point in the history
  • Loading branch information
binarybaron committed Jun 27, 2024
1 parent 93d57e1 commit 93a7bbc
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
6 changes: 5 additions & 1 deletion src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
} from 'store/config';
import { resolveHtmlPath } from './util';
import { isCliRunning, startRPC, stopCli } from './cli/cli';
import getSavedLogsOfSwapId, { getAssetPath, fixAppDataPath } from './cli/dirs';
import getSavedLogsOfSwapId, { getAssetPath, fixAppDataPath, getCliDataDir } from './cli/dirs';
import initSocket from './socket';
import logger from '../utils/logger';
import { isTorRunning, spawnTor, stopTor } from './tor';
Expand Down Expand Up @@ -219,6 +219,10 @@ ipcMain.handle('get-swap-logs', (_event, swapId) =>
getSavedLogsOfSwapId(swapId),
);

ipcMain.handle('open-data-dir-in-file-explorer', async () => {
shell.openPath(await getCliDataDir());
});

export function sendSnackbarAlertToRenderer(
message: string,
variant: string,
Expand Down
29 changes: 21 additions & 8 deletions src/renderer/components/IpcInvokeButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,27 @@ import { useAppSelector } from 'store/hooks';
import { RpcProcessStateType } from 'models/rpcModel';
import { isExternalRpc } from 'store/config';

function IpcNotReadyTooltip({
show,
function IpcButtonTooltip({
requiresRpcAndNotReady,
children,
processType,
tooltipTitle,
}: {
show: boolean;
requiresRpcAndNotReady: boolean;
children: ReactElement;
processType: RpcProcessStateType;
tooltipTitle?: string;
}) {
const getMessage = () => {
if (!show) return '';
if(tooltipTitle) {
return (
<Tooltip title={tooltipTitle}>
{children}
</Tooltip>
);
}

const getMessage = () => {
if (!requiresRpcAndNotReady) return '';

switch (processType) {
case RpcProcessStateType.LISTENING_FOR_CONNECTIONS:
Expand Down Expand Up @@ -55,6 +65,7 @@ interface IpcInvokeButtonProps<T> {
requiresRpc?: boolean;
disabled?: boolean;
displayErrorSnackbar?: boolean;
tooltipTitle?: string;
}

const DELAY_BEFORE_SHOWING_LOADING_MS = 0;
Expand All @@ -71,6 +82,7 @@ export default function IpcInvokeButton<T>({
isIconButton,
requiresRpc,
displayErrorSnackbar,
tooltipTitle,
...rest
}: IpcInvokeButtonProps<T> & ButtonProps) {
const { enqueueSnackbar } = useSnackbar();
Expand Down Expand Up @@ -120,9 +132,10 @@ export default function IpcInvokeButton<T>({
const isDisabled = disabled || requiresRpcAndNotReady || isLoading;

return (
<IpcNotReadyTooltip
show={requiresRpcAndNotReady}
<IpcButtonTooltip
requiresRpcAndNotReady={requiresRpcAndNotReady}
processType={rpcProcessType}
tooltipTitle={tooltipTitle}
>
<span>
{isIconButton ? (
Expand All @@ -142,7 +155,7 @@ export default function IpcInvokeButton<T>({
/>
)}
</span>
</IpcNotReadyTooltip>
</IpcButtonTooltip>
);
}

Expand Down
11 changes: 11 additions & 0 deletions src/renderer/components/pages/help/RpcControlBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import { RpcProcessStateType } from 'models/rpcModel';
import { getLogsAndStringsFromRawFileString } from 'utils/parseUtils';
import InfoBox from '../../modal/swap/InfoBox';
import CliLogsBox from '../../other/RenderedCliLog';
import FolderOpenIcon from '@material-ui/icons/FolderOpen';

const useStyles = makeStyles((theme) => ({
actionsOuter: {
display: 'flex',
gap: theme.spacing(1),
alignItems: 'center',
},
}));

Expand Down Expand Up @@ -55,6 +57,15 @@ export default function RpcControlBox() {
>
Stop Daemon
</IpcInvokeButton>
<IpcInvokeButton
ipcChannel="open-data-dir-in-file-explorer"
ipcArgs={[]}
endIcon={<FolderOpenIcon />}
requiresRpc={false}
isIconButton
size="small"
tooltipTitle='Open the data directory of the Swap Daemon in your file explorer'
/>
</Box>
}
icon={null}
Expand Down

0 comments on commit 93a7bbc

Please sign in to comment.