Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: print v4 desktop env path #4922

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions packages/desktop/src-electron/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,29 @@ function createMainWindow() {
event.returnValue = !!result;
});

ipcMain.on('app/getEnvPath', (event) => {
const home: string = app.getPath('home');
const appData: string = app.getPath('appData');
const userData: string = app.getPath('userData');
// const sessionData: string = app.getPath('sessionData');
const exe: string = app.getPath('exe');
const temp: string = app.getPath('temp');
const module: string = app.getPath('module');
const desktop: string = app.getPath('desktop');
const appPath: string = app.getAppPath();
event.returnValue = {
userData,
appPath,
home,
appData,
// sessionData,
exe,
temp,
module,
desktop,
};
});

ipcMain.on('app/promptTouchID', async (event, msg: string) => {
try {
await systemPreferences.promptTouchID(msg);
Expand Down
5 changes: 5 additions & 0 deletions packages/desktop/src-electron/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export type DesktopAPI = {
toggleMaximizeWindow: () => void;
onAppState: (cb: (state: IDesktopAppState) => void) => () => void;
canPromptTouchID: () => boolean;
getEnvPath: () => { [key: string]: string };
promptTouchID: (msg: string) => Promise<{ success: boolean; error?: string }>;
secureSetItemAsync: (key: string, value: string) => Promise<void>;
secureGetItemAsync: (key: string) => Promise<string | null>;
Expand Down Expand Up @@ -168,6 +169,10 @@ const desktopApi = {
toggleMaximizeWindow: () => ipcRenderer.send('app/toggleMaximizeWindow'),
canPromptTouchID: () =>
ipcRenderer.sendSync('app/canPromptTouchID') as boolean,
getEnvPath: () =>
ipcRenderer.sendSync('app/getEnvPath') as {
[key: string]: string;
},
promptTouchID: async (
msg: string,
): Promise<{ success: boolean; error?: string }> =>
Expand Down
53 changes: 48 additions & 5 deletions packages/kit/src/views/Me/DevSetting/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { FC } from 'react';
import { useCallback, useEffect, useMemo } from 'react';

import { useNavigation } from '@react-navigation/core';
Expand All @@ -7,13 +8,15 @@ import {
Box,
Button,
Container,
Dialog,
HStack,
Pressable,
Select,
Switch,
Text,
ToastManager,
Typography,
VStack,
useTheme,
} from '@onekeyhq/components';
import { shortenAddress } from '@onekeyhq/components/src/utils';
Expand Down Expand Up @@ -47,13 +50,10 @@ import platformEnv from '@onekeyhq/shared/src/platformEnv';
import { NetworkAccountSelectorTrigger } from '../../../components/NetworkAccountSelector';
import { ModalRoutes, RootRoutes } from '../../../routes/routesEnum';
import { EAccountSelectorMode } from '../../../store/reducers/reducerAccountSelector';
import { showDialog } from '../../../utils/overlayUtils';
import { MonitorRoutes } from '../../Monitor/types';

import {
requestsInterceptTest,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
requestsInterceptTest2,
} from './requestsInterceptTest';
import { requestsInterceptTest } from './requestsInterceptTest';

interface IOneKeyPerfCheckPayload {
testID?: string;
Expand Down Expand Up @@ -90,6 +90,30 @@ function usePerfCheck({ enablePerfCheck }: { enablePerfCheck?: boolean }) {
}
const emptyObj: any = Object.freeze({});

const DialogGetEnvPath: FC<{
message: string;
onClose?: () => void;
onConfirm?: () => void;
}> = ({ onConfirm, message, onClose }) => {
const intl = useIntl();
return (
<Dialog
visible
onClose={onClose}
contentProps={{
title: 'getEnvPath',
contentElement: (
<VStack>
<Typography.Body2 textAlign="center" wordBreak="break-all">
{message}
</Typography.Body2>
</VStack>
),
}}
/>
);
};

export const DevSettingSection = () => {
const { themeVariant } = useTheme();
const { devMode, pushNotification, instanceId } = useSettings();
Expand Down Expand Up @@ -387,6 +411,25 @@ export const DevSettingSection = () => {
}}
/>
</Container.Item>

<Container.Item
title="Print Env Path in Desktop"
titleColor="text-critical"
>
<Button
size="xs"
onPress={() => {
const envPath = window?.desktopApi.getEnvPath();
console.log(envPath);
showDialog(
<DialogGetEnvPath message={JSON.stringify(envPath, null, 2)} />,
);
}}
>
getEnvPath
</Button>
</Container.Item>

<Container.Item
title="Request intercept check"
titleColor="text-critical"
Expand Down
Loading