Skip to content

armgit / ente

Public Imported from GitHub
0

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

More transition

Manav Rathi56ce5c0b0ea8
diff --git a/web/apps/photos/src/pages/gallery/index.tsx b/web/apps/photos/src/pages/gallery/index.tsx
index 7b918ed647..69b833802b 100644
--- a/web/apps/photos/src/pages/gallery/index.tsx
+++ b/web/apps/photos/src/pages/gallery/index.tsx
@@ -61,37 +61,10 @@ import {
} from "utils/file";
import log from "@/next/log";
-import { PHOTOS_PAGES as PAGES } from "@ente/shared/constants/pages";
-import { CustomError } from "@ente/shared/error";
-import CollectionNamer, {
- CollectionNamerAttributes,
-} from "components/Collections/CollectionNamer";
-import Uploader from "components/Upload/Uploader";
-import PlanSelector from "components/pages/gallery/PlanSelector";
-import {
- ALL_SECTION,
- ARCHIVE_SECTION,
- CollectionSummaryType,
- DUMMY_UNCATEGORIZED_COLLECTION,
- HIDDEN_ITEMS_SECTION,
- TRASH_SECTION,
-} from "constants/collection";
-import { AppContext } from "pages/_app";
-import { getLocalTrashedFiles, syncTrash } from "services/trashService";
-import {
- COLLECTION_OPS_TYPE,
- constructCollectionNameMap,
- getArchivedCollections,
- getDefaultHiddenCollectionIDs,
- getSelectedCollection,
- handleCollectionOps,
- hasNonSystemCollections,
- splitNormalAndHiddenCollections,
-} from "utils/collection";
-
-import ElectronAPIs from "@/next/electron";
import { APPS } from "@ente/shared/apps/constants";
import { CenteredFlex } from "@ente/shared/components/Container";
+import { PHOTOS_PAGES as PAGES } from "@ente/shared/constants/pages";
+import { CustomError } from "@ente/shared/error";
import useFileInput from "@ente/shared/hooks/useFileInput";
import useMemoSingleThreaded from "@ente/shared/hooks/useMemoSingleThreaded";
import InMemoryStore, { MS_KEYS } from "@ente/shared/storage/InMemoryStore";
@@ -101,6 +74,9 @@ import { User } from "@ente/shared/user/types";
import { isPromise } from "@ente/shared/utils";
import AuthenticateUserModal from "components/AuthenticateUserModal";
import Collections from "components/Collections";
+import CollectionNamer, {
+ CollectionNamerAttributes,
+} from "components/Collections/CollectionNamer";
import ExportModal from "components/ExportModal";
import {
FilesDownloadProgress,
@@ -112,16 +88,27 @@ import FixCreationTime, {
import GalleryEmptyState from "components/GalleryEmptyState";
import { ITEM_TYPE, TimeStampListItem } from "components/PhotoList";
import SearchResultInfo from "components/Search/SearchResultInfo";
+import Uploader from "components/Upload/Uploader";
import UploadInputs from "components/UploadSelectorInputs";
import { GalleryNavbar } from "components/pages/gallery/Navbar";
+import PlanSelector from "components/pages/gallery/PlanSelector";
+import {
+ ALL_SECTION,
+ ARCHIVE_SECTION,
+ CollectionSummaryType,
+ DUMMY_UNCATEGORIZED_COLLECTION,
+ HIDDEN_ITEMS_SECTION,
+ TRASH_SECTION,
+} from "constants/collection";
import { SYNC_INTERVAL_IN_MICROSECONDS } from "constants/gallery";
-import isElectron from "is-electron";
+import { AppContext } from "pages/_app";
import { ClipService } from "services/clipService";
import { constructUserIDToEmailMap } from "services/collectionService";
import downloadManager from "services/download";
import { syncEmbeddings } from "services/embeddingService";
import { syncEntities } from "services/entityService";
import locationSearchService from "services/locationSearchService";
+import { getLocalTrashedFiles, syncTrash } from "services/trashService";
import uploadManager from "services/upload/uploadManager";
import { Collection, CollectionSummaries } from "types/collection";
import { EnteFile } from "types/file";
@@ -134,6 +121,16 @@ import {
} from "types/gallery";
import { Search, SearchResultSummary, UpdateSearch } from "types/search";
import { FamilyData } from "types/user";
+import {
+ COLLECTION_OPS_TYPE,
+ constructCollectionNameMap,
+ getArchivedCollections,
+ getDefaultHiddenCollectionIDs,
+ getSelectedCollection,
+ handleCollectionOps,
+ hasNonSystemCollections,
+ splitNormalAndHiddenCollections,
+} from "utils/collection";
import ComlinkSearchWorker from "utils/comlink/ComlinkSearchWorker";
import { isArchivedFile } from "utils/magicMetadata";
import { getSessionExpiredMessage } from "utils/ui";
@@ -321,6 +318,7 @@ export default function Gallery() {
return;
}
preloadImage("/images/subscription-card-background");
+ const electron = globalThis.electron;
const main = async () => {
const valid = await validateKey();
if (!valid) {
@@ -363,9 +361,9 @@ export default function Gallery() {
syncInterval.current = setInterval(() => {
syncWithRemote(false, true);
}, SYNC_INTERVAL_IN_MICROSECONDS);
- if (isElectron()) {
+ if (electron) {
void ClipService.setupOnFileUploadListener();
- ElectronAPIs.registerForegroundEventListener(() => {
+ electron.registerForegroundEventListener(() => {
syncWithRemote(false, true);
});
}
@@ -373,8 +371,8 @@ export default function Gallery() {
main();
return () => {
clearInterval(syncInterval.current);
- if (isElectron()) {
- ElectronAPIs.registerForegroundEventListener(() => {});
+ if (electron) {
+ electron.registerForegroundEventListener(() => {});
ClipService.removeOnFileUploadListener();
}
};
diff --git a/web/apps/photos/src/services/export/index.ts b/web/apps/photos/src/services/export/index.ts
index 49825f5685..da9b3b1698 100644
--- a/web/apps/photos/src/services/export/index.ts
+++ b/web/apps/photos/src/services/export/index.ts
@@ -1,5 +1,4 @@
import log from "@/next/log";
-import type { Electron } from "@/next/types/ipc";
import { CustomError } from "@ente/shared/error";
import { Events, eventBus } from "@ente/shared/events";
import { LS_KEYS, getData, setData } from "@ente/shared/storage/localStorage";
@@ -58,6 +57,7 @@ import downloadManager from "../download";
import { getAllLocalFiles } from "../fileService";
import { decodeLivePhoto } from "../livePhotoService";
import { migrateExport } from "./migration";
+import type { Electron } from "@/next/types/ipc";
const EXPORT_RECORD_FILE_NAME = "export_status.json";
@@ -71,7 +71,14 @@ export const NULL_EXPORT_RECORD: ExportRecord = {
collectionExportNames: {},
};
-let electron: Electron;
+const electron = (): Electron => {
+ const et = globalThis.electron;
+ if (!et)
+ throw new Error(
+ "Attempting to use ExportService in an unsupported non-electron context",
+ );
+ return et;
+};
class ExportService {
private exportSettings: ExportSettings;
@@ -92,15 +99,6 @@ class ExportService {
failed: 0,
};
- constructor() {
- const et = globalThis.electron;
- if (!et)
- throw new Error(
- "Attempting to initialize ExportService in an unsupported non-electron context",
- );
- electron = et;
- }
-
getExportSettings(): ExportSettings {
try {
if (this.exportSettings) {
@@ -168,12 +166,12 @@ class ExportService {
async changeExportDirectory() {
try {
- const newRootDir = await electron.selectDirectory();
+ const newRootDir = await electron().selectDirectory();
if (!newRootDir) {
throw Error(CustomError.SELECT_FOLDER_ABORTED);
}
const newExportDir = `${newRootDir}/${ENTE_EXPORT_DIRECTORY}`;
- await electron.checkExistsAndCreateDir(newExportDir);
+ await electron().checkExistsAndCreateDir(newExportDir);
return newExportDir;
} catch (e) {
if (e.message !== CustomError.SELECT_FOLDER_ABORTED) {
@@ -523,7 +521,7 @@ class ExportService {
newCollectionExportName,
);
try {
- await electron.rename(
+ await electron().rename(
oldCollectionExportPath,
newCollectionExportPath,
);
@@ -608,11 +606,11 @@ class ExportService {
);
try {
// delete the collection metadata folder
- await electron.deleteFolder(
+ await electron().deleteFolder(
getMetadataFolderExportPath(collectionExportPath),
);
// delete the collection folder
- await electron.deleteFolder(collectionExportPath);
+ await electron().deleteFolder(collectionExportPath);
} catch (e) {
await this.addCollectionExportedRecord(
exportFolder,
@@ -695,10 +693,10 @@ class ExportService {
exportDir,
collectionExportName,
);
- await electron.checkExistsAndCreateDir(
+ await electron().checkExistsAndCreateDir(
collectionExportPath,
);
- await electron.checkExistsAndCreateDir(
+ await electron().checkExistsAndCreateDir(
getMetadataFolderExportPath(collectionExportPath),
);
await this.downloadAndSave(
@@ -778,7 +776,7 @@ class ExportService {
`moving image file ${imageExportPath} to trash folder`,
);
if (await this.exists(imageExportPath)) {
- await electron.moveFile(
+ await electron().moveFile(
imageExportPath,
await getTrashedFileExportPath(
exportDir,
@@ -793,7 +791,7 @@ class ExportService {
if (
await this.exists(imageMetadataFileExportPath)
) {
- await electron.moveFile(
+ await electron().moveFile(
imageMetadataFileExportPath,
await getTrashedFileExportPath(
exportDir,
@@ -810,7 +808,7 @@ class ExportService {
`moving video file ${videoExportPath} to trash folder`,
);
if (await this.exists(videoExportPath)) {
- await electron.moveFile(
+ await electron().moveFile(
videoExportPath,
await getTrashedFileExportPath(
exportDir,
@@ -823,7 +821,7 @@ class ExportService {
if (
await this.exists(videoMetadataFileExportPath)
) {
- await electron.moveFile(
+ await electron().moveFile(
videoMetadataFileExportPath,
await getTrashedFileExportPath(
exportDir,
@@ -845,7 +843,7 @@ class ExportService {
`moving file ${fileExportPath} to ${trashedFilePath} trash folder`,
);
if (await this.exists(fileExportPath)) {
- await electron.moveFile(
+ await electron().moveFile(
fileExportPath,
trashedFilePath,
);
@@ -853,7 +851,7 @@ class ExportService {
const metadataFileExportPath =
getMetadataFileExportPath(fileExportPath);
if (await this.exists(metadataFileExportPath)) {
- await electron.moveFile(
+ await electron().moveFile(
metadataFileExportPath,
await getTrashedFileExportPath(
exportDir,
@@ -992,7 +990,7 @@ class ExportService {
try {
const exportRecord = await this.getExportRecord(folder);
const newRecord: ExportRecord = { ...exportRecord, ...newData };
- await electron.saveFileToDisk(
+ await electron().saveFileToDisk(
`${folder}/${EXPORT_RECORD_FILE_NAME}`,
JSON.stringify(newRecord, null, 2),
);
@@ -1014,7 +1012,7 @@ class ExportService {
return this.createEmptyExportRecord(exportRecordJSONPath);
}
const recordFile =
- await electron.readTextFile(exportRecordJSONPath);
+ await electron().readTextFile(exportRecordJSONPath);
try {
return JSON.parse(recordFile);
} catch (e) {
@@ -1050,8 +1048,8 @@ class ExportService {
exportFolder,
collectionExportName,
);
- await electron.checkExistsAndCreateDir(collectionExportPath);
- await electron.checkExistsAndCreateDir(
+ await electron().checkExistsAndCreateDir(collectionExportPath);
+ await electron().checkExistsAndCreateDir(
getMetadataFolderExportPath(collectionExportPath),
);
@@ -1098,7 +1096,7 @@ class ExportService {
fileExportName,
file,
);
- await electron.saveStreamToDisk(
+ await electron().saveStreamToDisk(
getFileExportPath(collectionExportPath, fileExportName),
updatedFileStream,
);
@@ -1146,7 +1144,7 @@ class ExportService {
imageExportName,
file,
);
- await electron.saveStreamToDisk(
+ await electron().saveStreamToDisk(
getFileExportPath(collectionExportPath, imageExportName),
imageStream,
);
@@ -1158,12 +1156,12 @@ class ExportService {
file,
);
try {
- await electron.saveStreamToDisk(
+ await electron().saveStreamToDisk(
getFileExportPath(collectionExportPath, videoExportName),
videoStream,
);
} catch (e) {
- await electron.deleteFile(
+ await electron().deleteFile(
getFileExportPath(collectionExportPath, imageExportName),
);
throw e;
@@ -1179,7 +1177,7 @@ class ExportService {
fileExportName: string,
file: EnteFile,
) {
- await electron.saveFileToDisk(
+ await electron().saveFileToDisk(
getFileMetadataExportPath(collectionExportPath, fileExportName),
getGoogleLikeMetadataFile(fileExportName, file),
);
@@ -1190,15 +1188,15 @@ class ExportService {
};
exists = (path: string) => {
- return electron.fs.exists(path);
+ return electron().fs.exists(path);
};
rename = (oldPath: string, newPath: string) => {
- return electron.rename(oldPath, newPath);
+ return electron().rename(oldPath, newPath);
};
checkExistsAndCreateDir = (path: string) => {
- return electron.checkExistsAndCreateDir(path);
+ return electron().checkExistsAndCreateDir(path);
};
exportFolderExists = async (exportFolder: string) => {
@@ -1220,7 +1218,7 @@ class ExportService {
private createEmptyExportRecord = async (exportRecordJSONPath: string) => {
const exportRecord: ExportRecord = NULL_EXPORT_RECORD;
- await electron.saveFileToDisk(
+ await electron().saveFileToDisk(
exportRecordJSONPath,
JSON.stringify(exportRecord, null, 2),
);
diff --git a/web/apps/photos/src/services/ffmpeg/ffmpegFactory.ts b/web/apps/photos/src/services/ffmpeg/ffmpegFactory.ts
index decd325218..49aee9868e 100644
--- a/web/apps/photos/src/services/ffmpeg/ffmpegFactory.ts
+++ b/web/apps/photos/src/services/ffmpeg/ffmpegFactory.ts
@@ -1,5 +1,3 @@
-import ElectronAPIs from "@/next/electron";
-import isElectron from "is-electron";
import { ElectronFile } from "types/upload";
import ComlinkFFmpegWorker from "utils/comlink/ComlinkFFmpegWorker";
@@ -16,10 +14,11 @@ class FFmpegFactory {
private client: IFFmpeg;
async getFFmpegClient() {
if (!this.client) {
- if (isElectron()) {
+ const electron = globalThis.electron;
+ if (electron) {
this.client = {
run(cmd, inputFile, outputFilename, dontTimeout) {
- return ElectronAPIs.runFFmpegCmd(
+ return electron.runFFmpegCmd(
cmd,
inputFile,
outputFilename,
diff --git a/web/apps/photos/src/services/importService.ts b/web/apps/photos/src/services/importService.ts
index 29fc17161f..8e15e9fef7 100644
--- a/web/apps/photos/src/services/importService.ts
+++ b/web/apps/photos/src/services/importService.ts
@@ -1,4 +1,5 @@
-import ElectronAPIs from "@/next/electron";
+import log from "@/next/log";
+import type { Electron } from "@/next/types/ipc";
import { PICKED_UPLOAD_TYPE } from "constants/upload";
import { Collection } from "types/collection";
import { ElectronFile, FileWithCollection } from "types/upload";
@@ -9,11 +10,20 @@ interface PendingUploads {
type: PICKED_UPLOAD_TYPE;
}
+const electron = (): Electron => {
+ const et = globalThis.electron;
+ if (!et)
+ throw new Error(
+ "Attempting to use ExportService in an unsupported non-electron context",
+ );
+ return et;
+};
+
class ImportService {
async getPendingUploads(): Promise<PendingUploads> {
try {
const pendingUploads =
- (await ElectronAPIs.getPendingUploads()) as PendingUploads;
+ (await electron().getPendingUploads()) as PendingUploads;
return pendingUploads;
} catch (e) {
if (e?.message?.includes("ENOENT: no such file or directory")) {
@@ -39,7 +49,7 @@ class ImportService {
if (collections.length === 1) {
collectionName = collections[0].name;
}
- await ElectronAPIs.setToUploadCollection(collectionName);
+ await electron().setToUploadCollection(collectionName);
}
async updatePendingUploads(files: FileWithCollection[]) {
@@ -56,16 +66,13 @@ class ImportService {
filePaths.push((fileWithCollection.file as ElectronFile).path);
}
}
- await ElectronAPIs.setToUploadFiles(
- PICKED_UPLOAD_TYPE.FILES,
- filePaths,
- );
+ await electron().setToUploadFiles(PICKED_UPLOAD_TYPE.FILES, filePaths);
}
async cancelRemainingUploads() {
- await ElectronAPIs.setToUploadCollection(null);
- await ElectronAPIs.setToUploadFiles(PICKED_UPLOAD_TYPE.ZIPS, []);
- await ElectronAPIs.setToUploadFiles(PICKED_UPLOAD_TYPE.FILES, []);
+ await electron().setToUploadCollection(null);
+ await electron().setToUploadFiles(PICKED_UPLOAD_TYPE.ZIPS, []);
+ await electron().setToUploadFiles(PICKED_UPLOAD_TYPE.FILES, []);
}
}
diff --git a/web/apps/photos/src/services/watchFolder/watchFolderService.ts b/web/apps/photos/src/services/watchFolder/watchFolderService.ts
index b31a3bd87a..6d37c759fd 100644
--- a/web/apps/photos/src/services/watchFolder/watchFolderService.ts
+++ b/web/apps/photos/src/services/watchFolder/watchFolderService.ts
@@ -1,5 +1,5 @@
-import ElectronAPIs from "@/next/electron";
import log from "@/next/log";
+import type { Electron } from "@/next/types/ipc";
import { UPLOAD_RESULT, UPLOAD_STRATEGY } from "constants/upload";
import debounce from "debounce";
import uploadManager from "services/upload/uploadManager";
@@ -22,6 +22,15 @@ import {
diskFolderRemovedCallback,
} from "./watchFolderEventHandlers";
+const electron = (): Electron => {
+ const et = globalThis.electron;
+ if (!et)
+ throw new Error(
+ "Attempting to use ExportService in an unsupported non-electron context",
+ );
+ return et;
+};
+
class watchFolderService {
private eventQueue: EventQueueItem[] = [];
private currentEvent: EventQueueItem;
@@ -83,7 +92,7 @@ class watchFolderService {
for (const mapping of mappings) {
const filesOnDisk: ElectronFile[] =
- await ElectronAPIs.getDirFiles(mapping.folderPath);
+ await electron().getDirFiles(mapping.folderPath);
this.uploadDiffOfFiles(mapping, filesOnDisk);
this.trashDiffOfFiles(mapping, filesOnDisk);
@@ -150,11 +159,9 @@ class watchFolderService {
): Promise<WatchMapping[]> {
const notDeletedMappings = [];
for (const mapping of mappings) {
- const mappingExists = await ElectronAPIs.isFolder(
- mapping.folderPath,
- );
+ const mappingExists = await electron().isFolder(mapping.folderPath);
if (!mappingExists) {
- ElectronAPIs.removeWatchMapping(mapping.folderPath);
+ electron().removeWatchMapping(mapping.folderPath);
} else {
notDeletedMappings.push(mapping);
}
@@ -172,7 +179,7 @@ class watchFolderService {
}
private setupWatcherFunctions() {
- ElectronAPIs.registerWatcherFunctions(
+ electron().registerWatcherFunctions(
diskFileAddedCallback,
diskFileRemovedCallback,
diskFolderRemovedCallback,
@@ -185,7 +192,7 @@ class watchFolderService {
uploadStrategy: UPLOAD_STRATEGY,
) {
try {
- await ElectronAPIs.addWatchMapping(
+ await electron().addWatchMapping(
rootFolderName,
folderPath,
uploadStrategy,
@@ -198,7 +205,7 @@ class watchFolderService {
async removeWatchMapping(folderPath: string) {
try {
- await ElectronAPIs.removeWatchMapping(folderPath);
+ await electron().removeWatchMapping(folderPath);
} catch (e) {
log.error("error while removing watch mapping", e);
}
@@ -206,7 +213,7 @@ class watchFolderService {
async getWatchMappings(): Promise<WatchMapping[]> {
try {
- return (await ElectronAPIs.getWatchMappings()) ?? [];
+ return (await electron().getWatchMappings()) ?? [];
} catch (e) {
log.error("error while getting watch mappings", e);
return [];
@@ -378,7 +385,7 @@ class watchFolderService {
...this.currentlySyncedMapping.syncedFiles,
...syncedFiles,
];
- await ElectronAPIs.updateWatchMappingSyncedFiles(
+ await electron().updateWatchMappingSyncedFiles(
this.currentlySyncedMapping.folderPath,
this.currentlySyncedMapping.syncedFiles,
);
@@ -388,7 +395,7 @@ class watchFolderService {
...this.currentlySyncedMapping.ignoredFiles,
...ignoredFiles,
];
- await ElectronAPIs.updateWatchMappingIgnoredFiles(
+ await electron().updateWatchMappingIgnoredFiles(
this.currentlySyncedMapping.folderPath,
this.currentlySyncedMapping.ignoredFiles,
);
@@ -503,7 +510,7 @@ class watchFolderService {
this.currentlySyncedMapping.syncedFiles.filter(
(file) => !filePathsToRemove.has(file.path),
);
- await ElectronAPIs.updateWatchMappingSyncedFiles(
+ await electron().updateWatchMappingSyncedFiles(
this.currentlySyncedMapping.folderPath,
this.currentlySyncedMapping.syncedFiles,
);
@@ -595,7 +602,7 @@ class watchFolderService {
async selectFolder(): Promise<string> {
try {
- const folderPath = await ElectronAPIs.selectDirectory();
+ const folderPath = await electron().selectDirectory();
return folderPath;
} catch (e) {
log.error("error while selecting folder", e);
@@ -623,7 +630,7 @@ class watchFolderService {
async isFolder(folderPath: string) {
try {
- const isFolder = await ElectronAPIs.isFolder(folderPath);
+ const isFolder = await electron().isFolder(folderPath);
return isFolder;
} catch (e) {
log.error("error while checking if folder exists", e);
diff --git a/web/apps/photos/src/utils/ui/index.tsx b/web/apps/photos/src/utils/ui/index.tsx
index d193ba9605..9090c6917d 100644
--- a/web/apps/photos/src/utils/ui/index.tsx
+++ b/web/apps/photos/src/utils/ui/index.tsx
@@ -1,4 +1,3 @@
-import ElectronAPIs from "@/next/electron";
import { AppUpdateInfo } from "@/next/types/ipc";
import { logoutUser } from "@ente/accounts/services/user";
import { DialogBoxAttributes } from "@ente/shared/components/DialogBox/types";
@@ -60,14 +59,15 @@ export const getUpdateReadyToInstallMessage = (
title: t("UPDATE_AVAILABLE"),
content: t("UPDATE_INSTALLABLE_MESSAGE"),
proceed: {
- action: () => ElectronAPIs.updateAndRestart(),
+ action: () => globalThis.electron?.updateAndRestart(),
text: t("INSTALL_NOW"),
variant: "accent",
},
close: {
text: t("INSTALL_ON_NEXT_LAUNCH"),
variant: "secondary",
- action: () => ElectronAPIs.muteUpdateNotification(updateInfo.version),
+ action: () =>
+ globalThis.electron?.muteUpdateNotification(updateInfo.version),
},
});
@@ -80,7 +80,7 @@ export const getUpdateAvailableForDownloadMessage = (
close: {
text: t("IGNORE_THIS_VERSION"),
variant: "secondary",
- action: () => ElectronAPIs.skipAppUpdate(updateInfo.version),
+ action: () => globalThis.electron?.skipAppUpdate(updateInfo.version),
},
proceed: {
action: downloadApp,
diff --git a/web/apps/photos/tests/zip-file-reading.test.ts b/web/apps/photos/tests/zip-file-reading.test.ts
index 38be7ae754..6ac20bfeed 100644
--- a/web/apps/photos/tests/zip-file-reading.test.ts
+++ b/web/apps/photos/tests/zip-file-reading.test.ts
@@ -1,7 +1,5 @@
-import ElectronAPIs from "@/next/electron";
import { getFileNameSize } from "@/next/file";
import { FILE_READER_CHUNK_SIZE, PICKED_UPLOAD_TYPE } from "constants/upload";
-import isElectron from "is-electron";
import { getElectronFileStream, getFileStream } from "services/readerService";
import { DataStream } from "types/upload";
import { getImportSuggestion } from "utils/upload";
@@ -12,7 +10,8 @@ import { getImportSuggestion } from "utils/upload";
// sizes starting from 1M to 20M.
export const testZipFileReading = async () => {
try {
- if (!isElectron()) {
+ const electron = globalThis.electron;
+ if (!electron) {
console.log("testZipFileReading Check is for desktop only");
return;
}
@@ -21,7 +20,7 @@ export const testZipFileReading = async () => {
"upload test failed NEXT_PUBLIC_FILE_READING_TEST_ZIP_PATH missing",
);
}
- const files = await ElectronAPIs.getElectronFilesFromGoogleZip(
+ const files = await electron.getElectronFilesFromGoogleZip(
process.env.NEXT_PUBLIC_FILE_READING_TEST_ZIP_PATH,
);
if (!files?.length) {
@@ -81,7 +80,8 @@ export const testZipFileReading = async () => {
// at the root.
export const testZipWithRootFileReadingTest = async () => {
try {
- if (!isElectron()) {
+ const electron = globalThis.electron;
+ if (!electron) {
console.log("testZipFileReading Check is for desktop only");
return;
}
@@ -90,7 +90,7 @@ export const testZipWithRootFileReadingTest = async () => {
"upload test failed NEXT_PUBLIC_ZIP_WITH_ROOT_FILE_PATH missing",
);
}
- const files = await ElectronAPIs.getElectronFilesFromGoogleZip(
+ const files = await electron.getElectronFilesFromGoogleZip(
process.env.NEXT_PUBLIC_ZIP_WITH_ROOT_FILE_PATH,
);
diff --git a/web/packages/accounts/pages/credentials.tsx b/web/packages/accounts/pages/credentials.tsx
index e2f4ea70ec..bf5943238a 100644
--- a/web/packages/accounts/pages/credentials.tsx
+++ b/web/packages/accounts/pages/credentials.tsx
@@ -1,4 +1,3 @@
-import ElectronAPIs from "@/next/electron";
import log from "@/next/log";
import { APP_HOMES } from "@ente/shared/apps/constants";
import { PageProps } from "@ente/shared/apps/types";
@@ -41,7 +40,6 @@ import {
} from "@ente/shared/storage/sessionStorage";
import { KeyAttributes, User } from "@ente/shared/user/types";
import { t } from "i18next";
-import isElectron from "is-electron";
import { useRouter } from "next/router";
import { useEffect, useState } from "react";
import { getSRPAttributes } from "../api/srp";
@@ -69,9 +67,10 @@ export default function Credentials({ appContext, appName }: PageProps) {
}
setUser(user);
let key = getKey(SESSION_KEYS.ENCRYPTION_KEY);
- if (!key && isElectron()) {
+ const electron = globalThis.electron;
+ if (!key && electron) {
try {
- key = await ElectronAPIs.getEncryptionKey();
+ key = await electron.getEncryptionKey();
} catch (e) {
log.error("getEncryptionKey failed", e);
}
diff --git a/web/packages/accounts/services/user.ts b/web/packages/accounts/services/user.ts
index d481cfd8a1..43d2f0883f 100644
--- a/web/packages/accounts/services/user.ts
+++ b/web/packages/accounts/services/user.ts
@@ -1,4 +1,3 @@
-import ElectronAPIs from "@/next/electron";
import log from "@/next/log";
import { Events, eventBus } from "@ente/shared/events";
import InMemoryStore from "@ente/shared/storage/InMemoryStore";
@@ -6,7 +5,6 @@ import { deleteAllCache } from "@ente/shared/storage/cacheStorage/helpers";
import { clearFiles } from "@ente/shared/storage/localForage/helpers";
import { clearData } from "@ente/shared/storage/localStorage";
import { clearKeys } from "@ente/shared/storage/sessionStorage";
-import isElectron from "is-electron";
import router from "next/router";
import { _logout } from "../api/user";
import { PAGES } from "../constants/pages";
@@ -44,12 +42,10 @@ export const logoutUser = async () => {
} catch (e) {
log.error("clearFiles failed", e);
}
- if (isElectron()) {
- try {
- ElectronAPIs.clearElectronStore();
- } catch (e) {
- log.error("clearElectronStore failed", e);
- }
+ try {
+ globalThis.electron?.clearElectronStore();
+ } catch (e) {
+ log.error("clearElectronStore failed", e);
}
try {
eventBus.emit(Events.LOGOUT);