[desktop] Include app version in X-Client-Package (#2485)
This commit is contained in:
@@ -58,7 +58,6 @@ const worker = async () => {
|
||||
const createComlinkWorker = async () => {
|
||||
const electron = ensureElectron();
|
||||
const mlWorkerElectron = {
|
||||
appVersion: electron.appVersion,
|
||||
detectFaces: electron.detectFaces,
|
||||
computeFaceEmbeddings: electron.computeFaceEmbeddings,
|
||||
computeCLIPImageEmbedding: electron.computeCLIPImageEmbedding,
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
* {@link Electron} that are needed by the code running in the ML web worker.
|
||||
*/
|
||||
export interface MLWorkerElectron {
|
||||
appVersion: () => Promise<string>;
|
||||
detectFaces: (input: Float32Array) => Promise<Float32Array>;
|
||||
computeFaceEmbeddings: (input: Float32Array) => Promise<Float32Array>;
|
||||
computeCLIPImageEmbedding: (input: Float32Array) => Promise<Float32Array>;
|
||||
|
||||
@@ -69,7 +69,6 @@ interface IndexableItem {
|
||||
export class MLWorker {
|
||||
private electron: MLWorkerElectron | undefined;
|
||||
private delegate: MLWorkerDelegate | undefined;
|
||||
private userAgent: string | undefined;
|
||||
private state: "idle" | "indexing" = "idle";
|
||||
private liveQ: IndexableItem[] = [];
|
||||
private idleTimeout: ReturnType<typeof setTimeout> | undefined;
|
||||
@@ -91,8 +90,6 @@ export class MLWorker {
|
||||
async init(electron: MLWorkerElectron, delegate?: MLWorkerDelegate) {
|
||||
this.electron = electron;
|
||||
this.delegate = delegate;
|
||||
// Set the user agent that'll be set in the generated embeddings.
|
||||
this.userAgent = `${clientPackageName}/${await electron.appVersion()}`;
|
||||
// Initialize the downloadManager running in the web worker with the
|
||||
// user's token. It'll be used to download files to index if needed.
|
||||
await downloadManager.init(await ensureAuthToken());
|
||||
@@ -181,7 +178,6 @@ export class MLWorker {
|
||||
const allSuccess = await indexNextBatch(
|
||||
items,
|
||||
ensure(this.electron),
|
||||
ensure(this.userAgent),
|
||||
this.delegate,
|
||||
);
|
||||
if (allSuccess) {
|
||||
@@ -241,7 +237,6 @@ expose(MLWorker);
|
||||
const indexNextBatch = async (
|
||||
items: IndexableItem[],
|
||||
electron: MLWorkerElectron,
|
||||
userAgent: string,
|
||||
delegate: MLWorkerDelegate | undefined,
|
||||
) => {
|
||||
// Don't try to index if we wouldn't be able to upload them anyway. The
|
||||
@@ -259,7 +254,7 @@ const indexNextBatch = async (
|
||||
let allSuccess = true;
|
||||
for (const item of items) {
|
||||
try {
|
||||
await index(item, electron, userAgent);
|
||||
await index(item, electron);
|
||||
delegate?.workerDidProcessFile();
|
||||
// Possibly unnecessary, but let us drain the microtask queue.
|
||||
await wait(0);
|
||||
@@ -359,7 +354,6 @@ const syncWithLocalFilesAndGetFilesToIndex = async (
|
||||
const index = async (
|
||||
{ enteFile, uploadItem, remoteDerivedData }: IndexableItem,
|
||||
electron: MLWorkerElectron,
|
||||
userAgent: string,
|
||||
) => {
|
||||
const f = fileLogID(enteFile);
|
||||
const fileID = enteFile.id;
|
||||
@@ -453,13 +447,13 @@ const index = async (
|
||||
|
||||
const remoteFaceIndex = existingRemoteFaceIndex ?? {
|
||||
version: faceIndexingVersion,
|
||||
client: userAgent,
|
||||
client: clientPackageName,
|
||||
...faceIndex,
|
||||
};
|
||||
|
||||
const remoteCLIPIndex = existingRemoteCLIPIndex ?? {
|
||||
version: clipIndexingVersion,
|
||||
client: userAgent,
|
||||
client: clientPackageName,
|
||||
...clipIndex,
|
||||
};
|
||||
|
||||
|
||||
@@ -34,6 +34,13 @@ export const appName: AppName = process.env.appName as AppName;
|
||||
*/
|
||||
export const isDesktop = process.env.isDesktop == "1";
|
||||
|
||||
/**
|
||||
* Version of the desktop app.
|
||||
*
|
||||
* This is only defined when {@link isDesktop} is true.
|
||||
*/
|
||||
export const desktopAppVersion = process.env.desktopAppVersion;
|
||||
|
||||
/**
|
||||
* Static (English) title for the app.
|
||||
*
|
||||
@@ -59,7 +66,9 @@ export const clientPackageName = (() => {
|
||||
if (isDesktop) {
|
||||
if (appName != "photos")
|
||||
throw new Error(`Unsupported desktop appName ${appName}`);
|
||||
return "io.ente.photos.desktop";
|
||||
if (!desktopAppVersion)
|
||||
throw new Error(`desktopAppVersion is not defined`);
|
||||
return `io.ente.photos.desktop/${desktopAppVersion}`;
|
||||
}
|
||||
return {
|
||||
accounts: "io.ente.accounts.web",
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
const cp = require("child_process");
|
||||
const os = require("os");
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
|
||||
/**
|
||||
* Return the current commit ID if we're running inside a git repository.
|
||||
@@ -64,6 +65,17 @@ const appName = path.basename(process.cwd());
|
||||
*/
|
||||
const isDesktop = process.env._ENTE_IS_DESKTOP ? "1" : "";
|
||||
|
||||
/**
|
||||
* When we're running within the desktop app, also extract the version of the
|
||||
* desktop app for use in our "X-Client-Package" string.
|
||||
*
|
||||
* > The web app has continuous deployments, and doesn't have versions.
|
||||
*/
|
||||
const desktopAppVersion = isDesktop
|
||||
? JSON.parse(fs.readFileSync("../../../desktop/package.json", "utf-8"))
|
||||
.version
|
||||
: undefined;
|
||||
|
||||
/**
|
||||
* Configuration for the Next.js build
|
||||
*
|
||||
@@ -84,6 +96,7 @@ const nextConfig = {
|
||||
gitSHA,
|
||||
appName,
|
||||
isDesktop,
|
||||
desktopAppVersion,
|
||||
},
|
||||
|
||||
// Customize the webpack configuration used by Next.js.
|
||||
|
||||
Reference in New Issue
Block a user