From 93a7bbcfe2c9a18aa217af2feefa1ea09a0a3427 Mon Sep 17 00:00:00 2001
From: binarybaron <86064887+binarybaron@users.noreply.github.com>
Date: Thu, 27 Jun 2024 14:23:32 +0200
Subject: [PATCH] feat: Add Button to open data directory to RpcControlBox
---
src/main/main.ts | 6 +++-
src/renderer/components/IpcInvokeButton.tsx | 29 ++++++++++++++-----
.../components/pages/help/RpcControlBox.tsx | 11 +++++++
3 files changed, 37 insertions(+), 9 deletions(-)
diff --git a/src/main/main.ts b/src/main/main.ts
index c6ec5b3..9631aa8 100644
--- a/src/main/main.ts
+++ b/src/main/main.ts
@@ -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';
@@ -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,
diff --git a/src/renderer/components/IpcInvokeButton.tsx b/src/renderer/components/IpcInvokeButton.tsx
index 03324f9..3158a66 100644
--- a/src/renderer/components/IpcInvokeButton.tsx
+++ b/src/renderer/components/IpcInvokeButton.tsx
@@ -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 (
+
+ {children}
+
+ );
+ }
+
+ const getMessage = () => {
+ if (!requiresRpcAndNotReady) return '';
switch (processType) {
case RpcProcessStateType.LISTENING_FOR_CONNECTIONS:
@@ -55,6 +65,7 @@ interface IpcInvokeButtonProps {
requiresRpc?: boolean;
disabled?: boolean;
displayErrorSnackbar?: boolean;
+ tooltipTitle?: string;
}
const DELAY_BEFORE_SHOWING_LOADING_MS = 0;
@@ -71,6 +82,7 @@ export default function IpcInvokeButton({
isIconButton,
requiresRpc,
displayErrorSnackbar,
+ tooltipTitle,
...rest
}: IpcInvokeButtonProps & ButtonProps) {
const { enqueueSnackbar } = useSnackbar();
@@ -120,9 +132,10 @@ export default function IpcInvokeButton({
const isDisabled = disabled || requiresRpcAndNotReady || isLoading;
return (
-
{isIconButton ? (
@@ -142,7 +155,7 @@ export default function IpcInvokeButton({
/>
)}
-
+
);
}
diff --git a/src/renderer/components/pages/help/RpcControlBox.tsx b/src/renderer/components/pages/help/RpcControlBox.tsx
index 42609af..0ce538f 100644
--- a/src/renderer/components/pages/help/RpcControlBox.tsx
+++ b/src/renderer/components/pages/help/RpcControlBox.tsx
@@ -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',
},
}));
@@ -55,6 +57,15 @@ export default function RpcControlBox() {
>
Stop Daemon
+ }
+ requiresRpc={false}
+ isIconButton
+ size="small"
+ tooltipTitle='Open the data directory of the Swap Daemon in your file explorer'
+ />
}
icon={null}