More transition

This commit is contained in:
Manav Rathi 2024-04-09 12:12:25 +05:30
parent d441418b5b
commit 56ce5c0b0e
No known key found for this signature in database
9 changed files with 126 additions and 122 deletions

View file

@ -61,37 +61,10 @@ import {
} from "utils/file"; } from "utils/file";
import log from "@/next/log"; 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 { APPS } from "@ente/shared/apps/constants";
import { CenteredFlex } from "@ente/shared/components/Container"; 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 useFileInput from "@ente/shared/hooks/useFileInput";
import useMemoSingleThreaded from "@ente/shared/hooks/useMemoSingleThreaded"; import useMemoSingleThreaded from "@ente/shared/hooks/useMemoSingleThreaded";
import InMemoryStore, { MS_KEYS } from "@ente/shared/storage/InMemoryStore"; 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 { isPromise } from "@ente/shared/utils";
import AuthenticateUserModal from "components/AuthenticateUserModal"; import AuthenticateUserModal from "components/AuthenticateUserModal";
import Collections from "components/Collections"; import Collections from "components/Collections";
import CollectionNamer, {
CollectionNamerAttributes,
} from "components/Collections/CollectionNamer";
import ExportModal from "components/ExportModal"; import ExportModal from "components/ExportModal";
import { import {
FilesDownloadProgress, FilesDownloadProgress,
@ -112,16 +88,27 @@ import FixCreationTime, {
import GalleryEmptyState from "components/GalleryEmptyState"; import GalleryEmptyState from "components/GalleryEmptyState";
import { ITEM_TYPE, TimeStampListItem } from "components/PhotoList"; import { ITEM_TYPE, TimeStampListItem } from "components/PhotoList";
import SearchResultInfo from "components/Search/SearchResultInfo"; import SearchResultInfo from "components/Search/SearchResultInfo";
import Uploader from "components/Upload/Uploader";
import UploadInputs from "components/UploadSelectorInputs"; import UploadInputs from "components/UploadSelectorInputs";
import { GalleryNavbar } from "components/pages/gallery/Navbar"; 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 { SYNC_INTERVAL_IN_MICROSECONDS } from "constants/gallery";
import isElectron from "is-electron"; import { AppContext } from "pages/_app";
import { ClipService } from "services/clipService"; import { ClipService } from "services/clipService";
import { constructUserIDToEmailMap } from "services/collectionService"; import { constructUserIDToEmailMap } from "services/collectionService";
import downloadManager from "services/download"; import downloadManager from "services/download";
import { syncEmbeddings } from "services/embeddingService"; import { syncEmbeddings } from "services/embeddingService";
import { syncEntities } from "services/entityService"; import { syncEntities } from "services/entityService";
import locationSearchService from "services/locationSearchService"; import locationSearchService from "services/locationSearchService";
import { getLocalTrashedFiles, syncTrash } from "services/trashService";
import uploadManager from "services/upload/uploadManager"; import uploadManager from "services/upload/uploadManager";
import { Collection, CollectionSummaries } from "types/collection"; import { Collection, CollectionSummaries } from "types/collection";
import { EnteFile } from "types/file"; import { EnteFile } from "types/file";
@ -134,6 +121,16 @@ import {
} from "types/gallery"; } from "types/gallery";
import { Search, SearchResultSummary, UpdateSearch } from "types/search"; import { Search, SearchResultSummary, UpdateSearch } from "types/search";
import { FamilyData } from "types/user"; 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 ComlinkSearchWorker from "utils/comlink/ComlinkSearchWorker";
import { isArchivedFile } from "utils/magicMetadata"; import { isArchivedFile } from "utils/magicMetadata";
import { getSessionExpiredMessage } from "utils/ui"; import { getSessionExpiredMessage } from "utils/ui";
@ -321,6 +318,7 @@ export default function Gallery() {
return; return;
} }
preloadImage("/images/subscription-card-background"); preloadImage("/images/subscription-card-background");
const electron = globalThis.electron;
const main = async () => { const main = async () => {
const valid = await validateKey(); const valid = await validateKey();
if (!valid) { if (!valid) {
@ -363,9 +361,9 @@ export default function Gallery() {
syncInterval.current = setInterval(() => { syncInterval.current = setInterval(() => {
syncWithRemote(false, true); syncWithRemote(false, true);
}, SYNC_INTERVAL_IN_MICROSECONDS); }, SYNC_INTERVAL_IN_MICROSECONDS);
if (isElectron()) { if (electron) {
void ClipService.setupOnFileUploadListener(); void ClipService.setupOnFileUploadListener();
ElectronAPIs.registerForegroundEventListener(() => { electron.registerForegroundEventListener(() => {
syncWithRemote(false, true); syncWithRemote(false, true);
}); });
} }
@ -373,8 +371,8 @@ export default function Gallery() {
main(); main();
return () => { return () => {
clearInterval(syncInterval.current); clearInterval(syncInterval.current);
if (isElectron()) { if (electron) {
ElectronAPIs.registerForegroundEventListener(() => {}); electron.registerForegroundEventListener(() => {});
ClipService.removeOnFileUploadListener(); ClipService.removeOnFileUploadListener();
} }
}; };

View file

@ -1,5 +1,4 @@
import log from "@/next/log"; import log from "@/next/log";
import type { Electron } from "@/next/types/ipc";
import { CustomError } from "@ente/shared/error"; import { CustomError } from "@ente/shared/error";
import { Events, eventBus } from "@ente/shared/events"; import { Events, eventBus } from "@ente/shared/events";
import { LS_KEYS, getData, setData } from "@ente/shared/storage/localStorage"; import { LS_KEYS, getData, setData } from "@ente/shared/storage/localStorage";
@ -58,6 +57,7 @@ import downloadManager from "../download";
import { getAllLocalFiles } from "../fileService"; import { getAllLocalFiles } from "../fileService";
import { decodeLivePhoto } from "../livePhotoService"; import { decodeLivePhoto } from "../livePhotoService";
import { migrateExport } from "./migration"; import { migrateExport } from "./migration";
import type { Electron } from "@/next/types/ipc";
const EXPORT_RECORD_FILE_NAME = "export_status.json"; const EXPORT_RECORD_FILE_NAME = "export_status.json";
@ -71,7 +71,14 @@ export const NULL_EXPORT_RECORD: ExportRecord = {
collectionExportNames: {}, 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 { class ExportService {
private exportSettings: ExportSettings; private exportSettings: ExportSettings;
@ -92,15 +99,6 @@ class ExportService {
failed: 0, 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 { getExportSettings(): ExportSettings {
try { try {
if (this.exportSettings) { if (this.exportSettings) {
@ -168,12 +166,12 @@ class ExportService {
async changeExportDirectory() { async changeExportDirectory() {
try { try {
const newRootDir = await electron.selectDirectory(); const newRootDir = await electron().selectDirectory();
if (!newRootDir) { if (!newRootDir) {
throw Error(CustomError.SELECT_FOLDER_ABORTED); throw Error(CustomError.SELECT_FOLDER_ABORTED);
} }
const newExportDir = `${newRootDir}/${ENTE_EXPORT_DIRECTORY}`; const newExportDir = `${newRootDir}/${ENTE_EXPORT_DIRECTORY}`;
await electron.checkExistsAndCreateDir(newExportDir); await electron().checkExistsAndCreateDir(newExportDir);
return newExportDir; return newExportDir;
} catch (e) { } catch (e) {
if (e.message !== CustomError.SELECT_FOLDER_ABORTED) { if (e.message !== CustomError.SELECT_FOLDER_ABORTED) {
@ -523,7 +521,7 @@ class ExportService {
newCollectionExportName, newCollectionExportName,
); );
try { try {
await electron.rename( await electron().rename(
oldCollectionExportPath, oldCollectionExportPath,
newCollectionExportPath, newCollectionExportPath,
); );
@ -608,11 +606,11 @@ class ExportService {
); );
try { try {
// delete the collection metadata folder // delete the collection metadata folder
await electron.deleteFolder( await electron().deleteFolder(
getMetadataFolderExportPath(collectionExportPath), getMetadataFolderExportPath(collectionExportPath),
); );
// delete the collection folder // delete the collection folder
await electron.deleteFolder(collectionExportPath); await electron().deleteFolder(collectionExportPath);
} catch (e) { } catch (e) {
await this.addCollectionExportedRecord( await this.addCollectionExportedRecord(
exportFolder, exportFolder,
@ -695,10 +693,10 @@ class ExportService {
exportDir, exportDir,
collectionExportName, collectionExportName,
); );
await electron.checkExistsAndCreateDir( await electron().checkExistsAndCreateDir(
collectionExportPath, collectionExportPath,
); );
await electron.checkExistsAndCreateDir( await electron().checkExistsAndCreateDir(
getMetadataFolderExportPath(collectionExportPath), getMetadataFolderExportPath(collectionExportPath),
); );
await this.downloadAndSave( await this.downloadAndSave(
@ -778,7 +776,7 @@ class ExportService {
`moving image file ${imageExportPath} to trash folder`, `moving image file ${imageExportPath} to trash folder`,
); );
if (await this.exists(imageExportPath)) { if (await this.exists(imageExportPath)) {
await electron.moveFile( await electron().moveFile(
imageExportPath, imageExportPath,
await getTrashedFileExportPath( await getTrashedFileExportPath(
exportDir, exportDir,
@ -793,7 +791,7 @@ class ExportService {
if ( if (
await this.exists(imageMetadataFileExportPath) await this.exists(imageMetadataFileExportPath)
) { ) {
await electron.moveFile( await electron().moveFile(
imageMetadataFileExportPath, imageMetadataFileExportPath,
await getTrashedFileExportPath( await getTrashedFileExportPath(
exportDir, exportDir,
@ -810,7 +808,7 @@ class ExportService {
`moving video file ${videoExportPath} to trash folder`, `moving video file ${videoExportPath} to trash folder`,
); );
if (await this.exists(videoExportPath)) { if (await this.exists(videoExportPath)) {
await electron.moveFile( await electron().moveFile(
videoExportPath, videoExportPath,
await getTrashedFileExportPath( await getTrashedFileExportPath(
exportDir, exportDir,
@ -823,7 +821,7 @@ class ExportService {
if ( if (
await this.exists(videoMetadataFileExportPath) await this.exists(videoMetadataFileExportPath)
) { ) {
await electron.moveFile( await electron().moveFile(
videoMetadataFileExportPath, videoMetadataFileExportPath,
await getTrashedFileExportPath( await getTrashedFileExportPath(
exportDir, exportDir,
@ -845,7 +843,7 @@ class ExportService {
`moving file ${fileExportPath} to ${trashedFilePath} trash folder`, `moving file ${fileExportPath} to ${trashedFilePath} trash folder`,
); );
if (await this.exists(fileExportPath)) { if (await this.exists(fileExportPath)) {
await electron.moveFile( await electron().moveFile(
fileExportPath, fileExportPath,
trashedFilePath, trashedFilePath,
); );
@ -853,7 +851,7 @@ class ExportService {
const metadataFileExportPath = const metadataFileExportPath =
getMetadataFileExportPath(fileExportPath); getMetadataFileExportPath(fileExportPath);
if (await this.exists(metadataFileExportPath)) { if (await this.exists(metadataFileExportPath)) {
await electron.moveFile( await electron().moveFile(
metadataFileExportPath, metadataFileExportPath,
await getTrashedFileExportPath( await getTrashedFileExportPath(
exportDir, exportDir,
@ -992,7 +990,7 @@ class ExportService {
try { try {
const exportRecord = await this.getExportRecord(folder); const exportRecord = await this.getExportRecord(folder);
const newRecord: ExportRecord = { ...exportRecord, ...newData }; const newRecord: ExportRecord = { ...exportRecord, ...newData };
await electron.saveFileToDisk( await electron().saveFileToDisk(
`${folder}/${EXPORT_RECORD_FILE_NAME}`, `${folder}/${EXPORT_RECORD_FILE_NAME}`,
JSON.stringify(newRecord, null, 2), JSON.stringify(newRecord, null, 2),
); );
@ -1014,7 +1012,7 @@ class ExportService {
return this.createEmptyExportRecord(exportRecordJSONPath); return this.createEmptyExportRecord(exportRecordJSONPath);
} }
const recordFile = const recordFile =
await electron.readTextFile(exportRecordJSONPath); await electron().readTextFile(exportRecordJSONPath);
try { try {
return JSON.parse(recordFile); return JSON.parse(recordFile);
} catch (e) { } catch (e) {
@ -1050,8 +1048,8 @@ class ExportService {
exportFolder, exportFolder,
collectionExportName, collectionExportName,
); );
await electron.checkExistsAndCreateDir(collectionExportPath); await electron().checkExistsAndCreateDir(collectionExportPath);
await electron.checkExistsAndCreateDir( await electron().checkExistsAndCreateDir(
getMetadataFolderExportPath(collectionExportPath), getMetadataFolderExportPath(collectionExportPath),
); );
@ -1098,7 +1096,7 @@ class ExportService {
fileExportName, fileExportName,
file, file,
); );
await electron.saveStreamToDisk( await electron().saveStreamToDisk(
getFileExportPath(collectionExportPath, fileExportName), getFileExportPath(collectionExportPath, fileExportName),
updatedFileStream, updatedFileStream,
); );
@ -1146,7 +1144,7 @@ class ExportService {
imageExportName, imageExportName,
file, file,
); );
await electron.saveStreamToDisk( await electron().saveStreamToDisk(
getFileExportPath(collectionExportPath, imageExportName), getFileExportPath(collectionExportPath, imageExportName),
imageStream, imageStream,
); );
@ -1158,12 +1156,12 @@ class ExportService {
file, file,
); );
try { try {
await electron.saveStreamToDisk( await electron().saveStreamToDisk(
getFileExportPath(collectionExportPath, videoExportName), getFileExportPath(collectionExportPath, videoExportName),
videoStream, videoStream,
); );
} catch (e) { } catch (e) {
await electron.deleteFile( await electron().deleteFile(
getFileExportPath(collectionExportPath, imageExportName), getFileExportPath(collectionExportPath, imageExportName),
); );
throw e; throw e;
@ -1179,7 +1177,7 @@ class ExportService {
fileExportName: string, fileExportName: string,
file: EnteFile, file: EnteFile,
) { ) {
await electron.saveFileToDisk( await electron().saveFileToDisk(
getFileMetadataExportPath(collectionExportPath, fileExportName), getFileMetadataExportPath(collectionExportPath, fileExportName),
getGoogleLikeMetadataFile(fileExportName, file), getGoogleLikeMetadataFile(fileExportName, file),
); );
@ -1190,15 +1188,15 @@ class ExportService {
}; };
exists = (path: string) => { exists = (path: string) => {
return electron.fs.exists(path); return electron().fs.exists(path);
}; };
rename = (oldPath: string, newPath: string) => { rename = (oldPath: string, newPath: string) => {
return electron.rename(oldPath, newPath); return electron().rename(oldPath, newPath);
}; };
checkExistsAndCreateDir = (path: string) => { checkExistsAndCreateDir = (path: string) => {
return electron.checkExistsAndCreateDir(path); return electron().checkExistsAndCreateDir(path);
}; };
exportFolderExists = async (exportFolder: string) => { exportFolderExists = async (exportFolder: string) => {
@ -1220,7 +1218,7 @@ class ExportService {
private createEmptyExportRecord = async (exportRecordJSONPath: string) => { private createEmptyExportRecord = async (exportRecordJSONPath: string) => {
const exportRecord: ExportRecord = NULL_EXPORT_RECORD; const exportRecord: ExportRecord = NULL_EXPORT_RECORD;
await electron.saveFileToDisk( await electron().saveFileToDisk(
exportRecordJSONPath, exportRecordJSONPath,
JSON.stringify(exportRecord, null, 2), JSON.stringify(exportRecord, null, 2),
); );

View file

@ -1,5 +1,3 @@
import ElectronAPIs from "@/next/electron";
import isElectron from "is-electron";
import { ElectronFile } from "types/upload"; import { ElectronFile } from "types/upload";
import ComlinkFFmpegWorker from "utils/comlink/ComlinkFFmpegWorker"; import ComlinkFFmpegWorker from "utils/comlink/ComlinkFFmpegWorker";
@ -16,10 +14,11 @@ class FFmpegFactory {
private client: IFFmpeg; private client: IFFmpeg;
async getFFmpegClient() { async getFFmpegClient() {
if (!this.client) { if (!this.client) {
if (isElectron()) { const electron = globalThis.electron;
if (electron) {
this.client = { this.client = {
run(cmd, inputFile, outputFilename, dontTimeout) { run(cmd, inputFile, outputFilename, dontTimeout) {
return ElectronAPIs.runFFmpegCmd( return electron.runFFmpegCmd(
cmd, cmd,
inputFile, inputFile,
outputFilename, outputFilename,

View file

@ -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 { PICKED_UPLOAD_TYPE } from "constants/upload";
import { Collection } from "types/collection"; import { Collection } from "types/collection";
import { ElectronFile, FileWithCollection } from "types/upload"; import { ElectronFile, FileWithCollection } from "types/upload";
@ -9,11 +10,20 @@ interface PendingUploads {
type: PICKED_UPLOAD_TYPE; 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 { class ImportService {
async getPendingUploads(): Promise<PendingUploads> { async getPendingUploads(): Promise<PendingUploads> {
try { try {
const pendingUploads = const pendingUploads =
(await ElectronAPIs.getPendingUploads()) as PendingUploads; (await electron().getPendingUploads()) as PendingUploads;
return pendingUploads; return pendingUploads;
} catch (e) { } catch (e) {
if (e?.message?.includes("ENOENT: no such file or directory")) { if (e?.message?.includes("ENOENT: no such file or directory")) {
@ -39,7 +49,7 @@ class ImportService {
if (collections.length === 1) { if (collections.length === 1) {
collectionName = collections[0].name; collectionName = collections[0].name;
} }
await ElectronAPIs.setToUploadCollection(collectionName); await electron().setToUploadCollection(collectionName);
} }
async updatePendingUploads(files: FileWithCollection[]) { async updatePendingUploads(files: FileWithCollection[]) {
@ -56,16 +66,13 @@ class ImportService {
filePaths.push((fileWithCollection.file as ElectronFile).path); filePaths.push((fileWithCollection.file as ElectronFile).path);
} }
} }
await ElectronAPIs.setToUploadFiles( await electron().setToUploadFiles(PICKED_UPLOAD_TYPE.FILES, filePaths);
PICKED_UPLOAD_TYPE.FILES,
filePaths,
);
} }
async cancelRemainingUploads() { async cancelRemainingUploads() {
await ElectronAPIs.setToUploadCollection(null); await electron().setToUploadCollection(null);
await ElectronAPIs.setToUploadFiles(PICKED_UPLOAD_TYPE.ZIPS, []); await electron().setToUploadFiles(PICKED_UPLOAD_TYPE.ZIPS, []);
await ElectronAPIs.setToUploadFiles(PICKED_UPLOAD_TYPE.FILES, []); await electron().setToUploadFiles(PICKED_UPLOAD_TYPE.FILES, []);
} }
} }

View file

@ -1,5 +1,5 @@
import ElectronAPIs from "@/next/electron";
import log from "@/next/log"; import log from "@/next/log";
import type { Electron } from "@/next/types/ipc";
import { UPLOAD_RESULT, UPLOAD_STRATEGY } from "constants/upload"; import { UPLOAD_RESULT, UPLOAD_STRATEGY } from "constants/upload";
import debounce from "debounce"; import debounce from "debounce";
import uploadManager from "services/upload/uploadManager"; import uploadManager from "services/upload/uploadManager";
@ -22,6 +22,15 @@ import {
diskFolderRemovedCallback, diskFolderRemovedCallback,
} from "./watchFolderEventHandlers"; } 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 { class watchFolderService {
private eventQueue: EventQueueItem[] = []; private eventQueue: EventQueueItem[] = [];
private currentEvent: EventQueueItem; private currentEvent: EventQueueItem;
@ -83,7 +92,7 @@ class watchFolderService {
for (const mapping of mappings) { for (const mapping of mappings) {
const filesOnDisk: ElectronFile[] = const filesOnDisk: ElectronFile[] =
await ElectronAPIs.getDirFiles(mapping.folderPath); await electron().getDirFiles(mapping.folderPath);
this.uploadDiffOfFiles(mapping, filesOnDisk); this.uploadDiffOfFiles(mapping, filesOnDisk);
this.trashDiffOfFiles(mapping, filesOnDisk); this.trashDiffOfFiles(mapping, filesOnDisk);
@ -150,11 +159,9 @@ class watchFolderService {
): Promise<WatchMapping[]> { ): Promise<WatchMapping[]> {
const notDeletedMappings = []; const notDeletedMappings = [];
for (const mapping of mappings) { for (const mapping of mappings) {
const mappingExists = await ElectronAPIs.isFolder( const mappingExists = await electron().isFolder(mapping.folderPath);
mapping.folderPath,
);
if (!mappingExists) { if (!mappingExists) {
ElectronAPIs.removeWatchMapping(mapping.folderPath); electron().removeWatchMapping(mapping.folderPath);
} else { } else {
notDeletedMappings.push(mapping); notDeletedMappings.push(mapping);
} }
@ -172,7 +179,7 @@ class watchFolderService {
} }
private setupWatcherFunctions() { private setupWatcherFunctions() {
ElectronAPIs.registerWatcherFunctions( electron().registerWatcherFunctions(
diskFileAddedCallback, diskFileAddedCallback,
diskFileRemovedCallback, diskFileRemovedCallback,
diskFolderRemovedCallback, diskFolderRemovedCallback,
@ -185,7 +192,7 @@ class watchFolderService {
uploadStrategy: UPLOAD_STRATEGY, uploadStrategy: UPLOAD_STRATEGY,
) { ) {
try { try {
await ElectronAPIs.addWatchMapping( await electron().addWatchMapping(
rootFolderName, rootFolderName,
folderPath, folderPath,
uploadStrategy, uploadStrategy,
@ -198,7 +205,7 @@ class watchFolderService {
async removeWatchMapping(folderPath: string) { async removeWatchMapping(folderPath: string) {
try { try {
await ElectronAPIs.removeWatchMapping(folderPath); await electron().removeWatchMapping(folderPath);
} catch (e) { } catch (e) {
log.error("error while removing watch mapping", e); log.error("error while removing watch mapping", e);
} }
@ -206,7 +213,7 @@ class watchFolderService {
async getWatchMappings(): Promise<WatchMapping[]> { async getWatchMappings(): Promise<WatchMapping[]> {
try { try {
return (await ElectronAPIs.getWatchMappings()) ?? []; return (await electron().getWatchMappings()) ?? [];
} catch (e) { } catch (e) {
log.error("error while getting watch mappings", e); log.error("error while getting watch mappings", e);
return []; return [];
@ -378,7 +385,7 @@ class watchFolderService {
...this.currentlySyncedMapping.syncedFiles, ...this.currentlySyncedMapping.syncedFiles,
...syncedFiles, ...syncedFiles,
]; ];
await ElectronAPIs.updateWatchMappingSyncedFiles( await electron().updateWatchMappingSyncedFiles(
this.currentlySyncedMapping.folderPath, this.currentlySyncedMapping.folderPath,
this.currentlySyncedMapping.syncedFiles, this.currentlySyncedMapping.syncedFiles,
); );
@ -388,7 +395,7 @@ class watchFolderService {
...this.currentlySyncedMapping.ignoredFiles, ...this.currentlySyncedMapping.ignoredFiles,
...ignoredFiles, ...ignoredFiles,
]; ];
await ElectronAPIs.updateWatchMappingIgnoredFiles( await electron().updateWatchMappingIgnoredFiles(
this.currentlySyncedMapping.folderPath, this.currentlySyncedMapping.folderPath,
this.currentlySyncedMapping.ignoredFiles, this.currentlySyncedMapping.ignoredFiles,
); );
@ -503,7 +510,7 @@ class watchFolderService {
this.currentlySyncedMapping.syncedFiles.filter( this.currentlySyncedMapping.syncedFiles.filter(
(file) => !filePathsToRemove.has(file.path), (file) => !filePathsToRemove.has(file.path),
); );
await ElectronAPIs.updateWatchMappingSyncedFiles( await electron().updateWatchMappingSyncedFiles(
this.currentlySyncedMapping.folderPath, this.currentlySyncedMapping.folderPath,
this.currentlySyncedMapping.syncedFiles, this.currentlySyncedMapping.syncedFiles,
); );
@ -595,7 +602,7 @@ class watchFolderService {
async selectFolder(): Promise<string> { async selectFolder(): Promise<string> {
try { try {
const folderPath = await ElectronAPIs.selectDirectory(); const folderPath = await electron().selectDirectory();
return folderPath; return folderPath;
} catch (e) { } catch (e) {
log.error("error while selecting folder", e); log.error("error while selecting folder", e);
@ -623,7 +630,7 @@ class watchFolderService {
async isFolder(folderPath: string) { async isFolder(folderPath: string) {
try { try {
const isFolder = await ElectronAPIs.isFolder(folderPath); const isFolder = await electron().isFolder(folderPath);
return isFolder; return isFolder;
} catch (e) { } catch (e) {
log.error("error while checking if folder exists", e); log.error("error while checking if folder exists", e);

View file

@ -1,4 +1,3 @@
import ElectronAPIs from "@/next/electron";
import { AppUpdateInfo } from "@/next/types/ipc"; import { AppUpdateInfo } from "@/next/types/ipc";
import { logoutUser } from "@ente/accounts/services/user"; import { logoutUser } from "@ente/accounts/services/user";
import { DialogBoxAttributes } from "@ente/shared/components/DialogBox/types"; import { DialogBoxAttributes } from "@ente/shared/components/DialogBox/types";
@ -60,14 +59,15 @@ export const getUpdateReadyToInstallMessage = (
title: t("UPDATE_AVAILABLE"), title: t("UPDATE_AVAILABLE"),
content: t("UPDATE_INSTALLABLE_MESSAGE"), content: t("UPDATE_INSTALLABLE_MESSAGE"),
proceed: { proceed: {
action: () => ElectronAPIs.updateAndRestart(), action: () => globalThis.electron?.updateAndRestart(),
text: t("INSTALL_NOW"), text: t("INSTALL_NOW"),
variant: "accent", variant: "accent",
}, },
close: { close: {
text: t("INSTALL_ON_NEXT_LAUNCH"), text: t("INSTALL_ON_NEXT_LAUNCH"),
variant: "secondary", variant: "secondary",
action: () => ElectronAPIs.muteUpdateNotification(updateInfo.version), action: () =>
globalThis.electron?.muteUpdateNotification(updateInfo.version),
}, },
}); });
@ -80,7 +80,7 @@ export const getUpdateAvailableForDownloadMessage = (
close: { close: {
text: t("IGNORE_THIS_VERSION"), text: t("IGNORE_THIS_VERSION"),
variant: "secondary", variant: "secondary",
action: () => ElectronAPIs.skipAppUpdate(updateInfo.version), action: () => globalThis.electron?.skipAppUpdate(updateInfo.version),
}, },
proceed: { proceed: {
action: downloadApp, action: downloadApp,

View file

@ -1,7 +1,5 @@
import ElectronAPIs from "@/next/electron";
import { getFileNameSize } from "@/next/file"; import { getFileNameSize } from "@/next/file";
import { FILE_READER_CHUNK_SIZE, PICKED_UPLOAD_TYPE } from "constants/upload"; import { FILE_READER_CHUNK_SIZE, PICKED_UPLOAD_TYPE } from "constants/upload";
import isElectron from "is-electron";
import { getElectronFileStream, getFileStream } from "services/readerService"; import { getElectronFileStream, getFileStream } from "services/readerService";
import { DataStream } from "types/upload"; import { DataStream } from "types/upload";
import { getImportSuggestion } from "utils/upload"; import { getImportSuggestion } from "utils/upload";
@ -12,7 +10,8 @@ import { getImportSuggestion } from "utils/upload";
// sizes starting from 1M to 20M. // sizes starting from 1M to 20M.
export const testZipFileReading = async () => { export const testZipFileReading = async () => {
try { try {
if (!isElectron()) { const electron = globalThis.electron;
if (!electron) {
console.log("testZipFileReading Check is for desktop only"); console.log("testZipFileReading Check is for desktop only");
return; return;
} }
@ -21,7 +20,7 @@ export const testZipFileReading = async () => {
"upload test failed NEXT_PUBLIC_FILE_READING_TEST_ZIP_PATH missing", "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, process.env.NEXT_PUBLIC_FILE_READING_TEST_ZIP_PATH,
); );
if (!files?.length) { if (!files?.length) {
@ -81,7 +80,8 @@ export const testZipFileReading = async () => {
// at the root. // at the root.
export const testZipWithRootFileReadingTest = async () => { export const testZipWithRootFileReadingTest = async () => {
try { try {
if (!isElectron()) { const electron = globalThis.electron;
if (!electron) {
console.log("testZipFileReading Check is for desktop only"); console.log("testZipFileReading Check is for desktop only");
return; return;
} }
@ -90,7 +90,7 @@ export const testZipWithRootFileReadingTest = async () => {
"upload test failed NEXT_PUBLIC_ZIP_WITH_ROOT_FILE_PATH missing", "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, process.env.NEXT_PUBLIC_ZIP_WITH_ROOT_FILE_PATH,
); );

View file

@ -1,4 +1,3 @@
import ElectronAPIs from "@/next/electron";
import log from "@/next/log"; import log from "@/next/log";
import { APP_HOMES } from "@ente/shared/apps/constants"; import { APP_HOMES } from "@ente/shared/apps/constants";
import { PageProps } from "@ente/shared/apps/types"; import { PageProps } from "@ente/shared/apps/types";
@ -41,7 +40,6 @@ import {
} from "@ente/shared/storage/sessionStorage"; } from "@ente/shared/storage/sessionStorage";
import { KeyAttributes, User } from "@ente/shared/user/types"; import { KeyAttributes, User } from "@ente/shared/user/types";
import { t } from "i18next"; import { t } from "i18next";
import isElectron from "is-electron";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { getSRPAttributes } from "../api/srp"; import { getSRPAttributes } from "../api/srp";
@ -69,9 +67,10 @@ export default function Credentials({ appContext, appName }: PageProps) {
} }
setUser(user); setUser(user);
let key = getKey(SESSION_KEYS.ENCRYPTION_KEY); let key = getKey(SESSION_KEYS.ENCRYPTION_KEY);
if (!key && isElectron()) { const electron = globalThis.electron;
if (!key && electron) {
try { try {
key = await ElectronAPIs.getEncryptionKey(); key = await electron.getEncryptionKey();
} catch (e) { } catch (e) {
log.error("getEncryptionKey failed", e); log.error("getEncryptionKey failed", e);
} }

View file

@ -1,4 +1,3 @@
import ElectronAPIs from "@/next/electron";
import log from "@/next/log"; import log from "@/next/log";
import { Events, eventBus } from "@ente/shared/events"; import { Events, eventBus } from "@ente/shared/events";
import InMemoryStore from "@ente/shared/storage/InMemoryStore"; 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 { clearFiles } from "@ente/shared/storage/localForage/helpers";
import { clearData } from "@ente/shared/storage/localStorage"; import { clearData } from "@ente/shared/storage/localStorage";
import { clearKeys } from "@ente/shared/storage/sessionStorage"; import { clearKeys } from "@ente/shared/storage/sessionStorage";
import isElectron from "is-electron";
import router from "next/router"; import router from "next/router";
import { _logout } from "../api/user"; import { _logout } from "../api/user";
import { PAGES } from "../constants/pages"; import { PAGES } from "../constants/pages";
@ -44,12 +42,10 @@ export const logoutUser = async () => {
} catch (e) { } catch (e) {
log.error("clearFiles failed", e); log.error("clearFiles failed", e);
} }
if (isElectron()) { try {
try { globalThis.electron?.clearElectronStore();
ElectronAPIs.clearElectronStore(); } catch (e) {
} catch (e) { log.error("clearElectronStore failed", e);
log.error("clearElectronStore failed", e);
}
} }
try { try {
eventBus.emit(Events.LOGOUT); eventBus.emit(Events.LOGOUT);