π Upscayl - #1 Free and Open Source AI Image Upscaler for Linux, MacOS and Windows.
TypeScript aielectronesrgangigapixelgigapixel-imagesimageimage-upscalingtopazupscaleupscalerimageupscayl
Merge upstream/main into feat/ctrl-v
abhishek-gaonkara6157bfc80c7
diff --cc renderer/components/main-content/index.tsxindex 42c4720,0b89aa5..216a689--- a/renderer/components/main-content/index.tsx+++ b/renderer/components/main-content/index.tsx@@@ -165,68 -165,37 +165,68 @@@ const MainContent = (const handlePaste = (e: React.ClipboardEvent<HTMLDivElement>) => {resetImagePaths();e.preventDefault();- const items = e.clipboardData.items;- const files = e.clipboardData.files;- if (items.length === 0 || files.length === 0) {- toast({- title: t("ERRORS.INVALID_IMAGE_ERROR.TITLE"),- description: t("ERRORS.INVALID_IMAGE_ERROR.ADDITIONAL_DESCRIPTION"),- });- return;- }- const type = items[0].type;- const filePath = files[0].path;- const extension = files[0].name- .split(".")- .at(-1)- .toLowerCase() as ImageFormat;- logit("π Pasted file: ", JSON.stringify({ type, filePath, extension }));- if (!type.includes("image") && !VALID_IMAGE_FORMATS.includes(extension)) {+ if (e.clipboardData.files.length) {+ const fileObject = e.clipboardData.files[0];+ const currentDate = new Date(Date.now());+ const currentTime = `${currentDate.getHours()}-${currentDate.getMinutes()}-${currentDate.getSeconds()}`;+ const fileName = `${currentTime}-${fileObject.name}`;+ const file = {+ name: fileName,- extension: fileName.split(".").pop(),++ extension: fileName.split(".").pop() as ImageFormat,+ size: fileObject.size,+ type: fileObject.type.split("/")[0],+ encodedBuffer: "",+ };++ logit(+ "π Pasted file: ",+ JSON.stringify({+ type: file.type,+ name: file.name,+ extension: file.extension,+ }),+ );++ if (+ file.type === "image" &&+ VALID_IMAGE_FORMATS.includes(file.extension)+ ) {+ const reader = new FileReader();+ reader.onload = async (event) => {+ const result = event.target?.result;+ if (typeof result === "string") {+ file.encodedBuffer = Buffer.from(result, "utf-8").toString(+ "base64",+ );+ } else if (result instanceof ArrayBuffer) {+ file.encodedBuffer = Buffer.from(new Uint8Array(result)).toString(+ "base64",+ );+ } else {+ logit("π« Invalid file pasted");+ toast({+ title: t("ERRORS.INVALID_IMAGE_ERROR.TITLE"),+ description: t(+ "ERRORS.INVALID_IMAGE_ERROR.CLIPBOARD_DESCRIPTION",+ ),+ });+ }+ window.electron.send(ELECTRON_COMMANDS.PASTE_IMAGE, file);+ };+ reader.readAsArrayBuffer(fileObject);+ } else {+ logit("π« Invalid file pasted");+ toast({+ title: t("ERRORS.INVALID_IMAGE_ERROR.TITLE"),+ description: t("ERRORS.INVALID_IMAGE_ERROR.CLIPBOARD_DESCRIPTION"),+ });+ }+ } else {+ logit("π« Invalid file pasted");toast({title: t("ERRORS.INVALID_IMAGE_ERROR.TITLE"),- description: t("ERRORS.INVALID_IMAGE_ERROR.ADDITIONAL_DESCRIPTION"),+ description: t("ERRORS.INVALID_IMAGE_ERROR.CLIPBOARD_DESCRIPTION"),});- } else {- setImagePath(filePath);- const dirname = getDirectoryFromPath(filePath);- logit("π Setting output path: ", dirname);- if (!FEATURE_FLAGS.APP_STORE_BUILD) {- if (!rememberOutputFolder) {- setOutputPath(dirname);- }- }- validateImagePath(filePath);}};