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.
This commit is contained in:
parent
e4684b22df
commit
eeaa5165ab
10 changed files with 14 additions and 130 deletions
|
@ -5,11 +5,7 @@ import { DiskCache } from "../services/diskCache";
|
|||
|
||||
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");
|
||||
return path.join(defaultSystemCacheDir, ENTE_CACHE_DIR_NAME);
|
||||
};
|
||||
|
@ -40,13 +36,3 @@ export async function deleteDiskCache(cacheName: string) {
|
|||
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");
|
||||
}
|
||||
|
|
|
@ -28,12 +28,7 @@
|
|||
*/
|
||||
|
||||
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 {
|
||||
getAppVersion,
|
||||
|
@ -144,6 +139,4 @@ contextBridge.exposeInMainWorld("ElectronAPIs", {
|
|||
computeImageEmbedding,
|
||||
computeTextEmbedding,
|
||||
getPlatform,
|
||||
getCacheDirectory,
|
||||
setCustomCacheDirectory,
|
||||
});
|
||||
|
|
|
@ -31,11 +31,3 @@ export function clearSkipAppVersion() {
|
|||
export function clearMuteUpdateNotificationVersion() {
|
||||
userPreferencesStore.delete("muteUpdateNotificationVersion");
|
||||
}
|
||||
|
||||
export function setCustomCacheDirectory(directory: string) {
|
||||
userPreferencesStore.set("customCacheDirectory", directory);
|
||||
}
|
||||
|
||||
export function getCustomCacheDirectory(): string {
|
||||
return userPreferencesStore.get("customCacheDirectory");
|
||||
}
|
||||
|
|
|
@ -11,9 +11,6 @@ const userPreferencesSchema: Schema<UserPreferencesType> = {
|
|||
muteUpdateNotificationVersion: {
|
||||
type: "string",
|
||||
},
|
||||
customCacheDirectory: {
|
||||
type: "string",
|
||||
},
|
||||
};
|
||||
|
||||
export const userPreferencesStore = new Store({
|
||||
|
|
|
@ -58,7 +58,6 @@ export interface UserPreferencesType {
|
|||
hideDockIcon: boolean;
|
||||
skipAppVersion: string;
|
||||
muteUpdateNotificationVersion: string;
|
||||
customCacheDirectory: string;
|
||||
}
|
||||
|
||||
export interface AppUpdateInfo {
|
||||
|
|
|
@ -27,10 +27,6 @@ import {
|
|||
generateImageThumbnail,
|
||||
} from "../services/imageProcessor";
|
||||
import { logErrorSentry } from "../services/sentry";
|
||||
import {
|
||||
getCustomCacheDirectory,
|
||||
setCustomCacheDirectory,
|
||||
} from "../services/userPreference";
|
||||
import { getPlatform } from "./common/platform";
|
||||
import { createWindow } from "./createWindow";
|
||||
import { generateTempFilePath } from "./temp";
|
||||
|
@ -183,12 +179,4 @@ export default function setupIpcComs(
|
|||
ipcMain.handle("get-platform", () => {
|
||||
return getPlatform();
|
||||
});
|
||||
|
||||
ipcMain.handle("set-custom-cache-directory", (_, directory: string) => {
|
||||
setCustomCacheDirectory(directory);
|
||||
});
|
||||
|
||||
ipcMain.handle("get-custom-cache-directory", async () => {
|
||||
return getCustomCacheDirectory();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ import isElectron from "is-electron";
|
|||
import { AppContext } from "pages/_app";
|
||||
import { ClipExtractionStatus, ClipService } from "services/clipService";
|
||||
import { formatNumber } from "utils/number/format";
|
||||
import CacheDirectory from "./Preferences/CacheDirectory";
|
||||
|
||||
export default function AdvancedSettings({ open, onClose, onRootClose }) {
|
||||
const appContext = useContext(AppContext);
|
||||
|
@ -77,22 +76,19 @@ export default function AdvancedSettings({ open, onClose, onRootClose }) {
|
|||
<Box px={"8px"}>
|
||||
<Stack py="20px" spacing="24px">
|
||||
{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>
|
||||
<MenuItemGroup>
|
||||
|
|
|
@ -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>
|
||||
);
|
||||
}
|
|
@ -130,11 +130,6 @@ class DownloadManagerImpl {
|
|||
this.progressUpdater = progressUpdater;
|
||||
}
|
||||
|
||||
async reloadCaches() {
|
||||
this.thumbnailCache = await openThumbnailCache();
|
||||
this.diskFileCache = isElectron() && (await openDiskFileCache());
|
||||
}
|
||||
|
||||
private async getCachedThumbnail(fileID: number) {
|
||||
try {
|
||||
const cacheResp: Response = await this.thumbnailCache?.match(
|
||||
|
|
|
@ -105,6 +105,4 @@ export interface ElectronAPIsType {
|
|||
) => Promise<Float32Array>;
|
||||
computeTextEmbedding: (model: Model, text: string) => Promise<Float32Array>;
|
||||
getPlatform: () => Promise<"mac" | "windows" | "linux">;
|
||||
setCustomCacheDirectory: (directory: string) => Promise<void>;
|
||||
getCacheDirectory: () => Promise<string>;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue