Skip to content

armgit / ente

Public Imported from GitHub
0

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

add support to detect unsupported platform and stop trying to run clip

Abhinav78c87d1df548
diff --git a/apps/photos/src/pages/gallery/index.tsx b/apps/photos/src/pages/gallery/index.tsx
index 78c1025f2d..1eeb3e165b 100644
--- a/apps/photos/src/pages/gallery/index.tsx
+++ b/apps/photos/src/pages/gallery/index.tsx
@@ -335,7 +335,6 @@ export default function Gallery() {
setHiddenFiles(hiddenFiles);
setCollections(normalCollections);
setHiddenCollections(hiddenCollections);
- void ClipService.setupOnFileUploadListener();
await syncWithRemote(true);
setIsFirstLoad(false);
setJustSignedUp(false);
@@ -344,6 +343,7 @@ export default function Gallery() {
syncWithRemote(false, true);
}, SYNC_INTERVAL_IN_MICROSECONDS);
if (isElectron()) {
+ void ClipService.setupOnFileUploadListener();
ElectronAPIs.registerForegroundEventListener(() => {
syncWithRemote(false, true);
});
@@ -354,8 +354,8 @@ export default function Gallery() {
clearInterval(syncInterval.current);
if (isElectron()) {
ElectronAPIs.registerForegroundEventListener(() => {});
+ ClipService.removeOnFileUploadListener();
}
- ClipService.removeOnFileUploadListener();
};
}, []);
@@ -722,8 +722,8 @@ export default function Gallery() {
await syncTrash(collections, setTrashedFiles);
await syncEntities();
await syncMapEnabled();
- if (isElectron()) {
- await syncEmbeddings();
+ await syncEmbeddings();
+ if (ClipService.isPlatformSupported()) {
void ClipService.scheduleImageEmbeddingExtraction();
}
} catch (e) {
diff --git a/apps/photos/src/services/clipService.ts b/apps/photos/src/services/clipService.ts
index 7bdd010d56..dd2dc9ee09 100644
--- a/apps/photos/src/services/clipService.ts
+++ b/apps/photos/src/services/clipService.ts
@@ -7,7 +7,6 @@ import { getAllLocalFiles, getLocalFiles } from './fileService';
import downloadManager from './downloadManager';
import { logError } from '@ente/shared/sentry';
import { addLogLine } from '@ente/shared/logging';
-import isElectron from 'is-electron';
import { Events, eventBus } from '@ente/shared/events';
import PQueue from 'p-queue';
import { EnteFile } from 'types/file';
@@ -40,6 +39,7 @@ class ClipServiceImpl {
private onFileUploadedHandler:
| ((arg: { enteFile: EnteFile; localFile: globalThis.File }) => void)
| null = null;
+ private unsupportedPlatform = false;
constructor() {
this.liveEmbeddingExtractionQueue = new PQueue({
@@ -47,9 +47,13 @@ class ClipServiceImpl {
});
}
+ isPlatformSupported = () => {
+ return !this.unsupportedPlatform;
+ };
+
setupOnFileUploadListener = async () => {
try {
- if (!isElectron()) {
+ if (this.unsupportedPlatform) {
return;
}
if (this.onFileUploadedHandler) {
@@ -148,6 +152,12 @@ class ClipServiceImpl {
private runClipEmbeddingExtraction = async (canceller: AbortController) => {
try {
+ if (this.unsupportedPlatform) {
+ addLogLine(
+ `skipping clip embedding extraction, platform unsupported`
+ );
+ return;
+ }
const user = getData(LS_KEYS.USER);
if (!user) {
return;
@@ -188,12 +198,23 @@ class ClipServiceImpl {
`successfully put clip embedding to server for file: ${file.metadata.title} fileID: ${file.id}`
);
} catch (e) {
- if (e.message !== CustomError.REQUEST_CANCELLED) {
+ if (e?.message !== CustomError.REQUEST_CANCELLED) {
logError(
e,
'failed to extract clip embedding for file'
);
}
+ if (
+ e?.message?.includes(CustomError.UNSUPPORTED_PLATFORM)
+ ) {
+ this.unsupportedPlatform = true;
+ }
+ if (
+ e?.message === CustomError.REQUEST_CANCELLED ||
+ e?.message?.includes(CustomError.UNSUPPORTED_PLATFORM)
+ ) {
+ throw e;
+ }
}
}
} catch (e) {
diff --git a/apps/photos/src/services/searchService.ts b/apps/photos/src/services/searchService.ts
index f164a24c89..0db671bfd8 100644
--- a/apps/photos/src/services/searchService.ts
+++ b/apps/photos/src/services/searchService.ts
@@ -32,7 +32,6 @@ import {
computeClipMatchScore,
getLocalClipImageEmbeddings,
} from './clipService';
-import isElectron from 'is-electron';
const DIGITS = new Set(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']);
@@ -291,7 +290,7 @@ async function getThingSuggestion(searchPhrase: string): Promise<Suggestion[]> {
}
async function getClipSuggestion(searchPhrase: string): Promise<Suggestion> {
- if (!isElectron()) {
+ if (!ClipService.isPlatformSupported()) {
return null;
}
const clipResults = await searchClip(searchPhrase);
diff --git a/packages/shared/error/index.ts b/packages/shared/error/index.ts
index 1e037b7ef9..cdeef73283 100644
--- a/packages/shared/error/index.ts
+++ b/packages/shared/error/index.ts
@@ -85,6 +85,7 @@ export const CustomError = {
CLIENT_ERROR: 'client error',
ServerError: 'server error',
FILE_NOT_FOUND: 'file not found',
+ UNSUPPORTED_PLATFORM: 'Unsupported platform',
};
export function handleUploadError(error: any): Error {