π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Account for processing in the timings
Manav Rathi42089403fd8a
diff --git a/web/apps/cast/src/pages/slideshow.tsx b/web/apps/cast/src/pages/slideshow.tsxindex 24f1bb4c57..bd3339b42b 100644--- a/web/apps/cast/src/pages/slideshow.tsx+++ b/web/apps/cast/src/pages/slideshow.tsx@@ -16,101 +16,35 @@ export default function Slideshow() {const pair = () => router.push("/");useEffect(() => {- let urlGenerator: AsyncGenerator<[string, string], void>;- try {- urlGenerator = renderableImageURLs(readCastData());- } catch (e) {- log.error("Failed to prepare generator", e);- pair();- }+ let stop = false;- advance(urlGenerator);-- const interval = window.setInterval(() => {- advance(urlGenerator);- }, 10000);-- return () => clearInterval(interval);- }, []);-- const advance = async (- urlGenerator: AsyncGenerator<[string, string], void>,- ) => {- try {- const { value: urls, done } = await urlGenerator.next();- if (done) {- log.warn("Empty collection");- pair();- return;- }-- setImageURL(urls[0]);- setNextImageURL(urls[1]);- setLoading(false);- } catch (e) {- log.error("Failed to generate image URL", e);- pair();- }- };-- /*- const showNextSlide = async () => {- try {- console.log("showNextSlide");- const currentIndex = collectionFiles.findIndex(- (file) => file.id === currentFileId,- );-- console.log(- "showNextSlide-index",- currentIndex,- collectionFiles.length,- );-- const nextIndex = (currentIndex + 1) % collectionFiles.length;- const nextNextIndex = (nextIndex + 1) % collectionFiles.length;-- console.log(- "showNextSlide-nextIndex and nextNextIndex",- nextIndex,- nextNextIndex,- );-- const nextFile = collectionFiles[nextIndex];- const nextNextFile = collectionFiles[nextNextIndex];-- let nextURL: string;+ const loop = async () => {try {- nextURL = await createRenderableURL(nextFile, castToken);+ const urlGenerator = renderableImageURLs(readCastData());+ while (!stop) {+ const { value: urls, done } = await urlGenerator.next();+ if (done) {+ log.warn("Empty collection");+ pair();+ return;+ }++ setImageURL(urls[0]);+ setNextImageURL(urls[1]);+ setLoading(false);+ }} catch (e) {- console.log("error in nextUrl", e);- return;+ log.error("Failed to prepare generator", e);+ pair();}+ };- let nextNextURL: string;- try {- nextNextURL = await createRenderableURL(- nextNextFile,- castToken,- );- } catch (e) {- console.log("error in nextNextURL", e);- return;- }+ void loop();- setLoading(false);- setCurrentFileId(nextFile.id);- // TODO: These might be the same in case the album has < 3 files- // so commenting this out for now.- // if (currentFileURL) URL.revokeObjectURL(currentFileURL);- setCurrentFileURL(nextURL);- // if (nextFileURL) URL.revokeObjectURL(nextFileURL);- setNextFileURL(nextNextURL);- } catch (e) {- console.log("error in showNextSlide", e);- }- };- */+ return () => {+ stop = true;+ };+ }, []);if (loading) return <PairedSuccessfullyOverlay />;diff --git a/web/apps/cast/src/services/cast.ts b/web/apps/cast/src/services/cast.tsindex 83e67b335d..4d01d0f2f7 100644--- a/web/apps/cast/src/services/cast.ts+++ b/web/apps/cast/src/services/cast.ts@@ -9,6 +9,7 @@ import { CustomError, parseSharingErrorCodes } from "@ente/shared/error";import HTTPService from "@ente/shared/network/HTTPService";import { getCastFileURL, getEndpoint } from "@ente/shared/network/api";import localForage from "@ente/shared/storage/localForage";+import { wait } from "@ente/shared/utils";import { detectMediaMIMEType } from "services/detect-type";import { Collection, CollectionPublicMagicMetadata } from "types/collection";import {@@ -107,6 +108,13 @@ export const renderableImageURLs = async function* (castData: CastData) {*/const urls: string[] = [""];let i = 0;+ /**+ * Time when we last yielded.+ *+ * We use this to keep an roughly periodic spacing between yields that+ * accounts for the time we spend fetching and processing the images.+ */+ let lastYieldTime = Date.now();while (true) {const collection = await getCastCollection(castToken, collectionKey);@@ -136,6 +144,11 @@ export const renderableImageURLs = async function* (castData: CastData) {ensure(urls[0]),ensure(urls[1]),];++ const elapsedTime = Date.now() - lastYieldTime;+ if (elapsedTime < 10000) await wait(10000 - elapsedTime);++ lastYieldTime = Date.now();yield urlPair;}