瀏覽代碼

Remove custom cache directory

From discussions, it seems that it was pre-emptively added but not specifically
requested by a customer. We can bring this back later if needed, or at least
offer better options to clean it, but for now I'm pruning the IPC surface to
reduce the amount of work needed for handling contextIsolation and sandboxing.
Manav Rathi 1 年之前
父節點
當前提交
eeaa5165ab

+ 1 - 15
desktop/src/api/cache.ts

@@ -5,11 +5,7 @@ import { DiskCache } from "../services/diskCache";
 
 
 const ENTE_CACHE_DIR_NAME = "ente";
 const ENTE_CACHE_DIR_NAME = "ente";
 
 
-export const getCacheDirectory = async () => {
-    const customCacheDir = await getCustomCacheDirectory();
-    if (customCacheDir && existsSync(customCacheDir)) {
-        return customCacheDir;
-    }
+const getCacheDirectory = async () => {
     const defaultSystemCacheDir = await ipcRenderer.invoke("get-path", "cache");
     const defaultSystemCacheDir = await ipcRenderer.invoke("get-path", "cache");
     return path.join(defaultSystemCacheDir, ENTE_CACHE_DIR_NAME);
     return path.join(defaultSystemCacheDir, ENTE_CACHE_DIR_NAME);
 };
 };
@@ -40,13 +36,3 @@ export async function deleteDiskCache(cacheName: string) {
         return false;
         return false;
     }
     }
 }
 }
-
-export async function setCustomCacheDirectory(
-    directory: string,
-): Promise<void> {
-    await ipcRenderer.invoke("set-custom-cache-directory", directory);
-}
-
-async function getCustomCacheDirectory(): Promise<string> {
-    return await ipcRenderer.invoke("get-custom-cache-directory");
-}

+ 1 - 8
desktop/src/preload.ts

@@ -28,12 +28,7 @@
  */
  */
 
 
 import { contextBridge } from "electron";
 import { contextBridge } from "electron";
-import {
-    deleteDiskCache,
-    getCacheDirectory,
-    openDiskCache,
-    setCustomCacheDirectory,
-} from "./api/cache";
+import { deleteDiskCache, openDiskCache } from "./api/cache";
 import { computeImageEmbedding, computeTextEmbedding } from "./api/clip";
 import { computeImageEmbedding, computeTextEmbedding } from "./api/clip";
 import {
 import {
     getAppVersion,
     getAppVersion,
@@ -144,6 +139,4 @@ contextBridge.exposeInMainWorld("ElectronAPIs", {
     computeImageEmbedding,
     computeImageEmbedding,
     computeTextEmbedding,
     computeTextEmbedding,
     getPlatform,
     getPlatform,
-    getCacheDirectory,
-    setCustomCacheDirectory,
 });
 });

+ 0 - 8
desktop/src/services/userPreference.ts

@@ -31,11 +31,3 @@ export function clearSkipAppVersion() {
 export function clearMuteUpdateNotificationVersion() {
 export function clearMuteUpdateNotificationVersion() {
     userPreferencesStore.delete("muteUpdateNotificationVersion");
     userPreferencesStore.delete("muteUpdateNotificationVersion");
 }
 }
-
-export function setCustomCacheDirectory(directory: string) {
-    userPreferencesStore.set("customCacheDirectory", directory);
-}
-
-export function getCustomCacheDirectory(): string {
-    return userPreferencesStore.get("customCacheDirectory");
-}

+ 0 - 3
desktop/src/stores/userPreferences.store.ts

@@ -11,9 +11,6 @@ const userPreferencesSchema: Schema<UserPreferencesType> = {
     muteUpdateNotificationVersion: {
     muteUpdateNotificationVersion: {
         type: "string",
         type: "string",
     },
     },
-    customCacheDirectory: {
-        type: "string",
-    },
 };
 };
 
 
 export const userPreferencesStore = new Store({
 export const userPreferencesStore = new Store({

+ 0 - 1
desktop/src/types/index.ts

@@ -58,7 +58,6 @@ export interface UserPreferencesType {
     hideDockIcon: boolean;
     hideDockIcon: boolean;
     skipAppVersion: string;
     skipAppVersion: string;
     muteUpdateNotificationVersion: string;
     muteUpdateNotificationVersion: string;
-    customCacheDirectory: string;
 }
 }
 
 
 export interface AppUpdateInfo {
 export interface AppUpdateInfo {

+ 0 - 12
desktop/src/utils/ipcComms.ts

@@ -27,10 +27,6 @@ import {
     generateImageThumbnail,
     generateImageThumbnail,
 } from "../services/imageProcessor";
 } from "../services/imageProcessor";
 import { logErrorSentry } from "../services/sentry";
 import { logErrorSentry } from "../services/sentry";
-import {
-    getCustomCacheDirectory,
-    setCustomCacheDirectory,
-} from "../services/userPreference";
 import { getPlatform } from "./common/platform";
 import { getPlatform } from "./common/platform";
 import { createWindow } from "./createWindow";
 import { createWindow } from "./createWindow";
 import { generateTempFilePath } from "./temp";
 import { generateTempFilePath } from "./temp";
@@ -183,12 +179,4 @@ export default function setupIpcComs(
     ipcMain.handle("get-platform", () => {
     ipcMain.handle("get-platform", () => {
         return getPlatform();
         return getPlatform();
     });
     });
-
-    ipcMain.handle("set-custom-cache-directory", (_, directory: string) => {
-        setCustomCacheDirectory(directory);
-    });
-
-    ipcMain.handle("get-custom-cache-directory", async () => {
-        return getCustomCacheDirectory();
-    });
 }
 }

+ 12 - 16
web/apps/photos/src/components/Sidebar/AdvancedSettings.tsx

@@ -16,7 +16,6 @@ import isElectron from "is-electron";
 import { AppContext } from "pages/_app";
 import { AppContext } from "pages/_app";
 import { ClipExtractionStatus, ClipService } from "services/clipService";
 import { ClipExtractionStatus, ClipService } from "services/clipService";
 import { formatNumber } from "utils/number/format";
 import { formatNumber } from "utils/number/format";
-import CacheDirectory from "./Preferences/CacheDirectory";
 
 
 export default function AdvancedSettings({ open, onClose, onRootClose }) {
 export default function AdvancedSettings({ open, onClose, onRootClose }) {
     const appContext = useContext(AppContext);
     const appContext = useContext(AppContext);
@@ -77,22 +76,19 @@ export default function AdvancedSettings({ open, onClose, onRootClose }) {
                 <Box px={"8px"}>
                 <Box px={"8px"}>
                     <Stack py="20px" spacing="24px">
                     <Stack py="20px" spacing="24px">
                         {isElectron() && (
                         {isElectron() && (
-                            <>
-                                <CacheDirectory />
-                                <Box>
-                                    <MenuSectionTitle
-                                        title={t("LABS")}
-                                        icon={<ScienceIcon />}
+                            <Box>
+                                <MenuSectionTitle
+                                    title={t("LABS")}
+                                    icon={<ScienceIcon />}
+                                />
+                                <MenuItemGroup>
+                                    <EnteMenuItem
+                                        endIcon={<ChevronRight />}
+                                        onClick={openMlSearchSettings}
+                                        label={t("ML_SEARCH")}
                                     />
                                     />
-                                    <MenuItemGroup>
-                                        <EnteMenuItem
-                                            endIcon={<ChevronRight />}
-                                            onClick={openMlSearchSettings}
-                                            label={t("ML_SEARCH")}
-                                        />
-                                    </MenuItemGroup>
-                                </Box>
-                            </>
+                                </MenuItemGroup>
+                            </Box>
                         )}
                         )}
                         <Box>
                         <Box>
                             <MenuItemGroup>
                             <MenuItemGroup>

+ 0 - 60
web/apps/photos/src/components/Sidebar/Preferences/CacheDirectory.tsx

@@ -1,60 +0,0 @@
-import ElectronAPIs from "@ente/shared/electron";
-import { addLogLine } from "@ente/shared/logging";
-import { logError } from "@ente/shared/sentry";
-import Box from "@mui/material/Box";
-import { DirectoryPath } from "components/Directory";
-import { EnteMenuItem } from "components/Menu/EnteMenuItem";
-import { MenuItemGroup } from "components/Menu/MenuItemGroup";
-import MenuSectionTitle from "components/Menu/MenuSectionTitle";
-import { t } from "i18next";
-import isElectron from "is-electron";
-import { useEffect, useState } from "react";
-import DownloadManager from "services/download";
-
-export default function CacheDirectory() {
-    const [cacheDirectory, setCacheDirectory] = useState(undefined);
-
-    useEffect(() => {
-        const main = async () => {
-            if (isElectron()) {
-                const customCacheDirectory =
-                    await ElectronAPIs.getCacheDirectory();
-                setCacheDirectory(customCacheDirectory);
-            }
-        };
-        main();
-    }, []);
-
-    const handleCacheDirectoryChange = async () => {
-        try {
-            if (!isElectron()) {
-                return;
-            }
-            const newFolder = await ElectronAPIs.selectDirectory();
-            if (!newFolder) {
-                return;
-            }
-            addLogLine(`Export folder changed to ${newFolder}`);
-            await ElectronAPIs.setCustomCacheDirectory(newFolder);
-            setCacheDirectory(newFolder);
-            await DownloadManager.reloadCaches();
-        } catch (e) {
-            logError(e, "handleCacheDirectoryChange failed");
-        }
-    };
-
-    return (
-        <Box>
-            <MenuSectionTitle title={t("CACHE_DIRECTORY")} />
-            <MenuItemGroup>
-                <EnteMenuItem
-                    variant="path"
-                    onClick={handleCacheDirectoryChange}
-                    labelComponent={
-                        <DirectoryPath width={265} path={cacheDirectory} />
-                    }
-                />
-            </MenuItemGroup>
-        </Box>
-    );
-}

+ 0 - 5
web/apps/photos/src/services/download/index.ts

@@ -130,11 +130,6 @@ class DownloadManagerImpl {
         this.progressUpdater = progressUpdater;
         this.progressUpdater = progressUpdater;
     }
     }
 
 
-    async reloadCaches() {
-        this.thumbnailCache = await openThumbnailCache();
-        this.diskFileCache = isElectron() && (await openDiskFileCache());
-    }
-
     private async getCachedThumbnail(fileID: number) {
     private async getCachedThumbnail(fileID: number) {
         try {
         try {
             const cacheResp: Response = await this.thumbnailCache?.match(
             const cacheResp: Response = await this.thumbnailCache?.match(

+ 0 - 2
web/packages/shared/electron/types.ts

@@ -105,6 +105,4 @@ export interface ElectronAPIsType {
     ) => Promise<Float32Array>;
     ) => Promise<Float32Array>;
     computeTextEmbedding: (model: Model, text: string) => Promise<Float32Array>;
     computeTextEmbedding: (model: Model, text: string) => Promise<Float32Array>;
     getPlatform: () => Promise<"mac" | "windows" | "linux">;
     getPlatform: () => Promise<"mac" | "windows" | "linux">;
-    setCustomCacheDirectory: (directory: string) => Promise<void>;
-    getCacheDirectory: () => Promise<string>;
 }
 }