mirror of
https://github.com/pompurin404/mihomo-party.git
synced 2024-11-16 11:42:19 +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 { registerShortcut } from '../resolve/shortcut'
|
||||||
import { mainWindow } from '..'
|
import { mainWindow } from '..'
|
||||||
import { subStoreCollections, subStoreSubs } from '../core/subStoreApi'
|
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
|
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
|
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()
|
return mainWindow?.isAlwaysOnTop()
|
||||||
})
|
})
|
||||||
ipcMain.handle('openFile', (_e, type, id, ext) => openFile(type, id, ext))
|
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('copyEnv', ipcErrorWrapper(copyEnv))
|
||||||
ipcMain.handle('alert', (_e, msg) => {
|
ipcMain.handle('alert', (_e, msg) => {
|
||||||
dialog.showErrorBox('Mihomo Party', msg)
|
dialog.showErrorBox('Mihomo Party', msg)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { Button, Tooltip } from '@nextui-org/react'
|
import { Button, Tooltip } from '@nextui-org/react'
|
||||||
import SettingCard from '../base/base-setting-card'
|
import SettingCard from '../base/base-setting-card'
|
||||||
import SettingItem from '../base/base-setting-item'
|
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 { useState } from 'react'
|
||||||
import UpdaterModal from '../updater/updater-modal'
|
import UpdaterModal from '../updater/updater-modal'
|
||||||
import { version } from '@renderer/utils/init'
|
import { version } from '@renderer/utils/init'
|
||||||
|
@ -54,6 +54,21 @@ const Actions: React.FC = () => {
|
||||||
检查更新
|
检查更新
|
||||||
</Button>
|
</Button>
|
||||||
</SettingItem>
|
</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
|
<SettingItem
|
||||||
title="轻量模式"
|
title="轻量模式"
|
||||||
actions={
|
actions={
|
||||||
|
|
|
@ -7,7 +7,7 @@ import { init, platform } from '@renderer/utils/init'
|
||||||
import '@renderer/assets/main.css'
|
import '@renderer/assets/main.css'
|
||||||
import App from '@renderer/App'
|
import App from '@renderer/App'
|
||||||
import BaseErrorBoundary from './components/base/base-error-boundary'
|
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 { AppConfigProvider } from './hooks/use-app-config'
|
||||||
import { ControledMihomoConfigProvider } from './hooks/use-controled-mihomo-config'
|
import { ControledMihomoConfigProvider } from './hooks/use-controled-mihomo-config'
|
||||||
import { OverrideConfigProvider } from './hooks/use-override-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 { RulesProvider } from './hooks/use-rules'
|
||||||
import { GroupsProvider } from './hooks/use-groups'
|
import { GroupsProvider } from './hooks/use-groups'
|
||||||
|
|
||||||
|
let F12Count = 0
|
||||||
|
|
||||||
init().then(() => {
|
init().then(() => {
|
||||||
document.addEventListener('keydown', (e) => {
|
document.addEventListener('keydown', (e) => {
|
||||||
if (platform !== 'darwin' && e.ctrlKey && e.key === 'q') {
|
if (platform !== 'darwin' && e.ctrlKey && e.key === 'q') {
|
||||||
|
@ -29,6 +31,14 @@ init().then(() => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
window.close()
|
window.close()
|
||||||
}
|
}
|
||||||
|
if (e.key === 'F12') {
|
||||||
|
e.preventDefault()
|
||||||
|
F12Count++
|
||||||
|
if (F12Count >= 5) {
|
||||||
|
openDevTools()
|
||||||
|
F12Count = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
|
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
|
||||||
<React.StrictMode>
|
<React.StrictMode>
|
||||||
|
|
|
@ -1,20 +1,20 @@
|
||||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
|
|
||||||
import { getPlatform, getVersion } from './ipc'
|
import { getPlatform, getVersion } from './ipc'
|
||||||
const originError = console.error
|
// const originError = console.error
|
||||||
const originWarn = console.warn
|
// const originWarn = console.warn
|
||||||
console.error = function (...args: any[]): void {
|
// console.error = function (...args: any[]): void {
|
||||||
if (typeof args[0] === 'string' && args[0].includes('validateDOMNesting')) {
|
// if (typeof args[0] === 'string' && args[0].includes('validateDOMNesting')) {
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
originError.call(console, args)
|
// originError.call(console, args)
|
||||||
}
|
// }
|
||||||
console.warn = function (...args): void {
|
// console.warn = function (...args): void {
|
||||||
if (typeof args[0] === 'string' && args[0].includes('aria-label')) {
|
// if (typeof args[0] === 'string' && args[0].includes('aria-label')) {
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
originWarn.call(console, args)
|
// originWarn.call(console, args)
|
||||||
}
|
// }
|
||||||
|
|
||||||
export let platform: NodeJS.Platform
|
export let platform: NodeJS.Platform
|
||||||
export let version: string
|
export let version: string
|
||||||
|
|
|
@ -323,6 +323,14 @@ export async function openFile(
|
||||||
return ipcErrorWrapper(await window.electron.ipcRenderer.invoke('openFile', type, id, ext))
|
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(
|
export async function registerShortcut(
|
||||||
oldShortcut: string,
|
oldShortcut: string,
|
||||||
newShortcut: string,
|
newShortcut: string,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user