mirror of
https://github.com/pompurin404/mihomo-party.git
synced 2024-11-16 03:32:17 +08:00
support create heapsnapshot
This commit is contained in:
parent
714352f5b7
commit
08ba7164e1
|
@ -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<T>( // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
fn: (...args: any[]) => Promise<T> // 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)
|
||||
|
|
|
@ -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 = () => {
|
|||
检查更新
|
||||
</Button>
|
||||
</SettingItem>
|
||||
<SettingItem
|
||||
title="创建堆快照"
|
||||
actions={
|
||||
<Tooltip content="创建主进程堆快照,用于排查内存问题">
|
||||
<Button isIconOnly size="sm" variant="light">
|
||||
<IoIosHelpCircle className="text-lg" />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
}
|
||||
divider
|
||||
>
|
||||
<Button size="sm" onPress={createHeapSnapshot}>
|
||||
创建堆快照
|
||||
</Button>
|
||||
</SettingItem>
|
||||
<SettingItem
|
||||
title="轻量模式"
|
||||
actions={
|
||||
|
|
|
@ -7,7 +7,7 @@ import { init, platform } from '@renderer/utils/init'
|
|||
import '@renderer/assets/main.css'
|
||||
import App from '@renderer/App'
|
||||
import BaseErrorBoundary from './components/base/base-error-boundary'
|
||||
import { quitApp } from './utils/ipc'
|
||||
import { openDevTools, quitApp } from './utils/ipc'
|
||||
import { AppConfigProvider } from './hooks/use-app-config'
|
||||
import { ControledMihomoConfigProvider } from './hooks/use-controled-mihomo-config'
|
||||
import { OverrideConfigProvider } from './hooks/use-override-config'
|
||||
|
@ -15,6 +15,8 @@ import { ProfileConfigProvider } from './hooks/use-profile-config'
|
|||
import { RulesProvider } from './hooks/use-rules'
|
||||
import { GroupsProvider } from './hooks/use-groups'
|
||||
|
||||
let F12Count = 0
|
||||
|
||||
init().then(() => {
|
||||
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(
|
||||
<React.StrictMode>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -323,6 +323,14 @@ export async function openFile(
|
|||
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('openFile', type, id, ext))
|
||||
}
|
||||
|
||||
export async function openDevTools(): Promise<void> {
|
||||
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('openDevTools'))
|
||||
}
|
||||
|
||||
export async function createHeapSnapshot(): Promise<void> {
|
||||
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('createHeapSnapshot'))
|
||||
}
|
||||
|
||||
export async function registerShortcut(
|
||||
oldShortcut: string,
|
||||
newShortcut: string,
|
||||
|
|
Loading…
Reference in New Issue
Block a user