mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-26 20:50:30 +08:00
support auto quit without core
This commit is contained in:
parent
24f819184d
commit
dfdf044b48
@ -4,9 +4,4 @@
|
||||
|
||||
### New Features
|
||||
|
||||
- 添加交互式使用指南
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- 修复 MacOS 无法退出全屏的问题
|
||||
- 修复设置页面的样式错误问题
|
||||
- 支持自动开启轻量模式
|
||||
|
||||
@ -3,7 +3,7 @@ import { registerIpcMainHandlers } from './utils/ipc'
|
||||
import windowStateKeeper from 'electron-window-state'
|
||||
import { app, shell, BrowserWindow, Menu, dialog, Notification } from 'electron'
|
||||
import { addProfileItem, getAppConfig } from './config'
|
||||
import { startCore, stopCore } from './core/manager'
|
||||
import { quitWithoutCore, startCore, stopCore } from './core/manager'
|
||||
import { triggerSysProxy } from './sys/sysproxy'
|
||||
import icon from '../../resources/icon.png?asset'
|
||||
import { createTray } from './resolve/tray'
|
||||
@ -17,6 +17,7 @@ import { existsSync, writeFileSync } from 'fs'
|
||||
import { taskDir } from './utils/dirs'
|
||||
import path from 'path'
|
||||
|
||||
let quitTimeout: NodeJS.Timeout | null = null
|
||||
export let mainWindow: BrowserWindow | null = null
|
||||
if (process.platform === 'win32' && !is.dev) {
|
||||
try {
|
||||
@ -97,7 +98,6 @@ app.whenReady().then(async () => {
|
||||
} catch (e) {
|
||||
dialog.showErrorBox('内核启动出错', `${e}`)
|
||||
}
|
||||
|
||||
// Default open or close DevTools by F12 in development
|
||||
// and ignore CommandOrControl + R in production.
|
||||
// see https://github.com/alex8088/electron-toolkit/tree/master/packages/utils
|
||||
@ -175,8 +175,23 @@ export async function createWindow(): Promise<void> {
|
||||
})
|
||||
mainWindowState.manage(mainWindow)
|
||||
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 (quitTimeout) {
|
||||
clearTimeout(quitTimeout)
|
||||
}
|
||||
mainWindow?.show()
|
||||
mainWindow?.focusOnWebView()
|
||||
}
|
||||
@ -185,9 +200,18 @@ export async function createWindow(): Promise<void> {
|
||||
mainWindow?.webContents.reload()
|
||||
})
|
||||
|
||||
mainWindow.on('close', (event) => {
|
||||
mainWindow.on('close', async (event) => {
|
||||
event.preventDefault()
|
||||
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) => {
|
||||
@ -206,6 +230,9 @@ export async function createWindow(): Promise<void> {
|
||||
|
||||
export function showMainWindow(): void {
|
||||
if (mainWindow) {
|
||||
if (quitTimeout) {
|
||||
clearTimeout(quitTimeout)
|
||||
}
|
||||
mainWindow.show()
|
||||
mainWindow.focusOnWebView()
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import React, { Key, useState } from 'react'
|
||||
import SettingCard from '../base/base-setting-card'
|
||||
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 useSWR from 'swr'
|
||||
import {
|
||||
@ -17,6 +17,7 @@ import { useAppConfig } from '@renderer/hooks/use-app-config'
|
||||
import { platform } from '@renderer/utils/init'
|
||||
import { useTheme } from 'next-themes'
|
||||
import debounce from '@renderer/utils/debounce'
|
||||
import { IoIosHelpCircle } from 'react-icons/io'
|
||||
|
||||
const GeneralConfig: React.FC = () => {
|
||||
const { data: enable, mutate: mutateEnable } = useSWR('checkAutoRun', checkAutoRun)
|
||||
@ -29,6 +30,8 @@ const GeneralConfig: React.FC = () => {
|
||||
proxyInTray = true,
|
||||
useWindowFrame = false,
|
||||
useSubStore = true,
|
||||
autoQuitWithoutCore = false,
|
||||
autoQuitWithoutCoreDelay = 60,
|
||||
useCustomSubStore = false,
|
||||
customSubStoreUrl,
|
||||
envType = platform === 'win32' ? 'powershell' : 'bash',
|
||||
@ -103,6 +106,42 @@ const GeneralConfig: React.FC = () => {
|
||||
}}
|
||||
/>
|
||||
</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
|
||||
title="复制环境变量类型"
|
||||
actions={
|
||||
|
||||
2
src/shared/types.d.ts
vendored
2
src/shared/types.d.ts
vendored
@ -234,6 +234,8 @@ interface IAppConfig {
|
||||
sysproxyCardStatus?: CardStatus
|
||||
tunCardStatus?: CardStatus
|
||||
useSubStore: boolean
|
||||
autoQuitWithoutCore?: boolean
|
||||
autoQuitWithoutCoreDelay?: number
|
||||
useCustomSubStore?: boolean
|
||||
customSubStoreUrl?: string
|
||||
autoSetDNS?: boolean
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user