diff --git a/desktop/src/main/ipc.ts b/desktop/src/main/ipc.ts index 6e8bbe3f7..271577aa0 100644 --- a/desktop/src/main/ipc.ts +++ b/desktop/src/main/ipc.ts @@ -52,11 +52,12 @@ import { saveEncryptionKey, } from "./services/store"; import { + clearPendingUploads, lsZip, + markUploadedFiles, + markUploadedZipEntries, pendingUploads, setPendingUploads, - markUploaded, - clearPendingUploads, } from "./services/upload"; import { watchAdd, @@ -205,18 +206,20 @@ export const attachIPCHandlers = () => { ipcMain.handle("setPendingUploads", (_, pendingUploads: PendingUploads) => setPendingUploads(pendingUploads), + ); - ipcMain.handle("markUploaded", (_, pathOrZipEntry: string | [zipPath: string, entryName: string]) => - markUploaded(pathOrZipEntry), + ipcMain.handle( + "markUploadedFiles", + (_, paths: PendingUploads["filePaths"]) => markUploadedFiles(paths), + ); + + ipcMain.handle( + "markUploadedZipEntries", + (_, zipEntries: PendingUploads["zipEntries"]) => + markUploadedZipEntries(zipEntries), ); ipcMain.handle("clearPendingUploads", () => clearPendingUploads()); - - // - - - ipcMain.handle("getElectronFilesFromGoogleZip", (_, filePath: string) => - getElectronFilesFromGoogleZip(filePath), - ); }; /** diff --git a/desktop/src/main/services/upload.ts b/desktop/src/main/services/upload.ts index 66c97e34c..ebd1f481f 100644 --- a/desktop/src/main/services/upload.ts +++ b/desktop/src/main/services/upload.ts @@ -60,9 +60,21 @@ export const pendingUploads = async (): Promise => { export const setPendingUploads = async (pendingUploads: PendingUploads) => uploadStatusStore.set(pendingUploads); -export const markUploaded = async ( - pathOrZipEntry: string | [zipPath: string, entryName: string], -) => {}; +export const markUploadedFiles = async (paths: string[]) => { + const existing = uploadStatusStore.get("filePaths"); + const updated = existing.filter((p) => !paths.includes(p)); + uploadStatusStore.set("filePaths", updated); +}; + +export const markUploadedZipEntries = async ( + entries: [zipPath: string, entryName: string][], +) => { + const existing = uploadStatusStore.get("zipEntries"); + const updated = existing.filter( + (z) => !entries.some((e) => z[0] == e[0] && z[1] == e[1]), + ); + uploadStatusStore.set("zipEntries", updated); +}; const validSavedPaths = (type: PendingUploads["type"]) => { const key = storeKey(type); diff --git a/desktop/src/preload.ts b/desktop/src/preload.ts index c3737aceb..484a3bc0e 100644 --- a/desktop/src/preload.ts +++ b/desktop/src/preload.ts @@ -250,9 +250,12 @@ const pendingUploads = (): Promise => const setPendingUploads = (pendingUploads: PendingUploads): Promise => ipcRenderer.invoke("setPendingUploads", pendingUploads); -const markUploaded = ( - pathOrZipEntry: string | [zipPath: string, entryName: string], -): Promise => ipcRenderer.invoke("markUploaded", pathOrZipEntry); +const markUploadedFiles = (paths: PendingUploads["filePaths"]): Promise => + ipcRenderer.invoke("markUploadedFiles", paths); + +const markUploadedZipEntries = ( + zipEntries: PendingUploads["zipEntries"], +): Promise => ipcRenderer.invoke("markUploadedZipEntries", zipEntries); const clearPendingUploads = (): Promise => ipcRenderer.invoke("clearPendingUploads"); @@ -369,6 +372,7 @@ contextBridge.exposeInMainWorld("electron", { lsZip, pendingUploads, setPendingUploads, - markUploaded, + markUploadedFiles, + markUploadedZipEntries, clearPendingUploads, }); diff --git a/web/packages/next/types/ipc.ts b/web/packages/next/types/ipc.ts index e340e7a06..761cd72f1 100644 --- a/web/packages/next/types/ipc.ts +++ b/web/packages/next/types/ipc.ts @@ -501,11 +501,16 @@ export interface Electron { setPendingUploads: (pendingUploads: PendingUploads) => Promise; /** - * Update the list of files (of {@link type}) associated with the pending - * upload. + * Mark the given files (given by their {@link paths}) as having been + * uploaded. */ - markUploaded: ( - pathOrZipEntry: string | [zipPath: string, entryName: string], + markUploadedFiles: (paths: PendingUploads["filePaths"]) => Promise; + + /** + * Mark the given zip file entries as having been uploaded. + */ + markUploadedZipEntries: ( + entries: PendingUploads["zipEntries"], ) => Promise; /**