diff --git a/src/main/utils/ipc.ts b/src/main/utils/ipc.ts index 7ee3cd3..fea0006 100644 --- a/src/main/utils/ipc.ts +++ b/src/main/utils/ipc.ts @@ -66,6 +66,9 @@ import { copyEnv } from '../resolve/tray' import { registerShortcut } from '../resolve/shortcut' import { mainWindow } from '..' import { subStoreCollections, subStoreSubs } from '../core/subStoreApi' +import { logDir } from './dirs' +import path from 'path' +import v8 from 'v8' function ipcErrorWrapper( // eslint-disable-next-line @typescript-eslint/no-explicit-any fn: (...args: any[]) => Promise // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -190,6 +193,12 @@ export function registerIpcMainHandlers(): void { return mainWindow?.isAlwaysOnTop() }) ipcMain.handle('openFile', (_e, type, id, ext) => openFile(type, id, ext)) + ipcMain.handle('openDevTools', () => { + mainWindow?.webContents.openDevTools() + }) + ipcMain.handle('createHeapSnapshot', () => { + v8.writeHeapSnapshot(path.join(logDir(), `${Date.now()}.heapsnapshot`)) + }) ipcMain.handle('copyEnv', ipcErrorWrapper(copyEnv)) ipcMain.handle('alert', (_e, msg) => { dialog.showErrorBox('Mihomo Party', msg) diff --git a/src/renderer/src/components/settings/actions.tsx b/src/renderer/src/components/settings/actions.tsx index 60356be..e446486 100644 --- a/src/renderer/src/components/settings/actions.tsx +++ b/src/renderer/src/components/settings/actions.tsx @@ -1,7 +1,7 @@ import { Button, Tooltip } from '@nextui-org/react' import SettingCard from '../base/base-setting-card' import SettingItem from '../base/base-setting-item' -import { checkUpdate, quitApp, quitWithoutCore } from '@renderer/utils/ipc' +import { checkUpdate, createHeapSnapshot, quitApp, quitWithoutCore } from '@renderer/utils/ipc' import { useState } from 'react' import UpdaterModal from '../updater/updater-modal' import { version } from '@renderer/utils/init' @@ -54,6 +54,21 @@ const Actions: React.FC = () => { 检查更新 + + + + } + divider + > + + { document.addEventListener('keydown', (e) => { if (platform !== 'darwin' && e.ctrlKey && e.key === 'q') { @@ -29,6 +31,14 @@ init().then(() => { e.preventDefault() window.close() } + if (e.key === 'F12') { + e.preventDefault() + F12Count++ + if (F12Count >= 5) { + openDevTools() + F12Count = 0 + } + } }) ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render( diff --git a/src/renderer/src/utils/init.ts b/src/renderer/src/utils/init.ts index 13ff18f..97b9412 100644 --- a/src/renderer/src/utils/init.ts +++ b/src/renderer/src/utils/init.ts @@ -1,20 +1,20 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import { getPlatform, getVersion } from './ipc' -const originError = console.error -const originWarn = console.warn -console.error = function (...args: any[]): void { - if (typeof args[0] === 'string' && args[0].includes('validateDOMNesting')) { - return - } - originError.call(console, args) -} -console.warn = function (...args): void { - if (typeof args[0] === 'string' && args[0].includes('aria-label')) { - return - } - originWarn.call(console, args) -} +// const originError = console.error +// const originWarn = console.warn +// console.error = function (...args: any[]): void { +// if (typeof args[0] === 'string' && args[0].includes('validateDOMNesting')) { +// return +// } +// originError.call(console, args) +// } +// console.warn = function (...args): void { +// if (typeof args[0] === 'string' && args[0].includes('aria-label')) { +// return +// } +// originWarn.call(console, args) +// } export let platform: NodeJS.Platform export let version: string diff --git a/src/renderer/src/utils/ipc.ts b/src/renderer/src/utils/ipc.ts index 756dc09..f6914ef 100644 --- a/src/renderer/src/utils/ipc.ts +++ b/src/renderer/src/utils/ipc.ts @@ -323,6 +323,14 @@ export async function openFile( return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('openFile', type, id, ext)) } +export async function openDevTools(): Promise { + return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('openDevTools')) +} + +export async function createHeapSnapshot(): Promise { + return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('createHeapSnapshot')) +} + export async function registerShortcut( oldShortcut: string, newShortcut: string,