π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Different tack
Manav Rathi21f87b7cbad7
diff --git a/web/packages/gallery/components/viewer/FileViewer.tsx b/web/packages/gallery/components/viewer/FileViewer.tsxindex ddf29541a6..848c2fccbb 100644--- a/web/packages/gallery/components/viewer/FileViewer.tsx+++ b/web/packages/gallery/components/viewer/FileViewer.tsx@@ -50,11 +50,7 @@ import React, {useRef,useState,} from "react";-import {- fileInfoExifForFile,- originalImageBlobForFileID,- updateItemDataAlt,-} from "./data-source";+import { fileInfoExifForFile, updateItemDataAlt } from "./data-source";import {FileViewerPhotoSwipe,moreButtonID,@@ -100,17 +96,15 @@ export interface FileViewerFileAnnotation {* `true` if the delete action should be shown for this file.*/showDelete: boolean;+ /**+ * `true` if the copy image action should be shown for this file.+ */+ showCopyImage: boolean;/*** `true` if this is an image which can be edited, _and_ editing is* possible, and the edit action should therefore be shown for this file.*/showEditImage: boolean;- /**- * If there is a image associated with the file, then this will be that- * image's raw (original) data as a {@link Blob}, and the copy image action- * will be show for this file.- */- originalImageBlob?: Blob;}/**@@ -298,6 +292,13 @@ const FileViewer: React.FC<FileViewerProps> = ({FileInfoExif | undefined>(undefined);+ // With semantics similar to `activeAnnotatedFile`, this is the imageURL+ // associated with the `activeAnnotatedFile`, if any. However, unlike+ // `activeAnnotatedFile`, this is only set when the more menu is activated.+ const [activeImageURL, setActiveImageURL] = useState<string | undefined>(+ undefined,+ );+const [openFileInfo, setOpenFileInfo] = useState(false);const [moreMenuAnchorEl, setMoreMenuAnchorEl] =useState<HTMLElement | null>(null);@@ -381,9 +382,11 @@ const FileViewer: React.FC<FileViewerProps> = ({const handleMore = useCallback((annotatedFile: FileViewerAnnotatedFile,+ imageURL: string | undefined,buttonElement: HTMLElement,) => {setActiveAnnotatedFile(annotatedFile);+ setActiveImageURL(imageURL);setMoreMenuAnchorEl(buttonElement);},[],@@ -433,8 +436,14 @@ const FileViewer: React.FC<FileViewerProps> = ({// Not memoized since it uses the frequently changing `activeAnnotatedFile`.const handleCopyImage = () => {console.log("TODO copy", activeAnnotatedFile!);- const blob = activeAnnotatedFile!.annotation.originalImageBlob;- const newBlob = new Blob([blob], { type: "image/png" });+ // const blob = activeAnnotatedFile!.annotation.originalImageBlob;+ const newBlob = new Promise((resolve) => {+ void fetch(activeImageURL)+ .then((res) => res.blob())+ .then((blob) =>+ resolve(new Blob([blob], { type: "image/png" })),+ );+ });console.log("image/png");void window.navigator.clipboard.write([@@ -493,8 +502,15 @@ const FileViewer: React.FC<FileViewerProps> = ({}})();- const originalImageBlob = originalImageBlobForFileID(fileID);- const showCopyImage = !!originalImageBlob;+ const showCopyImage = (() => {+ switch (file.metadata.fileType) {+ case FileType.image:+ case FileType.livePhoto:+ return true;+ default:+ return false;+ }+ })();const showMore =showDownload == "menu" ||@@ -509,8 +525,8 @@ const FileViewer: React.FC<FileViewerProps> = ({showDownload,showMore,showDelete,+ showCopyImage,showEditImage,- originalImageBlob,};},[@@ -689,15 +705,18 @@ const FileViewer: React.FC<FileViewerProps> = ({<DeleteIcon /></MoreMenuItem>)}- {activeAnnotatedFile?.annotation.originalImageBlob && (- <MoreMenuItem onClick={handleCopyImage}>- <MoreMenuItemTitle>- {/*TODO */ pt("Copy image")}- </MoreMenuItemTitle>- {/* Tweak icon size to visually fit better with neighbours */}- <ContentCopyIcon sx={{ "&&": { fontSize: "18px" } }} />- </MoreMenuItem>- )}+ {activeAnnotatedFile?.annotation.showCopyImage &&+ activeImageURL && (+ <MoreMenuItem onClick={handleCopyImage}>+ <MoreMenuItemTitle>+ {/*TODO */ pt("Copy image")}+ </MoreMenuItemTitle>+ {/* Tweak icon size to visually fit better with neighbours */}+ <ContentCopyIcon+ sx={{ "&&": { fontSize: "18px" } }}+ />+ </MoreMenuItem>+ )}{activeAnnotatedFile?.annotation.showEditImage && (<MoreMenuItem onClick={handleEditImage}><MoreMenuItemTitle>diff --git a/web/packages/gallery/components/viewer/data-source.ts b/web/packages/gallery/components/viewer/data-source.tsindex 633615faa8..1aa115535d 100644--- a/web/packages/gallery/components/viewer/data-source.ts+++ b/web/packages/gallery/components/viewer/data-source.ts@@ -301,13 +301,6 @@ export const forgetFailedItemDataForFileID = (fileID: number) => {}};-/**- * Return the cached {@link originalImageBlob}, if any, from the- * {@link ItemData} for the file with the given {@link fileID}.- */-export const originalImageBlobForFileID = (fileID: number) =>- _state.itemDataByFileID.get(fileID)?.originalImageBlob;-/*** Update the alt attribute of the {@link ItemData}, if any, associated with the* given {@link EnteFile}.diff --git a/web/packages/gallery/components/viewer/photoswipe.ts b/web/packages/gallery/components/viewer/photoswipe.tsindex 082ac919d5..9068b4dada 100644--- a/web/packages/gallery/components/viewer/photoswipe.ts+++ b/web/packages/gallery/components/viewer/photoswipe.ts@@ -119,11 +119,19 @@ type FileViewerPhotoSwipeOptions = Pick</*** Called when the user activates the more action on a file.*- * In addition to the file, callback is also passed a reference to the HTML- * DOM more button element.+ * @param annotatedFile The current (annotated) file.+ *+ * @param imageURL If the current file has an associated non-thumbnail image+ * that is being shown in the viewer, then this is set to the (object) URL+ * of the image being shown. Specifically, this is the same as the+ * {@link imageURL} attribute of the {@link ItemData} associated with the+ * current file.+ *+ * @param buttonElement The more button DOM element.*/onMore: (annotatedFile: FileViewerAnnotatedFile,+ imageURL: string | undefined,buttonElement: HTMLElement,) => void;};@@ -598,7 +606,11 @@ export class FileViewerPhotoSwipe {// See also: `resetMoreMenuButtonOnMenuClose`.buttonElement.setAttribute("aria-controls", moreMenuID);buttonElement.setAttribute("aria-expanded", true);- onMore(currentAnnotatedFile(), buttonElement);+ onMore(+ currentAnnotatedFile(),+ pswp.currSlide.content.data.imageURL,+ buttonElement,+ );},});}