diff --git a/apps/main/src/lib/cleaner.ts b/apps/main/src/lib/cleaner.ts index c761aa6583..325e52d8b1 100644 --- a/apps/main/src/lib/cleaner.ts +++ b/apps/main/src/lib/cleaner.ts @@ -69,7 +69,9 @@ export const getCacheSize = async () => { const cachePath = path.join(app.getPath("userData"), "cache") // Size is in bytes - const sizeInBytes = await fastFolderSizeAsync(cachePath) + const sizeInBytes = await fastFolderSizeAsync(cachePath).catch((error) => { + logger.error(error) + }) return sizeInBytes || 0 } diff --git a/apps/main/src/tipc/app.ts b/apps/main/src/tipc/app.ts index 3415a59ca2..e064653a80 100644 --- a/apps/main/src/tipc/app.ts +++ b/apps/main/src/tipc/app.ts @@ -5,7 +5,7 @@ import path from "node:path" import { getRendererHandlers } from "@egoist/tipc/main" import { callWindowExpose } from "@follow/shared/bridge" import type { BrowserWindow } from "electron" -import { app, clipboard, dialog, screen } from "electron" +import { app, clipboard, dialog, screen, shell } from "electron" import { registerMenuAndContextMenu } from "~/init" import { clearAllData, getCacheSize } from "~/lib/cleaner" @@ -275,13 +275,34 @@ ${content} getCacheSize: t.procedure.action(async () => { return getCacheSize() }), + openCacheFolder: t.procedure.action(async () => { + const dir = path.join(app.getPath("userData"), "cache") + shell.openPath(dir) + }), getCacheLimit: t.procedure.action(async () => { return store.get(StoreKey.CacheSizeLimit) }), clearCache: t.procedure.action(async () => { - const cachePath = path.join(app.getPath("userData"), "cache") - await fsp.rm(cachePath, { recursive: true, force: true }) + const cachePath = path.join(app.getPath("userData"), "cache", "Cache_Data") + if (process.platform === "win32") { + // Request elevation on Windows + + try { + // Create a bat file to delete cache with elevated privileges + const batPath = path.join(app.getPath("temp"), "clear_cache.bat") + await fsp.writeFile(batPath, `@echo off\nrd /s /q "${cachePath}"\ndel "%~f0"`, "utf-8") + + // Execute the bat file with admin privileges + await shell.openPath(batPath) + return + } catch (err) { + logger.error("Failed to clear cache with elevation", { error: err }) + } + } + await fsp.rm(cachePath, { recursive: true, force: true }).catch(() => { + logger.error("Failed to clear cache") + }) }), limitCacheSize: t.procedure.input().action(async ({ input }) => { diff --git a/apps/renderer/index.html b/apps/renderer/index.html index 97cb70803d..188bd8d37f 100644 --- a/apps/renderer/index.html +++ b/apps/renderer/index.html @@ -63,7 +63,7 @@
-
+