π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
API on electron side
Manav Rathi4455bb959536
diff --git a/desktop/src/main/services/watch.ts b/desktop/src/main/services/watch.tsindex 8dad45e0e4..b12913ed4d 100644--- a/desktop/src/main/services/watch.ts+++ b/desktop/src/main/services/watch.ts@@ -25,9 +25,9 @@ export const createWatcher = (mainWindow: BrowserWindow) => {});watcher- .on("add", send("addFile"))- .on("unlink", send("removeFile"))- .on("unlinkDir", send("removeDir"))+ .on("add", send("watchAddFile"))+ .on("unlink", send("watchRemoveFile"))+ .on("unlinkDir", send("watchRemoveDir")).on("error", (error) => log.error("Error while watching files", error));return watcher;diff --git a/desktop/src/preload.ts b/desktop/src/preload.tsindex cf5ded6d88..c23baef4e3 100644--- a/desktop/src/preload.ts+++ b/desktop/src/preload.ts@@ -40,9 +40,10 @@import { contextBridge, ipcRenderer } from "electron/renderer";// While we can't import other code, we can import types since they're just-// needed when compiling and will not be needed / looked around for at runtime.+// needed when compiling and will not be needed or looked around for at runtime.import type {AppUpdate,+ CollectionMapping,ElectronFile,FolderWatch,PendingUploads,@@ -191,43 +192,40 @@ const showUploadZipDialog = (): Promise<{// - Watch-const findFiles = (folderPath: string): Promise<string[]> =>- ipcRenderer.invoke("findFiles", folderPath);+const watchFindFiles = (folderPath: string): Promise<string[]> =>+ ipcRenderer.invoke("watchFindFiles", folderPath);-const registerWatcherFunctions = (- addFile: (file: ElectronFile) => Promise<void>,- removeFile: (path: string) => Promise<void>,- removeFolder: (folderPath: string) => Promise<void>,-) => {- ipcRenderer.removeAllListeners("watch-add");- ipcRenderer.removeAllListeners("watch-unlink");- ipcRenderer.removeAllListeners("watch-unlink-dir");- ipcRenderer.on("watch-add", (_, file: ElectronFile) => addFile(file));- ipcRenderer.on("watch-unlink", (_, filePath: string) =>- removeFile(filePath),- );- ipcRenderer.on("watch-unlink-dir", (_, folderPath: string) =>- removeFolder(folderPath),- );-};--const addWatchMapping = (- collectionName: string,+const watchAdd = (folderPath: string,- uploadStrategy: number,+ collectionMapping: CollectionMapping,): Promise<void> =>- ipcRenderer.invoke(- "addWatchMapping",- collectionName,- folderPath,- uploadStrategy,+ ipcRenderer.invoke("watchAdd", folderPath, collectionMapping);++const watchRemove = (folderPath: string): Promise<void> =>+ ipcRenderer.invoke("watchRemove", folderPath);++const watchGet = (): Promise<FolderWatch[]> => ipcRenderer.invoke("watchGet");++const watchOnAddFile = (f: (path: string, watch: FolderWatch) => void) => {+ ipcRenderer.removeAllListeners("watchAddFile");+ ipcRenderer.on("watchAddFile", (_, path: string, watch: FolderWatch) =>+ f(path, watch),);+};-const removeWatchMapping = (folderPath: string): Promise<void> =>- ipcRenderer.invoke("removeWatchMapping", folderPath);+const watchOnRemoveFile = (f: (path: string, watch: FolderWatch) => void) => {+ ipcRenderer.removeAllListeners("watchRemoveFile");+ ipcRenderer.on("watchRemoveFile", (_, path: string, watch: FolderWatch) =>+ f(path, watch),+ );+};-const getWatchMappings = (): Promise<FolderWatch[]> =>- ipcRenderer.invoke("getWatchMappings");+const watchOnRemoveDir = (f: (path: string, watch: FolderWatch) => void) => {+ ipcRenderer.removeAllListeners("watchRemoveDir");+ ipcRenderer.on("watchRemoveDir", (_, path: string, watch: FolderWatch) =>+ f(path, watch),+ );+};const updateWatchMappingSyncedFiles = (folderPath: string,@@ -265,6 +263,7 @@ const getElectronFilesFromGoogleZip = (const getDirFiles = (dirPath: string): Promise<ElectronFile[]> =>ipcRenderer.invoke("getDirFiles", dirPath);+//// These objects exposed here will become available to the JS code in our// renderer (the web/ code) as `window.ElectronAPIs.*`//@@ -296,8 +295,10 @@ const getDirFiles = (dirPath: string): Promise<ElectronFile[]> =>// https://www.electronjs.org/docs/latest/api/context-bridge#methods//// The copy itself is relatively fast, but the problem with transfering large-// amounts of data is potentially running out of memory during the copy. For an-// alternative, see [Note: IPC streams].+// amounts of data is potentially running out of memory during the copy.+//+// For an alternative, see [Note: IPC streams].+//contextBridge.exposeInMainWorld("electron", {// - General@@ -353,12 +354,14 @@ contextBridge.exposeInMainWorld("electron", {// - Watchwatch: {- findFiles,+ findFiles: watchFindFiles,+ add: watchAdd,+ remove: watchRemove,+ get: watchGet,+ onAddFile: watchOnAddFile,+ onRemoveFile: watchOnRemoveFile,+ onRemoveDir: watchOnRemoveDir,},- registerWatcherFunctions,- addWatchMapping,- removeWatchMapping,- getWatchMappings,updateWatchMappingSyncedFiles,updateWatchMappingIgnoredFiles,diff --git a/web/apps/photos/src/services/watch.ts b/web/apps/photos/src/services/watch.tsindex b804e82350..d773527438 100644--- a/web/apps/photos/src/services/watch.ts+++ b/web/apps/photos/src/services/watch.ts@@ -115,7 +115,7 @@ class FolderWatcher {* collection do files belonging to nested directories go to.*/async addWatch(folderPath: string, mapping: CollectionMapping) {- await ensureElectron().watcher.add(folderPath, mapping);+ await ensureElectron().watch.add(folderPath, mapping);this.syncWithDisk();}@@ -706,7 +706,7 @@ const deduceEvents = async (for (const watch of activeWatches) {const folderPath = watch.folderPath;- const paths = (await electron.watcher.findFiles(folderPath))+ const paths = (await electron.watch.findFiles(folderPath))// Filter out hidden files (files whose names begins with a dot).filter((path) => !isHiddenFile(path));diff --git a/web/packages/next/types/ipc.ts b/web/packages/next/types/ipc.tsindex ff8ce3fa9b..7bb8428dd5 100644--- a/web/packages/next/types/ipc.ts+++ b/web/packages/next/types/ipc.ts@@ -288,7 +288,7 @@ export interface Electron {* dragged/dropped or selected to set up the folder watch, will be referred* to as a folder when naming things.*/- watcher: {+ watch: {/*** Return the paths of all the files under the given folder.*@@ -343,9 +343,7 @@ export interface Electron {** The path is guaranteed to use POSIX separators ('/').*/- onAddFile: (- f: (path: string, watch: FolderWatch) => void,- ) => Promise<void>;+ onAddFile: (f: (path: string, watch: FolderWatch) => void) => void;/*** Register the function to invoke when a file is removed in one of the@@ -356,9 +354,7 @@ export interface Electron {** The path is guaranteed to use POSIX separators ('/').*/- onRemoveFile: (- f: (path: string, watch: FolderWatch) => void,- ) => Promise<void>;+ onRemoveFile: (f: (path: string, watch: FolderWatch) => void) => void;/*** Register the function to invoke when a directory is removed in one of@@ -369,30 +365,9 @@ export interface Electron {** The path is guaranteed to use POSIX separators ('/').*/- onRemoveDir: (- f: (path: string, watch: FolderWatch) => void,- ) => Promise<void>;+ onRemoveDir: (f: (path: string, watch: FolderWatch) => void) => void;};- registerWatcherFunctions: (- addFile: (file: ElectronFile) => Promise<void>,- removeFile: (path: string) => Promise<void>,- removeFolder: (folderPath: string) => Promise<void>,- ) => void;-- removeWatchMapping: (folderPath: string) => Promise<void>;-- /**- * TODO(MR): Outdated description- * Get the latest state of the watched folders.- *- * We persist the folder watches that the user has setup. This function goes- * through that list, prunes any folders that don't exist on disk anymore,- * and for each, also returns a list of files that exist in that folder.- */-- getWatchMappings: () => Promise<FolderWatch[]>;-updateWatchMappingSyncedFiles: (folderPath: string,files: FolderWatch["syncedFiles"],