1
0
mirror of https://github.com/upscayl/upscayl.git synced 2024-11-14 10:47:56 +01:00
upscayl/renderer/pages/index.tsx

676 lines
21 KiB
TypeScript
Raw Normal View History

2023-04-08 08:53:32 +02:00
import { useState, useEffect, useCallback } from "react";
2022-11-11 21:39:28 +01:00
import commands from "../../electron/commands";
import { ReactCompareSlider } from "react-compare-slider";
2022-11-11 21:39:28 +01:00
import Header from "../components/Header";
import Footer from "../components/Footer";
import ProgressBar from "../components/ProgressBar";
import RightPaneInfo from "../components/RightPaneInfo";
2022-11-23 19:24:30 +01:00
import ImageOptions from "../components/ImageOptions";
import LeftPaneImageSteps from "../components/LeftPaneImageSteps";
2023-03-18 18:08:50 +01:00
import Tabs from "../components/Tabs";
import SettingsTab from "../components/SettingsTab";
2023-04-08 08:53:32 +02:00
import { useAtom } from "jotai";
import { logAtom } from "../atoms/logAtom";
2023-04-09 07:48:53 +02:00
import { modelsListAtom } from "../atoms/modelsListAtom";
import { customModelsPathAtom } from "../atoms/userSettingsAtom";
2023-03-31 12:33:48 +02:00
2022-11-11 21:39:28 +01:00
const Home = () => {
2022-12-16 17:20:46 +01:00
// STATES
2022-11-11 21:39:28 +01:00
const [imagePath, SetImagePath] = useState("");
const [upscaledImagePath, setUpscaledImagePath] = useState("");
2022-11-23 19:24:30 +01:00
const [outputPath, setOutputPath] = useState("");
2022-11-11 21:39:28 +01:00
const [scaleFactor, setScaleFactor] = useState(4);
const [progress, setProgress] = useState("");
2022-12-24 08:17:54 +01:00
const [model, setModel] = useState("realesrgan-x4plus");
2022-11-11 21:39:28 +01:00
const [loaded, setLoaded] = useState(false);
const [version, setVersion] = useState("");
const [batchMode, setBatchMode] = useState(false);
const [batchFolderPath, setBatchFolderPath] = useState("");
const [upscaledBatchFolderPath, setUpscaledBatchFolderPath] = useState("");
const [doubleUpscayl, setDoubleUpscayl] = useState(false);
2022-11-15 15:53:56 +01:00
const [isVideo, setIsVideo] = useState(false);
2022-11-23 19:24:30 +01:00
const [videoPath, setVideoPath] = useState("");
const [upscaledVideoPath, setUpscaledVideoPath] = useState("");
2022-12-02 15:21:42 +01:00
const [doubleUpscaylCounter, setDoubleUpscaylCounter] = useState(0);
2022-12-16 17:20:46 +01:00
const [gpuId, setGpuId] = useState("");
const [saveImageAs, setSaveImageAs] = useState("png");
2022-12-27 12:33:39 +01:00
const [zoomAmount, setZoomAmount] = useState("100%");
2022-12-21 11:32:45 +01:00
const [backgroundPosition, setBackgroundPosition] = useState("0% 0%");
2022-12-24 08:17:54 +01:00
const [dimensions, setDimensions] = useState({
width: null,
height: null,
});
2023-03-18 18:08:50 +01:00
const [selectedTab, setSelectedTab] = useState(0);
2023-04-08 08:53:32 +02:00
const [logData, setLogData] = useAtom(logAtom);
2023-04-09 07:48:53 +02:00
const [customModelsPath, setCustomModelsPath] = useAtom(customModelsPathAtom);
const [modelOptions, setModelOptions] = useAtom(modelsListAtom);
2023-03-31 12:33:48 +02:00
2023-04-08 08:53:32 +02:00
// (function () {
// let info = console.info;
2023-03-31 12:33:48 +02:00
2023-04-08 08:53:32 +02:00
// console.log = function () {
// var args = Array.prototype.slice.call(arguments);
// info.apply(this, args);
// };
// })();
const addToLog = (data: string) => {
console.log("🚀 => file: index.tsx:52 => data:", data);
setLogData((prevLogData) => [...prevLogData, data]);
};
2022-12-21 11:32:45 +01:00
2022-12-16 17:20:46 +01:00
// EFFECTS
2022-11-11 21:39:28 +01:00
useEffect(() => {
setLoaded(true);
setVersion(navigator?.userAgent?.match(/Upscayl\/([\d\.]+\d+)/)[1]);
2023-04-08 08:53:32 +02:00
const handleErrors = (data: string) => {
2022-11-11 21:39:28 +01:00
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."
);
resetImagePaths();
} else if (data.includes("failed")) {
if (batchMode) return;
alert(
data.includes("encode")
? "ENCODING ERROR => "
: "DECODING ERROR => " +
"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."
);
resetImagePaths();
} else if (data.includes("uncaughtException")) {
alert(
"Upscayl encountered an error. Possibly, the upscayl binary failed to execute the commands properly. Try launching Upscayl using commandline through Terminal and see if you get any information. You can post an issue on Upscayl's GitHub repository for more help."
);
resetImagePaths();
}
};
2022-12-16 17:20:46 +01:00
// UPSCAYL PROGRESS
2023-04-08 08:53:32 +02:00
window.electron.on(commands.UPSCAYL_PROGRESS, (_, data: string) => {
2022-11-11 21:39:28 +01:00
if (data.length > 0 && data.length < 10) {
setProgress(data);
}
handleErrors(data);
2023-04-08 08:53:32 +02:00
addToLog(data);
2022-11-11 21:39:28 +01:00
});
2022-12-16 17:20:46 +01:00
// FOLDER UPSCAYL PROGRESS
2023-04-08 08:53:32 +02:00
window.electron.on(commands.FOLDER_UPSCAYL_PROGRESS, (_, data: string) => {
2022-11-11 21:39:28 +01:00
if (data.length > 0 && data.length < 10) {
setProgress(data);
}
handleErrors(data);
2023-04-08 08:53:32 +02:00
addToLog(data);
2022-11-11 21:39:28 +01:00
});
2022-12-16 17:20:46 +01:00
// DOUBLE UPSCAYL PROGRESS
2023-04-08 08:53:32 +02:00
window.electron.on(commands.DOUBLE_UPSCAYL_PROGRESS, (_, data: string) => {
2022-11-11 21:39:28 +01:00
if (data.length > 0 && data.length < 10) {
2022-12-02 15:21:42 +01:00
if (data === "0.00%") {
setDoubleUpscaylCounter(doubleUpscaylCounter + 1);
}
2022-11-11 21:39:28 +01:00
setProgress(data);
}
handleErrors(data);
2023-04-08 08:53:32 +02:00
addToLog(data);
2022-11-11 21:39:28 +01:00
});
2022-12-16 17:20:46 +01:00
// VIDEO UPSCAYL PROGRESS
2023-04-08 08:53:32 +02:00
window.electron.on(commands.UPSCAYL_VIDEO_PROGRESS, (_, data: string) => {
2022-11-25 07:54:30 +01:00
if (data.length > 0 && data.length < 10) {
setProgress(data);
}
handleErrors(data);
2023-04-08 08:53:32 +02:00
addToLog(data);
2022-11-25 07:54:30 +01:00
});
2022-11-11 21:39:28 +01:00
2022-12-16 17:20:46 +01:00
// UPSCAYL DONE
2023-04-08 08:53:32 +02:00
window.electron.on(commands.UPSCAYL_DONE, (_, data: string) => {
2022-11-11 21:39:28 +01:00
setProgress("");
setUpscaledImagePath(data);
2023-04-08 08:53:32 +02:00
addToLog(data);
2022-11-11 21:39:28 +01:00
});
2022-12-16 17:20:46 +01:00
// FOLDER UPSCAYL DONE
2023-04-08 08:53:32 +02:00
window.electron.on(commands.FOLDER_UPSCAYL_DONE, (_, data: string) => {
2022-11-11 21:39:28 +01:00
setProgress("");
setUpscaledBatchFolderPath(data);
2023-04-08 08:53:32 +02:00
addToLog(data);
2022-11-11 21:39:28 +01:00
});
2022-12-16 17:20:46 +01:00
// DOUBLE UPSCAYL DONE
2023-04-08 08:53:32 +02:00
window.electron.on(commands.DOUBLE_UPSCAYL_DONE, (_, data: string) => {
2022-12-02 15:21:42 +01:00
setProgress("");
setDoubleUpscaylCounter(0);
2022-11-11 21:39:28 +01:00
setUpscaledImagePath(data);
2023-04-08 08:53:32 +02:00
addToLog(data);
2022-11-11 21:39:28 +01:00
});
2022-12-16 17:20:46 +01:00
// VIDEO UPSCAYL DONE
2023-04-08 08:53:32 +02:00
window.electron.on(commands.UPSCAYL_VIDEO_DONE, (_, data: string) => {
2022-12-02 15:21:42 +01:00
setProgress("");
2022-11-25 07:54:30 +01:00
setUpscaledVideoPath(data);
2023-04-08 08:53:32 +02:00
addToLog(data);
2022-11-25 07:54:30 +01:00
});
2023-04-09 07:48:53 +02:00
// CUSTOM FOLDER LISTENER
window.electron.on(
commands.CUSTOM_MODEL_FILES_LIST,
(_, modelsList: string[]) => {
console.log("🚀 => file: index.tsx:161 => modelsList:", modelsList);
modelsList.forEach((model: string) => {
setModelOptions((prev) => [...prev, { label: model, value: model }]);
});
}
);
}, []);
useEffect(() => {
const customModelsPath = JSON.parse(
localStorage.getItem("customModelsPath")
);
if (customModelsPath !== null) {
window.electron.send(commands.GET_MODELS_LIST, customModelsPath);
}
2022-11-11 21:39:28 +01:00
}, []);
useEffect(() => {
setProgress("");
}, [batchMode]);
useEffect(() => {
2022-11-25 08:30:03 +01:00
if (imagePath.length > 0 && !isVideo) {
2022-11-11 21:39:28 +01:00
const filePath = imagePath;
console.log(
"🚀 => file: index.jsx => line 109 => useEffect => filePath",
filePath
);
const extension = imagePath.toLocaleLowerCase().split(".").pop();
console.log(
"🚀 => file: index.jsx => line 111 => useEffect => extension",
extension
);
if (!allowedFileTypes.includes(extension.toLowerCase())) {
alert("Please select an image");
resetImagePaths();
}
2022-11-25 08:30:03 +01:00
} else if (videoPath.length > 0 && isVideo) {
2022-11-25 07:54:30 +01:00
const filePath = videoPath;
2022-11-25 08:30:03 +01:00
console.log("🚀 => file: index.tsx => line 146 => filePath", filePath);
2022-11-25 07:54:30 +01:00
const extension = videoPath.toLocaleLowerCase().split(".").pop();
2022-11-25 08:30:03 +01:00
console.log("🚀 => file: index.tsx => line 150 => extension", extension);
2022-11-25 07:54:30 +01:00
if (!allowedVideoFileTypes.includes(extension.toLowerCase())) {
alert("Please select an MP4, WebM or MKV video");
resetImagePaths();
}
2022-11-25 08:30:03 +01:00
} else {
resetImagePaths();
2022-11-11 21:39:28 +01:00
}
2022-11-25 07:54:30 +01:00
}, [imagePath, videoPath]);
2022-11-11 21:39:28 +01:00
2022-12-16 17:20:46 +01:00
const resetImagePaths = () => {
2022-12-24 08:17:54 +01:00
setDimensions({
width: null,
height: null,
});
2022-12-16 17:20:46 +01:00
setProgress("");
SetImagePath("");
setUpscaledImagePath("");
setBatchFolderPath("");
setUpscaledBatchFolderPath("");
setVideoPath("");
setUpscaledVideoPath("");
};
// HANDLERS
2023-04-08 08:53:32 +02:00
const handleMouseMove = useCallback((e: any) => {
2022-12-21 11:32:45 +01:00
const { left, top, width, height } = e.target.getBoundingClientRect();
const x = ((e.pageX - left) / width) * 100;
const y = ((e.pageY - top) / height) * 100;
setBackgroundPosition(`${x}% ${y}%`);
2023-04-08 08:53:32 +02:00
}, []);
2022-12-21 11:32:45 +01:00
2023-04-08 08:53:32 +02:00
// const selectVideoHandler = async () => {
// resetImagePaths();
2022-11-23 19:24:30 +01:00
2023-04-08 08:53:32 +02:00
// var path = await window.electron.invoke(commands.SELECT_FILE);
2022-11-23 19:24:30 +01:00
2023-04-08 08:53:32 +02:00
// if (path !== "cancelled") {
// setVideoPath(path);
// var dirname = path.match(/(.*)[\/\\]/)[1] || "";
// setOutputPath(dirname);
// }
// };
2022-11-23 19:24:30 +01:00
2022-11-11 21:39:28 +01:00
const selectImageHandler = async () => {
resetImagePaths();
var path = await window.electron.invoke(commands.SELECT_FILE);
2023-04-09 07:16:15 +02:00
if (path !== null) {
2022-11-11 21:39:28 +01:00
SetImagePath(path);
var dirname = path.match(/(.*)[\/\\]/)[1] || "";
2022-11-23 19:24:30 +01:00
setOutputPath(dirname);
2022-11-11 21:39:28 +01:00
}
};
const selectFolderHandler = async () => {
resetImagePaths();
var path = await window.electron.invoke(commands.SELECT_FOLDER);
2023-04-09 07:16:15 +02:00
if (path !== null) {
2022-11-11 21:39:28 +01:00
setBatchFolderPath(path);
2022-11-23 19:24:30 +01:00
setOutputPath(path + "_upscayled");
2022-11-11 21:39:28 +01:00
}
};
2023-04-08 08:53:32 +02:00
// ? What's this for
// const imageLoadHandler = ({ target: img }) => {
// const image = img;
// console.log("imageLoadHandler", {
// image,
// });
// };
2022-12-24 08:17:54 +01:00
2023-04-08 08:53:32 +02:00
const handleModelChange = (e: any) => {
2022-11-11 21:39:28 +01:00
setModel(e.value);
2022-12-24 09:45:15 +01:00
localStorage.setItem(
"model",
JSON.stringify({ label: e.label, value: e.value })
);
2022-11-11 21:39:28 +01:00
};
2022-12-16 17:20:46 +01:00
// DRAG AND DROP HANDLERS
2022-11-11 21:39:28 +01:00
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");
};
2022-12-16 17:20:46 +01:00
2022-11-11 21:39:28 +01:00
const openFolderHandler = (e) => {
window.electron.send(commands.OPEN_FOLDER, upscaledBatchFolderPath);
};
const handleDrop = (e) => {
e.preventDefault();
resetImagePaths();
const type = e.dataTransfer.items[0].type;
console.log("🚀 => handleDrop => type", type);
const filePath = e.dataTransfer.files[0].path;
console.log("🚀 => handleDrop => filePath", filePath);
const extension = e.dataTransfer.files[0].name.split(".").at(-1);
console.log("🚀 => handleDrop => extension", extension);
if (
2022-11-25 07:54:30 +01:00
(!type.includes("image") && !type.includes("video")) ||
(!allowedFileTypes.includes(extension.toLowerCase()) &&
!allowedVideoFileTypes.includes(extension.toLowerCase()))
2022-11-11 21:39:28 +01:00
) {
alert("Please drag and drop an image");
} else {
2022-11-25 07:54:30 +01:00
if (isVideo) {
setVideoPath(filePath);
} else {
SetImagePath(filePath);
}
2022-11-11 21:39:28 +01:00
var dirname = filePath.match(/(.*)[\/\\]/)[1] || "";
console.log("🚀 => handleDrop => dirname", dirname);
2022-11-23 19:24:30 +01:00
setOutputPath(dirname);
2022-11-11 21:39:28 +01:00
}
};
const handlePaste = (e) => {
console.log(e);
resetImagePaths();
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") &&
!allowedFileTypes.includes(extension.toLowerCase())
) {
alert("Please drag and drop an image");
} else {
SetImagePath(filePath);
var dirname = filePath.match(/(.*)[\/\\]/)[1] || "";
2022-11-23 19:24:30 +01:00
setOutputPath(dirname);
2022-11-11 21:39:28 +01:00
}
};
const outputHandler = async () => {
var path = await window.electron.invoke(commands.SELECT_FOLDER);
2023-04-09 07:16:15 +02:00
if (path !== null) {
2022-11-23 19:24:30 +01:00
setOutputPath(path);
2022-11-11 21:39:28 +01:00
} else {
console.log("Getting output path from input file");
}
};
const upscaylHandler = async () => {
2022-11-25 07:54:30 +01:00
if (isVideo) {
setUpscaledVideoPath("");
} else {
setUpscaledImagePath("");
}
2023-03-12 08:41:43 +01:00
2022-11-26 10:42:16 +01:00
if (!isVideo && (imagePath !== "" || batchFolderPath !== "")) {
2022-11-11 21:39:28 +01:00
setProgress("Hold on...");
if (doubleUpscayl) {
await window.electron.send(commands.DOUBLE_UPSCAYL, {
imagePath,
outputPath,
model,
2022-12-16 17:20:46 +01:00
gpuId: gpuId.length === 0 ? null : gpuId,
saveImageAs,
2022-11-11 21:39:28 +01:00
});
} else if (batchMode) {
setDoubleUpscayl(false);
await window.electron.send(commands.FOLDER_UPSCAYL, {
scaleFactor,
batchFolderPath,
outputPath,
model,
2022-12-16 17:20:46 +01:00
gpuId: gpuId.length === 0 ? null : gpuId,
saveImageAs,
2022-11-11 21:39:28 +01:00
});
} else {
await window.electron.send(commands.UPSCAYL, {
scaleFactor,
imagePath,
outputPath,
model,
2022-12-16 17:20:46 +01:00
gpuId: gpuId.length === 0 ? null : gpuId,
saveImageAs,
2022-11-11 21:39:28 +01:00
});
}
2022-11-26 10:42:16 +01:00
} else if (isVideo && videoPath !== "") {
2022-11-25 07:54:30 +01:00
await window.electron.send(commands.UPSCAYL_VIDEO, {
scaleFactor,
2022-11-26 10:42:16 +01:00
videoPath,
2022-11-25 07:54:30 +01:00
outputPath,
model,
2022-12-16 17:20:46 +01:00
gpuId: gpuId.length === 0 ? null : gpuId,
saveImageAs,
2022-11-25 07:54:30 +01:00
});
2022-11-11 21:39:28 +01:00
} else {
2022-11-26 10:42:16 +01:00
alert(`Please select ${isVideo ? "a video" : "an image"} to upscale`);
2022-11-11 21:39:28 +01:00
}
};
2022-12-16 17:20:46 +01:00
const allowedFileTypes = ["png", "jpg", "jpeg", "webp"];
const allowedVideoFileTypes = ["webm", "mp4", "mkv"];
2022-11-11 21:39:28 +01:00
return (
2022-11-11 22:32:24 +01:00
<div className="flex h-screen w-screen flex-row overflow-hidden bg-base-300">
2022-11-15 15:42:20 +01:00
<div className="flex h-screen w-128 flex-col rounded-r-3xl bg-base-100">
2022-11-11 21:39:28 +01:00
{/* HEADER */}
2023-03-12 08:59:07 +01:00
<Header version={version} />
2023-03-18 18:08:50 +01:00
<Tabs selectedTab={selectedTab} setSelectedTab={setSelectedTab} />
2022-12-08 04:25:26 +01:00
{/* <div className="flex items-center justify-center gap-2 pb-4 font-medium">
2022-11-23 19:24:30 +01:00
<p>Image</p>
<input
type="radio"
name="radio-1"
className="radio"
checked={!isVideo}
2022-11-25 08:30:03 +01:00
onChange={() => {
setIsVideo(false);
console.log("isImage");
}}
2022-11-23 19:24:30 +01:00
/>
<input
type="radio"
name="radio-1"
className="radio"
checked={isVideo}
2022-11-25 08:30:03 +01:00
onChange={() => {
setIsVideo(true);
console.log("isVideo");
}}
2022-11-23 19:24:30 +01:00
/>
<p>Video</p>
2022-12-08 04:25:26 +01:00
</div> */}
2022-11-11 21:39:28 +01:00
{/* LEFT PANE */}
2023-03-18 18:08:50 +01:00
{/* {isVideo ? (
2022-11-23 19:24:30 +01:00
<LeftPaneVideoSteps
progress={progress}
2022-11-25 08:30:03 +01:00
selectVideoHandler={selectVideoHandler}
2022-11-23 19:24:30 +01:00
handleModelChange={handleModelChange}
handleDrop={handleDrop}
outputHandler={outputHandler}
upscaylHandler={upscaylHandler}
outputPath={outputPath}
2022-11-25 08:30:03 +01:00
videoPath={videoPath}
2022-11-23 19:24:30 +01:00
model={model}
isVideo={isVideo}
setIsVideo={setIsVideo}
/>
2023-03-18 18:08:50 +01:00
) : ( */}
{selectedTab === 0 && (
2022-11-23 19:24:30 +01:00
<LeftPaneImageSteps
progress={progress}
selectImageHandler={selectImageHandler}
selectFolderHandler={selectFolderHandler}
handleModelChange={handleModelChange}
handleDrop={handleDrop}
outputHandler={outputHandler}
upscaylHandler={upscaylHandler}
batchMode={batchMode}
setBatchMode={setBatchMode}
imagePath={imagePath}
outputPath={outputPath}
doubleUpscayl={doubleUpscayl}
setDoubleUpscayl={setDoubleUpscayl}
model={model}
2023-03-12 08:41:43 +01:00
setModel={setModel}
2022-11-23 19:24:30 +01:00
isVideo={isVideo}
setIsVideo={setIsVideo}
2022-12-16 17:20:46 +01:00
gpuId={gpuId}
setGpuId={setGpuId}
saveImageAs={saveImageAs}
setSaveImageAs={setSaveImageAs}
2022-12-24 08:17:54 +01:00
dimensions={dimensions}
2022-11-23 19:24:30 +01:00
/>
)}
2023-03-18 18:08:50 +01:00
{selectedTab === 1 && (
<SettingsTab
batchMode={batchMode}
setBatchMode={setBatchMode}
imagePath={imagePath}
setModel={setModel}
gpuId={gpuId}
setGpuId={setGpuId}
saveImageAs={saveImageAs}
setSaveImageAs={setSaveImageAs}
2023-04-08 08:53:32 +02:00
logData={logData}
2023-03-18 18:08:50 +01:00
/>
)}
{/* )} */}
2022-11-11 21:39:28 +01:00
<Footer />
</div>
{/* RIGHT PANE */}
<div
className="relative flex h-screen w-full flex-col items-center justify-center"
onDrop={(e) => handleDrop(e)}
onDragOver={(e) => handleDragOver(e)}
onDragEnter={(e) => handleDragEnter(e)}
onDragLeave={(e) => handleDragLeave(e)}
2022-11-23 19:24:30 +01:00
onPaste={(e) => handlePaste(e)}>
2022-11-11 21:39:28 +01:00
{progress.length > 0 &&
upscaledImagePath.length === 0 &&
2022-11-25 08:30:03 +01:00
upscaledBatchFolderPath.length === 0 &&
upscaledVideoPath.length === 0 ? (
2022-12-02 15:21:42 +01:00
<ProgressBar
progress={progress}
doubleUpscaylCounter={doubleUpscaylCounter}
/>
2022-11-11 21:39:28 +01:00
) : null}
2023-03-12 09:36:36 +01:00
2022-11-25 08:30:03 +01:00
{/* DEFAULT PANE INFO */}
{((!isVideo &&
!batchMode &&
2022-11-11 21:39:28 +01:00
imagePath.length === 0 &&
upscaledImagePath.length === 0) ||
2022-11-25 08:30:03 +01:00
(!isVideo &&
batchMode &&
2022-11-11 21:39:28 +01:00
batchFolderPath.length === 0 &&
2022-11-25 08:30:03 +01:00
upscaledBatchFolderPath.length === 0) ||
(isVideo &&
videoPath.length === 0 &&
upscaledVideoPath.length === 0)) && (
<RightPaneInfo
version={version}
batchMode={batchMode}
isVideo={isVideo}
/>
2022-11-11 21:39:28 +01:00
)}
2022-11-25 08:30:03 +01:00
{/* SHOW SELECTED IMAGE */}
2022-11-11 21:39:28 +01:00
{!batchMode &&
2022-11-25 08:30:03 +01:00
!isVideo &&
2022-11-11 21:39:28 +01:00
upscaledImagePath.length === 0 &&
imagePath.length > 0 && (
2022-12-24 08:40:45 +01:00
<>
<ImageOptions
zoomAmount={zoomAmount}
setZoomAmount={setZoomAmount}
resetImagePaths={resetImagePaths}
hideZoomOptions={true}
/>
<img
src={
"file://" +
`${upscaledImagePath ? upscaledImagePath : imagePath}`
}
onLoad={(e: any) => {
setDimensions({
width: e.target.naturalWidth,
height: e.target.naturalHeight,
});
}}
draggable="false"
alt=""
className={`h-full w-full bg-[#1d1c23] object-contain`}
/>
</>
2022-11-11 21:39:28 +01:00
)}
2022-11-25 08:30:03 +01:00
{/* BATCH UPSCALE SHOW SELECTED FOLDER */}
2022-11-11 21:39:28 +01:00
{batchMode &&
upscaledBatchFolderPath.length === 0 &&
batchFolderPath.length > 0 && (
2023-03-18 18:08:50 +01:00
<p className="select-none font-bold text-neutral-50">
2022-11-11 21:39:28 +01:00
Selected folder: {batchFolderPath}
</p>
)}
2022-11-25 08:30:03 +01:00
{/* BATCH UPSCALE DONE INFO */}
2022-11-11 21:39:28 +01:00
{batchMode && upscaledBatchFolderPath.length > 0 && (
<>
2023-03-18 18:08:50 +01:00
<p className="select-none py-4 font-bold text-neutral-50">
2022-11-11 21:39:28 +01:00
All done!
</p>
<button
className="bg-gradient-blue rounded-lg p-3 font-medium text-white/90 transition-colors"
2022-11-23 19:24:30 +01:00
onClick={openFolderHandler}>
2022-11-11 21:39:28 +01:00
Open Upscayled Folder
</button>
</>
)}
2022-11-25 08:30:03 +01:00
{/* COMPARISON SLIDER */}
{!batchMode &&
!isVideo &&
imagePath.length > 0 &&
upscaledImagePath.length > 0 && (
<>
2022-12-16 17:20:46 +01:00
<ImageOptions
zoomAmount={zoomAmount}
setZoomAmount={setZoomAmount}
2022-12-21 16:43:54 +01:00
resetImagePaths={resetImagePaths}
2022-12-16 17:20:46 +01:00
/>
2022-11-25 08:30:03 +01:00
<ReactCompareSlider
itemOne={
<>
<p className="absolute bottom-1 left-1 rounded-md bg-black p-1 text-sm font-medium text-white opacity-30">
Original
</p>
2022-12-21 11:32:45 +01:00
<img
2022-11-25 08:30:03 +01:00
src={"file://" + imagePath}
alt="Original"
2022-12-24 08:40:45 +01:00
onMouseMove={handleMouseMove}
2022-11-25 08:30:03 +01:00
style={{
objectFit: "contain",
2022-12-24 08:40:45 +01:00
backgroundPosition: "0% 0%",
2022-12-21 11:32:45 +01:00
transformOrigin: backgroundPosition,
2022-11-25 08:30:03 +01:00
}}
2022-12-21 11:32:45 +01:00
className={`h-full w-full bg-[#1d1c23] transition-transform group-hover:scale-[${zoomAmount}]`}
2022-11-25 08:30:03 +01:00
/>
</>
}
itemTwo={
<>
<p className="absolute bottom-1 right-1 rounded-md bg-black p-1 text-sm font-medium text-white opacity-30">
Upscayled
</p>
2022-12-21 11:32:45 +01:00
<img
2022-11-25 08:30:03 +01:00
src={"file://" + upscaledImagePath}
alt="Upscayl"
style={{
objectFit: "contain",
2022-12-24 08:40:45 +01:00
backgroundPosition: "0% 0%",
2022-12-21 11:32:45 +01:00
transformOrigin: backgroundPosition,
2022-11-25 08:30:03 +01:00
}}
2022-12-21 11:32:45 +01:00
onMouseMove={handleMouseMove}
className={`h-full w-full bg-[#1d1c23] transition-transform group-hover:scale-[${zoomAmount}]`}
2022-11-25 08:30:03 +01:00
/>
</>
}
2022-12-21 11:32:45 +01:00
className="group h-screen"
2022-11-25 08:30:03 +01:00
/>
</>
)}
{isVideo && videoPath.length > 0 && upscaledVideoPath.length === 0 && (
<video autoPlay controls className="m-10 w-11/12 rounded-2xl">
<source src={"file://" + videoPath} type="video/mp4" />
</video>
2022-11-11 21:39:28 +01:00
)}
</div>
</div>
);
};
export default Home;