Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

add setCustomCacheDirectory API

Abhinav351d63dfd4d4
diff --git a/src/api/cache.ts b/src/api/cache.ts
index a80e6ce996..a9aa00bde6 100644
--- a/src/api/cache.ts
+++ b/src/api/cache.ts
@@ -6,8 +6,14 @@ import { DiskCache } from '../services/diskCache';
const ENTE_CACHE_DIR_NAME = 'ente';
const getCacheDir = async () => {
- const systemCacheDir = await ipcRenderer.invoke('get-path', 'cache');
- return path.join(systemCacheDir, ENTE_CACHE_DIR_NAME);
+ const customCacheDir = await ipcRenderer.invoke(
+ 'get-custom-cache-directory'
+ );
+ if (customCacheDir && existsSync(customCacheDir)) {
+ return customCacheDir;
+ }
+ const defaultSystemCacheDir = await ipcRenderer.invoke('get-path', 'cache');
+ return path.join(defaultSystemCacheDir, ENTE_CACHE_DIR_NAME);
};
const getCacheBucketDir = async (cacheName: string) => {
@@ -36,3 +42,7 @@ export async function deleteDiskCache(cacheName: string) {
return false;
}
}
+
+export async function setCustomCacheDirectory(directory: string) {
+ await ipcRenderer.invoke('set-custom-cache-directory', directory);
+}
diff --git a/src/preload.ts b/src/preload.ts
index 8ae4ce936e..76be59d241 100644
--- a/src/preload.ts
+++ b/src/preload.ts
@@ -26,7 +26,11 @@ import {
} from './api/watch';
import { getEncryptionKey, setEncryptionKey } from './api/safeStorage';
import { clearElectronStore } from './api/electronStore';
-import { openDiskCache, deleteDiskCache } from './api/cache';
+import {
+ openDiskCache,
+ deleteDiskCache,
+ setCustomCacheDirectory,
+} from './api/cache';
import {
checkExistsAndCreateDir,
saveStreamToDisk,
@@ -119,4 +123,5 @@ windowObject['ElectronAPIs'] = {
computeImageEmbedding,
computeTextEmbedding,
getPlatform,
+ setCustomCacheDirectory,
};
diff --git a/src/services/userPreference.ts b/src/services/userPreference.ts
index 4836b8f3a8..6062a7679a 100644
--- a/src/services/userPreference.ts
+++ b/src/services/userPreference.ts
@@ -39,3 +39,11 @@ export function clearSkipAppVersion() {
export function clearMuteUpdateNotificationVersion() {
userPreferencesStore.delete('muteUpdateNotificationVersion');
}
+
+export function setCustomCacheDirectory(directory: string) {
+ userPreferencesStore.set('customCacheDirectory', directory);
+}
+
+export function getCustomCacheDirectory() {
+ return userPreferencesStore.get('customCacheDirectory');
+}
diff --git a/src/utils/ipcComms.ts b/src/utils/ipcComms.ts
index 40029041eb..d6d1e7dcdb 100644
--- a/src/utils/ipcComms.ts
+++ b/src/utils/ipcComms.ts
@@ -25,7 +25,11 @@ import {
} from '../services/appUpdater';
import { deleteTempFile, runFFmpegCmd } from '../services/ffmpeg';
import { generateTempFilePath } from './temp';
-import { setOptOutOfCrashReports } from '../services/userPreference';
+import {
+ getCustomCacheDirectory,
+ setCustomCacheDirectory,
+ setOptOutOfCrashReports,
+} from '../services/userPreference';
import { updateOptOutOfCrashReports } from '../main';
import {
computeImageEmbedding,
@@ -180,4 +184,12 @@ 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();
+ });
}