π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
refactor(gallery):clean-up-download-progress-percentage
Aswin Asok42198474d787
diff --git a/web/apps/photos/tests/download-progress.test.ts b/web/apps/photos/tests/download-progress.test.tsindex bf36c9dda7..b38b937931 100644--- a/web/apps/photos/tests/download-progress.test.ts+++ b/web/apps/photos/tests/download-progress.test.ts@@ -12,18 +12,18 @@ describe("downloadProgressState", () => {);expect(downloaded).toEqual({phase: "decrypting",- precentage: 100,+ percentage: 100,loaded: 100,total: 100,});const tail = downloadProgressState(loading, undefined, downloaded);- expect(tail).toEqual({ phase: "decrypting", precentage: 100 });+ expect(tail).toEqual({ phase: "decrypting", percentage: 100 });expect(downloadProgressState(loading, undefined, tail)).toEqual(tail);});test("prepares HLS auto video without a download entry, then hides", () => {const preparing = downloadProgressState(loading, undefined, undefined);- expect(preparing).toEqual({ phase: "preparing", precentage: 0 });+ expect(preparing).toEqual({ phase: "preparing", percentage: 0 });expect(downloadProgressState({}, undefined, preparing)).toBeUndefined();});@@ -32,18 +32,18 @@ describe("downloadProgressState", () => {downloadProgressState({},{ loaded: 30, total: 100 },- { phase: "downloading", precentage: 30 },+ { phase: "downloading", percentage: 30 },),).toBeUndefined();expect(downloadProgressState({}, undefined, {phase: "failed",- precentage: 70,+ percentage: 70,}),).toBeUndefined();});- test("clamps ciphertext exceeding the plaintext size fallback", () => {+ test("shows decrypting when downloaded bytes exceed the reported total", () => {expect(downloadProgressState(loading,@@ -52,7 +52,7 @@ describe("downloadProgressState", () => {),).toEqual({phase: "decrypting",- precentage: 100,+ percentage: 100,loaded: 117,total: 100,});@@ -66,7 +66,7 @@ describe("downloadProgressState", () => {);expect(state).toEqual({phase: "downloading",- precentage: undefined,+ percentage: undefined,loaded: 30,});const completed = downloadProgressState(@@ -76,7 +76,7 @@ describe("downloadProgressState", () => {);expect(downloadProgressState(loading, undefined, completed)).toEqual({phase: "decrypting",- precentage: 100,+ percentage: 100,});});@@ -87,35 +87,35 @@ describe("downloadProgressState", () => {undefined,);const removed = downloadProgressState(loading, undefined, downloading);- expect(removed).toEqual({ phase: "downloading", precentage: 42 });+ expect(removed).toEqual({ phase: "downloading", percentage: 42 });expect(downloadProgressState({ fetchFailed: true }, undefined, removed),- ).toEqual({ phase: "failed", precentage: 42 });+ ).toEqual({ phase: "failed", percentage: 42 });});test("failure takes precedence and keeps the previous percentage", () => {expect(downloadProgressState({ fetchFailed: true }, undefined, {phase: "downloading",- precentage: 42,+ percentage: 42,}),- ).toEqual({ phase: "failed", precentage: 42 });+ ).toEqual({ phase: "failed", percentage: 42 });expect(downloadProgressState({ ...loading, fetchFailed: true },{ loaded: 100, total: 100 },undefined,),- ).toEqual({ phase: "failed", precentage: 0 });+ ).toEqual({ phase: "failed", percentage: 0 });});test("retry ignores the previous failed percentage", () => {expect(downloadProgressState(loading, undefined, {phase: "failed",- precentage: 42,+ percentage: 42,}),- ).toEqual({ phase: "preparing", precentage: 0 });+ ).toEqual({ phase: "preparing", percentage: 0 });});test("opens on an in-flight download without previous state", () => {@@ -127,7 +127,7 @@ describe("downloadProgressState", () => {),).toEqual({phase: "downloading",- precentage: 30,+ percentage: 30,loaded: 30,total: 100,});@@ -140,13 +140,13 @@ describe("downloadProgressState", () => {{ loaded: 0, total: 100 },undefined,),- ).toEqual({ phase: "preparing", precentage: 0 });+ ).toEqual({ phase: "preparing", percentage: 0 });expect(downloadProgressState(loading,{ loaded: 9999, total: 10000 },undefined,- )?.precentage,+ )?.percentage,).toBe(99);});});diff --git a/web/packages/gallery/components/viewer/download-progress.ts b/web/packages/gallery/components/viewer/download-progress.tsindex f2491099d4..e7c25a9820 100644--- a/web/packages/gallery/components/viewer/download-progress.ts+++ b/web/packages/gallery/components/viewer/download-progress.ts@@ -9,7 +9,7 @@ export type DownloadProgressPhase =export interface DownloadProgressState {phase: DownloadProgressPhase;- precentage: number | undefined;+ percentage: number | undefined;loaded?: number;total?: number;}@@ -20,33 +20,30 @@ export const downloadProgressState = (previous: DownloadProgressState | undefined,): DownloadProgressState | undefined => {if (itemData.fetchFailed)- return { phase: "failed", precentage: previous?.precentage ?? 0 };+ return { phase: "failed", percentage: previous?.percentage ?? 0 };if (!itemData.isContentLoading) return undefined;if (entry) {const { loaded, total } = entry;if (total !== undefined && total > 0) {if (loaded >= total)- return { phase: "decrypting", precentage: 100, loaded, total };+ return { phase: "decrypting", percentage: 100, loaded, total };if (loaded > 0)return {phase: "downloading",- precentage: Math.min(- 99,- Math.floor((loaded * 100) / total),- ),+ percentage: Math.floor((loaded * 100) / total),loaded,total,};- return { phase: "preparing", precentage: 0 };+ return { phase: "preparing", percentage: 0 };}if (total === undefined && loaded > 0)- return { phase: "downloading", precentage: undefined, loaded };+ return { phase: "downloading", percentage: undefined, loaded };} else if (previous?.phase == "downloading" ||previous?.phase == "decrypting") {- return { phase: previous.phase, precentage: previous.precentage };+ return { phase: previous.phase, percentage: previous.percentage };}- return { phase: "preparing", precentage: 0 };+ return { phase: "preparing", percentage: 0 };};diff --git a/web/packages/gallery/components/viewer/photoswipe-core.ts b/web/packages/gallery/components/viewer/photoswipe-core.tsindex 704413f123..fb775b65a5 100644--- a/web/packages/gallery/components/viewer/photoswipe-core.ts+++ b/web/packages/gallery/components/viewer/photoswipe-core.ts@@ -864,7 +864,7 @@ export class FileViewerPhotoSwipe<let progressRing: SVGCircleElement;let progressBar: HTMLElement;let fill: HTMLElement;- let precentage: HTMLElement;+ let percentageEl: HTMLElement;let status: HTMLElement;let separator: HTMLElement;let size: HTMLElement;@@ -902,10 +902,10 @@ export class FileViewerPhotoSwipe<const state = rememberDownloadProgress();const failed = state?.phase == "failed";- const precentageText =- state?.precentage === undefined+ const percentageText =+ state?.percentage === undefined? ""- : `${state.precentage}%`;+ : `${state.percentage}%`;const statusText = state? t({@@ -926,15 +926,15 @@ export class FileViewerPhotoSwipe<}): `${formattedByteSize(state.loaded, 1)} / ${formattedByteSize(state.total, 1)}`: "";- setText(precentage, precentageText);+ setText(percentageEl, percentageText);setText(status, statusText);setText(size, sizeText);setText(retry, t("retry"));size.hidden = !sizeText;separator.hidden = !(sizeText || failed);retry.hidden = !failed;- fill.style.width = `${Math.max(state?.precentage ?? 0, 1)}%`;- progressRing.style.strokeDashoffset = `${100 - (state?.precentage ?? 0)}`;+ fill.style.width = `${Math.max(state?.percentage ?? 0, 1)}%`;+ progressRing.style.strokeDashoffset = `${100 - (state?.percentage ?? 0)}`;for (const [element, prefix] of [[progressText, "pswp__ente-progress-text"],[progressValue, "pswp__ente-progress-overlay"],@@ -948,7 +948,7 @@ export class FileViewerPhotoSwipe<element.classList.toggle(`${prefix}--failed`, failed);element.classList.toggle(`${prefix}--indeterminate`,- !!state && state.precentage === undefined,+ !!state && state.percentage === undefined,);}setAttribute(@@ -964,13 +964,13 @@ export class FileViewerPhotoSwipe<setAttribute(progressValue,"aria-valuenow",- state?.precentage?.toString(),+ state?.percentage?.toString(),);setAttribute(progressValue,"aria-valuetext",[- precentageText,+ percentageText,!(compactProgress.matches && sizeText) && statusText,!compactProgress.matches && (sizeText || failed) && "Β·",sizeText,@@ -1022,7 +1022,7 @@ export class FileViewerPhotoSwipe<onInit: (element) => {progressValue = element;progressRing = element.querySelector("circle")!;- precentage = element.querySelector<HTMLElement>(+ percentageEl = element.querySelector<HTMLElement>(".pswp__ente-progress-pct",)!;element.setAttribute("role", "progressbar");