import { useState, useEffect, useRef, useCallback } from "react"; import commands from "../../main/commands"; import { ReactCompareSlider, ReactCompareSliderImage, } from "react-compare-slider"; import Animated from "../public/loading.svg"; import Image from "next/image"; const Home = () => { const [imagePath, SetImagePath] = useState(""); const [upscaledImagePath, setUpscaledImagePath] = useState(""); const [outputPath, SetOutputPath] = useState(""); const [scaleFactor, setScaleFactor] = useState(4); const [progress, setProgress] = useState(""); const [model, setModel] = useState("realesrgan-x4plus"); const [loaded, setLoaded] = useState(false); const [version, setVersion] = useState(""); useEffect(() => { setVersion(navigator.userAgent.match(/Upscayl\/([\d\.]+\d+)/)[1]); }, []); useEffect(() => { setLoaded(true); window.electron.on(commands.UPSCAYL_PROGRESS, (_, data) => { if (data.includes("invalid gpu")) { alert( "Error. Please make sure you have a Vulkan compatible GPU (Most modern GPUs support Vulkan). Upscayl does not work with CPU or iGPU sadly." ); SetImagePath(""); upscaledImagePath(""); } else if (data.includes("failed")) { alert( "This image is possibly corrupt or not supported by Upscayl. You could try converting the image into another format and upscaling again. Otherwise, make sure that the output path is correct and you have the proper write permissions for the directory. If not, then unfortuantely this image is not supported by Upscayl, sorry." ); SetImagePath(""); upscaledImagePath(""); } else if (data.length > 0 && data.length < 10) setProgress(data); }); window.electron.on(commands.UPSCAYL_DONE, (_, data) => { setUpscaledImagePath(data); }); }, []); const selectImageHandler = async () => { SetImagePath(""); setUpscaledImagePath(""); setProgress(""); var path = await window.electron.invoke(commands.SELECT_FILE); if (path !== "cancelled") { SetImagePath(path); var dirname = path.match(/(.*)[\/\\]/)[1] || ""; SetOutputPath(dirname); } }; const handleModelChange = (e) => { setModel(e.target.value); }; const handleDragEnter = (e) => { e.preventDefault(); console.log("drag enter"); }; const handleDragLeave = (e) => { e.preventDefault(); console.log("drag leave"); }; const handleDragOver = (e) => { e.preventDefault(); console.log("drag over"); }; const handleDrop = (e) => { e.preventDefault(); const type = e.dataTransfer.items[0].type; const filePath = e.dataTransfer.files[0].path; const extension = e.dataTransfer.files[0].name.split(".").at(-1); if ( !type.includes("image") && !["jpeg", "jpg", "png", "webp"].includes(extension.toLowerCase()) ) { alert("Please drag and drop an image"); } else { SetImagePath(filePath); var dirname = filePath.match(/(.*)[\/\\]/)[1] || ""; SetOutputPath(dirname); } }; const handlePaste = (e) => { console.log(e); e.preventDefault(); const type = e.clipboardData.items[0].type; const filePath = e.clipboardData.files[0].path; const extension = e.clipboardData.files[0].name.split(".").at(-1); if ( !type.includes("image") && !["jpeg", "jpg", "png", "webp"].includes(extension.toLowerCase()) ) { alert("Please drag and drop an image"); } else { SetImagePath(filePath); var dirname = filePath.match(/(.*)[\/\\]/)[1] || ""; SetOutputPath(dirname); } }; const outputHandler = async () => { var path = await window.electron.invoke(commands.SELECT_FOLDER); if (path !== "cancelled") { SetOutputPath(path); } else { console.log("Getting output path from input file"); } }; const upscaylHandler = async () => { if (imagePath !== "") { setUpscaledImagePath(""); setProgress("Hold on..."); await window.electron.send(commands.UPSCAYL, { scaleFactor, imagePath, outputPath, model, }); } else { alert("Please select an image to upscale"); } }; return (
{/* HEADER */}

Upscayl

AI Image Upscaler

{/* LEFT PANE */}
{/* STEP 1 */}

Step 1

{/* STEP 2 */}

Step 2

Select Upscaling Type

{/* STEP 3

Step 3

Select Scale Factor

*/} {/* STEP 4 */}

Step 3

Defaults to Image's path

{/* STEP 4 */}

Step 5

Copyright © 2022 -{" "} Upscayl

Made by{" "} TGS963 {" "} and{" "} Nayam Amarshe

{/* RIGHT PANE */}
handleDrop(e)} onDragOver={(e) => handleDragOver(e)} onDragEnter={(e) => handleDragEnter(e)} onDragLeave={(e) => handleDragLeave(e)} onPaste={(e) => handlePaste(e)} > {progress.length > 0 && upscaledImagePath.length === 0 && (

{progress}

)} {imagePath.length === 0 ? ( <>

Select an Image to Upscale

Upscale v{version}

) : upscaledImagePath.length === 0 ? ( ) : ( } itemTwo={ } className="h-screen" /> )}
); }; export default Home;