Propagate

This commit is contained in:
Manav Rathi 2024-04-29 11:55:53 +05:30
parent 63841abd30
commit 2d8bcd2530
No known key found for this signature in database
5 changed files with 30 additions and 42 deletions

View file

@ -52,12 +52,11 @@ import {
saveEncryptionKey,
} from "./services/store";
import {
clearPendingUploads,
getElectronFilesFromGoogleZip,
lsZip,
pendingUploads,
setPendingUploadCollection,
setPendingUploadFiles,
setPendingUploads,
markUploaded,
clearPendingUploads,
} from "./services/upload";
import {
watchAdd,
@ -204,14 +203,11 @@ export const attachIPCHandlers = () => {
ipcMain.handle("pendingUploads", () => pendingUploads());
ipcMain.handle("setPendingUploadCollection", (_, collectionName: string) =>
setPendingUploadCollection(collectionName),
);
ipcMain.handle("setPendingUploads", (_, pendingUploads: PendingUploads) =>
setPendingUploads(pendingUploads),
ipcMain.handle(
"setPendingUploadFiles",
(_, type: PendingUploads["type"], filePaths: string[]) =>
setPendingUploadFiles(type, filePaths),
ipcMain.handle("markUploaded", (_, pathOrZipEntry: string | [zipPath: string, entryName: string]) =>
markUploaded(pathOrZipEntry),
);
ipcMain.handle("clearPendingUploads", () => clearPendingUploads());

View file

@ -26,7 +26,8 @@ export const lsZip = async (zipPath: string) => {
return [entryPaths];
};
export const pendingUploads = async () => {
export const pendingUploads = async (): Promise<PendingUploads | undefined> => {
/* TODO */
const collectionName = uploadStatusStore.get("collectionName");
const filePaths = validSavedPaths("files");
const zipPaths = validSavedPaths("zips");
@ -56,7 +57,14 @@ export const pendingUploads = async () => {
};
};
export const validSavedPaths = (type: PendingUploads["type"]) => {
export const setPendingUploads = async (pendingUploads: PendingUploads) =>
uploadStatusStore.set(pendingUploads);
export const markUploaded = async (
pathOrZipEntry: string | [zipPath: string, entryName: string],
) => {};
const validSavedPaths = (type: PendingUploads["type"]) => {
const key = storeKey(type);
const savedPaths = (uploadStatusStore.get(key) as string[]) ?? [];
const paths = savedPaths.filter((p) => existsSync(p));
@ -64,12 +72,12 @@ export const validSavedPaths = (type: PendingUploads["type"]) => {
return paths;
};
export const setPendingUploadCollection = (collectionName: string) => {
const setPendingUploadCollection = (collectionName: string) => {
if (collectionName) uploadStatusStore.set("collectionName", collectionName);
else uploadStatusStore.delete("collectionName");
};
export const setPendingUploadFiles = (
const setPendingUploadFiles = (
type: PendingUploads["type"],
filePaths: string[],
) => {
@ -78,9 +86,7 @@ export const setPendingUploadFiles = (
else uploadStatusStore.delete(key);
};
export const clearPendingUploads = () => {
uploadStatusStore.clear();
};
export const clearPendingUploads = () => uploadStatusStore.clear();
const storeKey = (type: PendingUploads["type"]): keyof UploadStatusStore => {
switch (type) {

View file

@ -10,7 +10,7 @@ export interface UploadStatusStore {
*/
zipEntries: [zipPath: string, entryName: string][];
/** Legacy paths to zip files, now subsumed into zipEntries */
zipPaths: string[];
zipPaths?: string[];
}
const uploadStatusSchema: Schema<UploadStatusStore> = {

View file

@ -247,26 +247,16 @@ const lsZip = (zipPath: string): Promise<string[]> =>
const pendingUploads = (): Promise<PendingUploads | undefined> =>
ipcRenderer.invoke("pendingUploads");
const setPendingUploadCollection = (collectionName: string): Promise<void> =>
ipcRenderer.invoke("setPendingUploadCollection", collectionName);
const setPendingUploads = (pendingUploads: PendingUploads): Promise<void> =>
ipcRenderer.invoke("setPendingUploads", pendingUploads);
const setPendingUploadFiles = (
type: PendingUploads["type"],
filePaths: string[],
): Promise<void> =>
ipcRenderer.invoke("setPendingUploadFiles", type, filePaths);
const markUploaded = (
pathOrZipEntry: string | [zipPath: string, entryName: string],
): Promise<void> => ipcRenderer.invoke("markUploaded", pathOrZipEntry);
const clearPendingUploads = (): Promise<void> =>
ipcRenderer.invoke("clearPendingUploads");
// - TODO: AUDIT below this
// -
const getElectronFilesFromGoogleZip = (
filePath: string,
): Promise<ElectronFile[]> =>
ipcRenderer.invoke("getElectronFilesFromGoogleZip", filePath);
/**
* These objects exposed here will become available to the JS code in our
* renderer (the web/ code) as `window.ElectronAPIs.*`
@ -378,11 +368,7 @@ contextBridge.exposeInMainWorld("electron", {
lsZip,
pendingUploads,
setPendingUploadCollection,
setPendingUploadFiles,
setPendingUploads,
markUploaded,
clearPendingUploads,
// -
getElectronFilesFromGoogleZip,
});

View file

@ -27,8 +27,8 @@ export interface FolderWatchSyncedFile {
export interface PendingUploads {
collectionName: string;
type: "files" | "zips";
files: ElectronFile[];
filePaths: string[];
zipEntries: [zipPath: string, entryName: string][];
}
/**