@@ -9,7 +9,7 @@ import { app, nativeTheme, Notification, shell } from "electron"
|
||||
import contextMenu from "electron-context-menu"
|
||||
|
||||
import { getIconPath } from "./helper"
|
||||
import { clearCacheCronJob } from "./lib/cleaner"
|
||||
import { checkAndCleanCodeCache, clearCacheCronJob } from "./lib/cleaner"
|
||||
import { t } from "./lib/i18n"
|
||||
import { store } from "./lib/store"
|
||||
import { updateNotificationsToken } from "./lib/user"
|
||||
@@ -61,6 +61,7 @@ export const initializeAppStage1 = () => {
|
||||
|
||||
registerPushNotifications()
|
||||
clearCacheCronJob()
|
||||
checkAndCleanCodeCache()
|
||||
}
|
||||
|
||||
let contextMenuDisposer: () => void
|
||||
|
||||
@@ -144,3 +144,25 @@ export const clearCacheCronJob = () => {
|
||||
timer = clearInterval(timer)
|
||||
}
|
||||
}
|
||||
|
||||
export const checkAndCleanCodeCache = async () => {
|
||||
const cachePath = path.join(app.getPath("userData"), "Code Cache")
|
||||
|
||||
const size = await fastFolderSizeAsync(cachePath).catch((error) => {
|
||||
logger.error(error)
|
||||
})
|
||||
|
||||
if (!size) return
|
||||
|
||||
const threshold = 1024 * 1024 * 100 // 100MB
|
||||
if (size > threshold) {
|
||||
await fsp
|
||||
.rm(cachePath, { force: true, recursive: true })
|
||||
.then(() => {
|
||||
logger.info(`Cleaned ${size} bytes code cache`)
|
||||
})
|
||||
.catch((error) => {
|
||||
logger.error(`clean code cache failed: ${error.message}`)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user