mirror of
https://github.com/pompurin404/mihomo-party.git
synced 2024-11-16 11:42:19 +08:00
auto cleanup
This commit is contained in:
parent
9af1112103
commit
48028a43c1
|
@ -1,3 +1,7 @@
|
|||
### New Features
|
||||
|
||||
- 自动删除过期日志与更新缓存
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- 修复接管dns后自定义hosts无法删除的问题
|
||||
|
|
|
@ -20,7 +20,7 @@ import {
|
|||
defaultProfileConfig
|
||||
} from './template'
|
||||
import yaml from 'yaml'
|
||||
import { mkdir, writeFile, copyFile } from 'fs/promises'
|
||||
import { mkdir, writeFile, copyFile, rm, readdir } from 'fs/promises'
|
||||
import { existsSync } from 'fs'
|
||||
import path from 'path'
|
||||
import { startPacServer } from '../resolve/server'
|
||||
|
@ -90,6 +90,26 @@ async function initFiles(): Promise<void> {
|
|||
])
|
||||
}
|
||||
|
||||
async function cleanup(): Promise<void> {
|
||||
// update cache
|
||||
const files = await readdir(dataDir())
|
||||
for (const file of files) {
|
||||
if (file.endsWith('.exe') || file.endsWith('.dmg')) {
|
||||
await rm(path.join(dataDir(), file))
|
||||
}
|
||||
}
|
||||
// logs
|
||||
const { maxLogDays = 7 } = await getAppConfig()
|
||||
const logs = await readdir(logDir())
|
||||
for (const log of logs) {
|
||||
const date = new Date(log.split('.')[0])
|
||||
const diff = Date.now() - date.getTime()
|
||||
if (diff > maxLogDays * 24 * 60 * 60 * 1000) {
|
||||
await rm(path.join(logDir(), log))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function initDeeplink(): void {
|
||||
if (process.defaultApp) {
|
||||
if (process.argv.length >= 2) {
|
||||
|
@ -106,6 +126,7 @@ export async function init(): Promise<void> {
|
|||
await initDirs()
|
||||
await initConfig()
|
||||
await initFiles()
|
||||
await cleanup()
|
||||
await startPacServer()
|
||||
const { sysProxy } = await getAppConfig()
|
||||
await triggerSysProxy(sysProxy.enable)
|
||||
|
|
|
@ -3,6 +3,7 @@ export const defaultConfig: IAppConfig = {
|
|||
silentStart: false,
|
||||
appTheme: 'system',
|
||||
proxyInTray: true,
|
||||
maxLogDays: 7,
|
||||
proxyDisplayMode: 'simple',
|
||||
proxyDisplayOrder: 'default',
|
||||
autoCheckUpdate: true,
|
||||
|
|
|
@ -17,7 +17,7 @@ const CoreMap = {
|
|||
|
||||
const Mihomo: React.FC = () => {
|
||||
const { appConfig, patchAppConfig } = useAppConfig()
|
||||
const { core = 'mihomo' } = appConfig || {}
|
||||
const { core = 'mihomo', maxLogDays = 7 } = appConfig || {}
|
||||
const { controledMihomoConfig, patchControledMihomoConfig } = useControledMihomoConfig()
|
||||
const {
|
||||
ipv6,
|
||||
|
@ -340,6 +340,17 @@ const Mihomo: React.FC = () => {
|
|||
}}
|
||||
/>
|
||||
</SettingItem>
|
||||
<SettingItem title="日志保留天数" divider>
|
||||
<Input
|
||||
size="sm"
|
||||
type="number"
|
||||
className="w-[100px]"
|
||||
value={maxLogDays.toString()}
|
||||
onValueChange={(v) => {
|
||||
patchAppConfig({ maxLogDays: parseInt(v) })
|
||||
}}
|
||||
/>
|
||||
</SettingItem>
|
||||
<SettingItem title="日志等级" divider>
|
||||
<Select
|
||||
className="w-[100px]"
|
||||
|
|
3
src/shared/types.d.ts
vendored
3
src/shared/types.d.ts
vendored
|
@ -214,7 +214,7 @@ interface IAppConfig {
|
|||
core: 'mihomo' | 'mihomo-alpha'
|
||||
proxyDisplayMode: 'simple' | 'full'
|
||||
proxyDisplayOrder: 'default' | 'delay' | 'name'
|
||||
envType: 'bash' | 'cmd' | 'powershell'
|
||||
envType?: 'bash' | 'cmd' | 'powershell'
|
||||
proxyInTray: boolean
|
||||
siderOrder: string[]
|
||||
appTheme: AppTheme
|
||||
|
@ -222,6 +222,7 @@ interface IAppConfig {
|
|||
silentStart: boolean
|
||||
autoCloseConnection: boolean
|
||||
sysProxy: ISysProxyConfig
|
||||
maxLogDays: number
|
||||
userAgent?: string
|
||||
delayTestUrl?: string
|
||||
delayTestTimeout?: number
|
||||
|
|
Loading…
Reference in New Issue
Block a user