mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 13:10:30 +08:00
support auto quit without core
This commit is contained in:
parent
24f819184d
commit
dfdf044b48
@ -4,9 +4,4 @@
|
|||||||
|
|
||||||
### New Features
|
### New Features
|
||||||
|
|
||||||
- 添加交互式使用指南
|
- 支持自动开启轻量模式
|
||||||
|
|
||||||
### Bug Fixes
|
|
||||||
|
|
||||||
- 修复 MacOS 无法退出全屏的问题
|
|
||||||
- 修复设置页面的样式错误问题
|
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import { registerIpcMainHandlers } from './utils/ipc'
|
|||||||
import windowStateKeeper from 'electron-window-state'
|
import windowStateKeeper from 'electron-window-state'
|
||||||
import { app, shell, BrowserWindow, Menu, dialog, Notification } from 'electron'
|
import { app, shell, BrowserWindow, Menu, dialog, Notification } from 'electron'
|
||||||
import { addProfileItem, getAppConfig } from './config'
|
import { addProfileItem, getAppConfig } from './config'
|
||||||
import { startCore, stopCore } from './core/manager'
|
import { quitWithoutCore, startCore, stopCore } from './core/manager'
|
||||||
import { triggerSysProxy } from './sys/sysproxy'
|
import { triggerSysProxy } from './sys/sysproxy'
|
||||||
import icon from '../../resources/icon.png?asset'
|
import icon from '../../resources/icon.png?asset'
|
||||||
import { createTray } from './resolve/tray'
|
import { createTray } from './resolve/tray'
|
||||||
@ -17,6 +17,7 @@ import { existsSync, writeFileSync } from 'fs'
|
|||||||
import { taskDir } from './utils/dirs'
|
import { taskDir } from './utils/dirs'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
|
|
||||||
|
let quitTimeout: NodeJS.Timeout | null = null
|
||||||
export let mainWindow: BrowserWindow | null = null
|
export let mainWindow: BrowserWindow | null = null
|
||||||
if (process.platform === 'win32' && !is.dev) {
|
if (process.platform === 'win32' && !is.dev) {
|
||||||
try {
|
try {
|
||||||
@ -97,7 +98,6 @@ app.whenReady().then(async () => {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
dialog.showErrorBox('内核启动出错', `${e}`)
|
dialog.showErrorBox('内核启动出错', `${e}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default open or close DevTools by F12 in development
|
// Default open or close DevTools by F12 in development
|
||||||
// and ignore CommandOrControl + R in production.
|
// and ignore CommandOrControl + R in production.
|
||||||
// see https://github.com/alex8088/electron-toolkit/tree/master/packages/utils
|
// see https://github.com/alex8088/electron-toolkit/tree/master/packages/utils
|
||||||
@ -175,8 +175,23 @@ export async function createWindow(): Promise<void> {
|
|||||||
})
|
})
|
||||||
mainWindowState.manage(mainWindow)
|
mainWindowState.manage(mainWindow)
|
||||||
mainWindow.on('ready-to-show', async () => {
|
mainWindow.on('ready-to-show', async () => {
|
||||||
const { silentStart } = await getAppConfig()
|
const {
|
||||||
|
silentStart = false,
|
||||||
|
autoQuitWithoutCore = false,
|
||||||
|
autoQuitWithoutCoreDelay = 60
|
||||||
|
} = await getAppConfig()
|
||||||
|
if (autoQuitWithoutCore && !mainWindow?.isVisible()) {
|
||||||
|
if (quitTimeout) {
|
||||||
|
clearTimeout(quitTimeout)
|
||||||
|
}
|
||||||
|
quitTimeout = setTimeout(async () => {
|
||||||
|
await quitWithoutCore()
|
||||||
|
}, autoQuitWithoutCoreDelay * 1000)
|
||||||
|
}
|
||||||
if (!silentStart) {
|
if (!silentStart) {
|
||||||
|
if (quitTimeout) {
|
||||||
|
clearTimeout(quitTimeout)
|
||||||
|
}
|
||||||
mainWindow?.show()
|
mainWindow?.show()
|
||||||
mainWindow?.focusOnWebView()
|
mainWindow?.focusOnWebView()
|
||||||
}
|
}
|
||||||
@ -185,9 +200,18 @@ export async function createWindow(): Promise<void> {
|
|||||||
mainWindow?.webContents.reload()
|
mainWindow?.webContents.reload()
|
||||||
})
|
})
|
||||||
|
|
||||||
mainWindow.on('close', (event) => {
|
mainWindow.on('close', async (event) => {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
mainWindow?.hide()
|
mainWindow?.hide()
|
||||||
|
const { autoQuitWithoutCore = false, autoQuitWithoutCoreDelay = 60 } = await getAppConfig()
|
||||||
|
if (autoQuitWithoutCore) {
|
||||||
|
if (quitTimeout) {
|
||||||
|
clearTimeout(quitTimeout)
|
||||||
|
}
|
||||||
|
quitTimeout = setTimeout(async () => {
|
||||||
|
await quitWithoutCore()
|
||||||
|
}, autoQuitWithoutCoreDelay * 1000)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
mainWindow.webContents.setWindowOpenHandler((details) => {
|
mainWindow.webContents.setWindowOpenHandler((details) => {
|
||||||
@ -206,6 +230,9 @@ export async function createWindow(): Promise<void> {
|
|||||||
|
|
||||||
export function showMainWindow(): void {
|
export function showMainWindow(): void {
|
||||||
if (mainWindow) {
|
if (mainWindow) {
|
||||||
|
if (quitTimeout) {
|
||||||
|
clearTimeout(quitTimeout)
|
||||||
|
}
|
||||||
mainWindow.show()
|
mainWindow.show()
|
||||||
mainWindow.focusOnWebView()
|
mainWindow.focusOnWebView()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import React, { Key, useState } from 'react'
|
import React, { Key, useState } from '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 { Button, Input, Select, SelectItem, Switch, Tab, Tabs } from '@nextui-org/react'
|
import { Button, Input, Select, SelectItem, Switch, Tab, Tabs, Tooltip } from '@nextui-org/react'
|
||||||
import { BiCopy } from 'react-icons/bi'
|
import { BiCopy } from 'react-icons/bi'
|
||||||
import useSWR from 'swr'
|
import useSWR from 'swr'
|
||||||
import {
|
import {
|
||||||
@ -17,6 +17,7 @@ import { useAppConfig } from '@renderer/hooks/use-app-config'
|
|||||||
import { platform } from '@renderer/utils/init'
|
import { platform } from '@renderer/utils/init'
|
||||||
import { useTheme } from 'next-themes'
|
import { useTheme } from 'next-themes'
|
||||||
import debounce from '@renderer/utils/debounce'
|
import debounce from '@renderer/utils/debounce'
|
||||||
|
import { IoIosHelpCircle } from 'react-icons/io'
|
||||||
|
|
||||||
const GeneralConfig: React.FC = () => {
|
const GeneralConfig: React.FC = () => {
|
||||||
const { data: enable, mutate: mutateEnable } = useSWR('checkAutoRun', checkAutoRun)
|
const { data: enable, mutate: mutateEnable } = useSWR('checkAutoRun', checkAutoRun)
|
||||||
@ -29,6 +30,8 @@ const GeneralConfig: React.FC = () => {
|
|||||||
proxyInTray = true,
|
proxyInTray = true,
|
||||||
useWindowFrame = false,
|
useWindowFrame = false,
|
||||||
useSubStore = true,
|
useSubStore = true,
|
||||||
|
autoQuitWithoutCore = false,
|
||||||
|
autoQuitWithoutCoreDelay = 60,
|
||||||
useCustomSubStore = false,
|
useCustomSubStore = false,
|
||||||
customSubStoreUrl,
|
customSubStoreUrl,
|
||||||
envType = platform === 'win32' ? 'powershell' : 'bash',
|
envType = platform === 'win32' ? 'powershell' : 'bash',
|
||||||
@ -103,6 +106,42 @@ const GeneralConfig: React.FC = () => {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</SettingItem>
|
</SettingItem>
|
||||||
|
<SettingItem
|
||||||
|
title="自动开启轻量模式"
|
||||||
|
actions={
|
||||||
|
<Tooltip content="关闭窗口指定时间后自动进入轻量模式">
|
||||||
|
<Button isIconOnly size="sm" variant="light">
|
||||||
|
<IoIosHelpCircle className="text-lg" />
|
||||||
|
</Button>
|
||||||
|
</Tooltip>
|
||||||
|
}
|
||||||
|
divider
|
||||||
|
>
|
||||||
|
<Switch
|
||||||
|
size="sm"
|
||||||
|
isSelected={autoQuitWithoutCore}
|
||||||
|
onValueChange={(v) => {
|
||||||
|
patchAppConfig({ autoQuitWithoutCore: v })
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</SettingItem>
|
||||||
|
{autoQuitWithoutCore && (
|
||||||
|
<SettingItem title="自动开启轻量模式延时" divider>
|
||||||
|
<Input
|
||||||
|
size="sm"
|
||||||
|
className="w-[100px]"
|
||||||
|
type="number"
|
||||||
|
endContent="秒"
|
||||||
|
value={autoQuitWithoutCoreDelay.toString()}
|
||||||
|
onValueChange={async (v: string) => {
|
||||||
|
let num = parseInt(v)
|
||||||
|
if (isNaN(num)) num = 5
|
||||||
|
if (num < 5) num = 5
|
||||||
|
await patchAppConfig({ autoQuitWithoutCoreDelay: num })
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</SettingItem>
|
||||||
|
)}
|
||||||
<SettingItem
|
<SettingItem
|
||||||
title="复制环境变量类型"
|
title="复制环境变量类型"
|
||||||
actions={
|
actions={
|
||||||
|
|||||||
2
src/shared/types.d.ts
vendored
2
src/shared/types.d.ts
vendored
@ -234,6 +234,8 @@ interface IAppConfig {
|
|||||||
sysproxyCardStatus?: CardStatus
|
sysproxyCardStatus?: CardStatus
|
||||||
tunCardStatus?: CardStatus
|
tunCardStatus?: CardStatus
|
||||||
useSubStore: boolean
|
useSubStore: boolean
|
||||||
|
autoQuitWithoutCore?: boolean
|
||||||
|
autoQuitWithoutCoreDelay?: number
|
||||||
useCustomSubStore?: boolean
|
useCustomSubStore?: boolean
|
||||||
customSubStoreUrl?: string
|
customSubStoreUrl?: string
|
||||||
autoSetDNS?: boolean
|
autoSetDNS?: boolean
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user