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
|
### Bug Fixes
|
||||||
|
|
||||||
- 修复接管dns后自定义hosts无法删除的问题
|
- 修复接管dns后自定义hosts无法删除的问题
|
||||||
|
|
|
@ -20,7 +20,7 @@ import {
|
||||||
defaultProfileConfig
|
defaultProfileConfig
|
||||||
} from './template'
|
} from './template'
|
||||||
import yaml from 'yaml'
|
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 { existsSync } from 'fs'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import { startPacServer } from '../resolve/server'
|
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 {
|
function initDeeplink(): void {
|
||||||
if (process.defaultApp) {
|
if (process.defaultApp) {
|
||||||
if (process.argv.length >= 2) {
|
if (process.argv.length >= 2) {
|
||||||
|
@ -106,6 +126,7 @@ export async function init(): Promise<void> {
|
||||||
await initDirs()
|
await initDirs()
|
||||||
await initConfig()
|
await initConfig()
|
||||||
await initFiles()
|
await initFiles()
|
||||||
|
await cleanup()
|
||||||
await startPacServer()
|
await startPacServer()
|
||||||
const { sysProxy } = await getAppConfig()
|
const { sysProxy } = await getAppConfig()
|
||||||
await triggerSysProxy(sysProxy.enable)
|
await triggerSysProxy(sysProxy.enable)
|
||||||
|
|
|
@ -3,6 +3,7 @@ export const defaultConfig: IAppConfig = {
|
||||||
silentStart: false,
|
silentStart: false,
|
||||||
appTheme: 'system',
|
appTheme: 'system',
|
||||||
proxyInTray: true,
|
proxyInTray: true,
|
||||||
|
maxLogDays: 7,
|
||||||
proxyDisplayMode: 'simple',
|
proxyDisplayMode: 'simple',
|
||||||
proxyDisplayOrder: 'default',
|
proxyDisplayOrder: 'default',
|
||||||
autoCheckUpdate: true,
|
autoCheckUpdate: true,
|
||||||
|
|
|
@ -17,7 +17,7 @@ const CoreMap = {
|
||||||
|
|
||||||
const Mihomo: React.FC = () => {
|
const Mihomo: React.FC = () => {
|
||||||
const { appConfig, patchAppConfig } = useAppConfig()
|
const { appConfig, patchAppConfig } = useAppConfig()
|
||||||
const { core = 'mihomo' } = appConfig || {}
|
const { core = 'mihomo', maxLogDays = 7 } = appConfig || {}
|
||||||
const { controledMihomoConfig, patchControledMihomoConfig } = useControledMihomoConfig()
|
const { controledMihomoConfig, patchControledMihomoConfig } = useControledMihomoConfig()
|
||||||
const {
|
const {
|
||||||
ipv6,
|
ipv6,
|
||||||
|
@ -340,6 +340,17 @@ const Mihomo: React.FC = () => {
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</SettingItem>
|
</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>
|
<SettingItem title="日志等级" divider>
|
||||||
<Select
|
<Select
|
||||||
className="w-[100px]"
|
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'
|
core: 'mihomo' | 'mihomo-alpha'
|
||||||
proxyDisplayMode: 'simple' | 'full'
|
proxyDisplayMode: 'simple' | 'full'
|
||||||
proxyDisplayOrder: 'default' | 'delay' | 'name'
|
proxyDisplayOrder: 'default' | 'delay' | 'name'
|
||||||
envType: 'bash' | 'cmd' | 'powershell'
|
envType?: 'bash' | 'cmd' | 'powershell'
|
||||||
proxyInTray: boolean
|
proxyInTray: boolean
|
||||||
siderOrder: string[]
|
siderOrder: string[]
|
||||||
appTheme: AppTheme
|
appTheme: AppTheme
|
||||||
|
@ -222,6 +222,7 @@ interface IAppConfig {
|
||||||
silentStart: boolean
|
silentStart: boolean
|
||||||
autoCloseConnection: boolean
|
autoCloseConnection: boolean
|
||||||
sysProxy: ISysProxyConfig
|
sysProxy: ISysProxyConfig
|
||||||
|
maxLogDays: number
|
||||||
userAgent?: string
|
userAgent?: string
|
||||||
delayTestUrl?: string
|
delayTestUrl?: string
|
||||||
delayTestTimeout?: number
|
delayTestTimeout?: number
|
||||||
|
|
Loading…
Reference in New Issue
Block a user