This commit is contained in:
Manav Rathi
2024-07-20 13:40:16 +05:30
parent 5a128f1e48
commit b0b7ec5347
4 changed files with 25 additions and 15 deletions

View File

@@ -1,4 +1,5 @@
import { openAccountsManagePasskeysPage } from "@/accounts/services/passkey";
import { isDesktop } from "@/base/app";
import { EnteDrawer } from "@/base/components/EnteDrawer";
import log from "@/base/log";
import { savedLogs } from "@/base/log-web";
@@ -599,13 +600,10 @@ const HelpSection: React.FC = () => {
const contactSupport = () => initiateEmail("support@ente.io");
function openExport() {
if (isElectron()) {
openExportModal();
} else {
setDialogMessage(getDownloadAppMessage());
}
}
const handleExport = () =>
isDesktop
? openExportModal()
: setDialogMessage(getDownloadAppMessage());
return (
<>
@@ -626,7 +624,7 @@ const HelpSection: React.FC = () => {
variant="secondary"
/>
<EnteMenuItem
onClick={openExport}
onClick={handleExport}
label={t("EXPORT")}
endIcon={
exportService.isExportInProgress() && (

View File

@@ -215,6 +215,15 @@ class ExportService {
}
}
/**
* Called when the local database of files changes.
*/
onLocalFilesUpdated() {
if (this.continuousExportEventHandler) {
this.continuousExportEventHandler();
}
}
getPendingExports = async (
exportRecord: ExportRecord,
): Promise<EnteFile[]> => {

View File

@@ -14,6 +14,7 @@ import ComlinkCryptoWorker from "@ente/shared/crypto";
import HTTPService from "@ente/shared/network/HTTPService";
import { getToken } from "@ente/shared/storage/localStorage/helpers";
import { REQUEST_BATCH_SIZE } from "constants/api";
import exportService from "services/export";
import { Collection } from "types/collection";
import { SetFiles } from "types/gallery";
import { batch } from "utils/common";
@@ -30,9 +31,11 @@ export const syncFiles = async (
) => {
const localFiles = await getLocalFiles(type);
let files = await removeDeletedCollectionFiles(collections, localFiles);
let didUpdateFiles = false;
if (files.length !== localFiles.length) {
await setLocalFiles(type, files);
setFiles(sortFiles(mergeMetadata(files)));
didUpdateFiles = true;
}
for (const collection of collections) {
if (!getToken()) {
@@ -46,8 +49,10 @@ export const syncFiles = async (
const newFiles = await getFiles(collection, lastSyncTime, setFiles);
files = getLatestVersionFiles([...files, ...newFiles]);
await setLocalFiles(type, files);
didUpdateFiles = true;
setCollectionLastSyncTime(collection, collection.updationTime);
}
if (didUpdateFiles) exportService.onLocalFilesUpdated();
return files;
};

View File

@@ -1,5 +1,3 @@
import log from "@/base/log";
import { Events, eventBus } from "@ente/shared/events";
import localForage from "@ente/shared/storage/localForage";
import { type EnteFile, type Trash } from "../types/file";
import { mergeMetadata } from "../utils/file";
@@ -25,17 +23,17 @@ export const getLocalFiles = async (type: "normal" | "hidden" = "normal") => {
return files;
};
/**
* Update the files that we know about locally.
*
* Sibling of {@link getLocalFiles}.
*/
export const setLocalFiles = async (
type: "normal" | "hidden",
files: EnteFile[],
) => {
const tableName = type === "normal" ? FILES_TABLE : HIDDEN_FILES_TABLE;
await localForage.setItem(tableName, files);
try {
eventBus.emit(Events.LOCAL_FILES_UPDATED);
} catch (e) {
log.error("Failed to save files", e);
}
};
export const TRASH = "file-trash";