1
0
mirror of https://github.com/upscayl/upscayl.git synced 2024-11-12 01:40:53 +01:00
upscayl/renderer/pages/index.tsx

681 lines
22 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";
2023-07-22 13:07:53 +02:00
import ProgressBar from "../components/upscayl-tab/view/ProgressBar";
import RightPaneInfo from "../components/upscayl-tab/view/RightPaneInfo";
import ImageOptions from "../components/upscayl-tab/view/ImageOptions";
import LeftPaneImageSteps from "../components/upscayl-tab/config/LeftPaneImageSteps";
2023-03-18 18:08:50 +01:00
import Tabs from "../components/Tabs";
2023-07-22 13:07:53 +02:00
import SettingsTab from "../components/settings-tab";
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";
2023-04-30 03:34:25 +02:00
import { batchModeAtom, scaleAtom } from "../atoms/userSettingsAtom";
2023-04-30 03:44:47 +02:00
import useLog from "../components/hooks/useLog";
import { UpscaylCloudModal } from "../components/UpscaylCloudModal";
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
2023-08-14 12:56:11 +02:00
const [os, setOs] = useState<"linux" | "mac" | "win" | undefined>(undefined);
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("");
2023-04-30 03:34:25 +02:00
const [scaleFactor] = useState(4);
2022-11-11 21:39:28 +01:00
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("");
2023-04-15 05:56:40 +02:00
const [batchMode, setBatchMode] = useAtom(batchModeAtom);
2022-11-11 21:39:28 +01:00
const [batchFolderPath, setBatchFolderPath] = useState("");
const [upscaledBatchFolderPath, setUpscaledBatchFolderPath] = useState("");
const [doubleUpscayl, setDoubleUpscayl] = useState(false);
2023-08-10 12:17:35 +02:00
const [overwrite, setOverwrite] = useState(false);
2022-12-02 15:21:42 +01:00
const [doubleUpscaylCounter, setDoubleUpscaylCounter] = useState(0);
const [quality, setQuality] = 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 [modelOptions, setModelOptions] = useAtom(modelsListAtom);
2023-04-14 12:31:37 +02:00
const [scale] = useAtom(scaleAtom);
2023-03-31 12:33:48 +02:00
2023-08-23 17:07:44 +02:00
const [showCloudModal, setShowCloudModal] = useState(true);
2023-04-30 03:44:47 +02:00
const { logit } = useLog();
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, or your GPU drivers are acting funny (Did you check if your GPU is compatible and drivers are alright?). You could try converting the image into another format and upscaling again. Also make sure that the output path is correct and you have the proper write permissions for the directory. If not, then unfortuantely there's not much we can do to help, sorry."
2022-11-11 21:39:28 +01:00
);
resetImagePaths();
} else if (data.includes("uncaughtException")) {
alert(
"Upscayl encountered an error. Possibly, the upscayl binary failed to execute the commands properly. Try checking the logs to see if you get any information. You can post an issue on Upscayl's GitHub repository for more help."
2022-11-11 21:39:28 +01:00
);
resetImagePaths();
}
};
2023-08-14 12:55:30 +02:00
window.electron.on(
commands.OS,
(_, data: "linux" | "mac" | "win" | undefined) => {
if (data) {
setOs(data);
}
}
);
2023-04-14 12:31:37 +02:00
// LOG
window.electron.on(commands.LOG, (_, data: string) => {
logit(`🐞 BACKEND REPORTED: `, data);
2023-04-14 12:31:37 +02:00
});
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);
logit(`🚧 UPSCAYL_PROGRESS: `, 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);
logit(`🚧 FOLDER_UPSCAYL_PROGRESS: `, 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);
logit(`🚧 DOUBLE_UPSCAYL_PROGRESS: `, data);
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-07-22 15:00:46 +02:00
logit("upscaledImagePath: ", data);
logit(`💯 UPSCAYL_DONE: `, 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);
logit(`💯 FOLDER_UPSCAYL_DONE: `, 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);
setUpscaledImagePath(data);
logit(`💯 DOUBLE_UPSCAYL_DONE: `, data);
2022-11-11 21:39:28 +01:00
});
2022-12-16 17:20:46 +01:00
2023-04-09 07:48:53 +02:00
// CUSTOM FOLDER LISTENER
window.electron.on(
commands.CUSTOM_MODEL_FILES_LIST,
2023-04-12 15:25:24 +02:00
(_, data: string[]) => {
logit(`📜 CUSTOM_MODEL_FILES_LIST: `, data);
2023-04-12 15:25:24 +02:00
const newModelOptions = data.map((model) => {
return {
value: model,
label: model,
};
2023-04-09 07:48:53 +02:00
});
2023-04-12 15:25:24 +02:00
// Add newModelsList to modelOptions and remove duplicates
const combinedModelOptions = [...modelOptions, ...newModelOptions];
const uniqueModelOptions = combinedModelOptions.filter(
// Check if any model in the array appears more than once
(model, index, array) =>
array.findIndex((t) => t.value === model.value) === index
);
setModelOptions(uniqueModelOptions);
2023-04-09 07:48:53 +02:00
}
);
}, []);
useEffect(() => {
const customModelsPath = JSON.parse(
localStorage.getItem("customModelsPath")
);
if (customModelsPath !== null) {
window.electron.send(commands.GET_MODELS_LIST, customModelsPath);
logit("🎯 GET_MODELS_LIST: ", customModelsPath);
2023-04-09 07:48:53 +02:00
}
2022-11-11 21:39:28 +01:00
}, []);
2023-04-28 14:47:51 +02:00
useEffect(() => {
const rememberOutputFolder = localStorage.getItem("rememberOutputFolder");
const lastOutputFolderPath = localStorage.getItem("lastOutputFolderPath");
if (rememberOutputFolder === "true") {
setOutputPath(lastOutputFolderPath);
} else {
setOutputPath("");
localStorage.removeItem("lastOutputFolderPath");
}
}, []);
2022-11-11 21:39:28 +01:00
useEffect(() => {
setProgress("");
setOutputPath("");
2022-11-11 21:39:28 +01:00
}, [batchMode]);
useEffect(() => {
2023-08-14 12:55:30 +02:00
if (imagePath.length > 0) {
logit("🖼 imagePath: ", imagePath);
2022-11-11 21:39:28 +01:00
const extension = imagePath.toLocaleLowerCase().split(".").pop();
logit("🔤 Extension: ", extension);
2022-11-11 21:39:28 +01:00
if (!allowedFileTypes.includes(extension.toLowerCase())) {
alert("Please select an image");
resetImagePaths();
}
2022-11-25 08:30:03 +01:00
} else {
resetImagePaths();
2022-11-11 21:39:28 +01:00
}
2023-08-14 12:55:30 +02:00
}, [imagePath]);
2022-11-11 21:39:28 +01:00
2022-12-16 17:20:46 +01:00
const resetImagePaths = () => {
logit("🔄 Resetting image paths");
2022-12-24 08:17:54 +01:00
setDimensions({
width: null,
height: null,
});
2023-04-30 03:34:25 +02:00
2022-12-16 17:20:46 +01:00
setProgress("");
SetImagePath("");
setUpscaledImagePath("");
setBatchFolderPath("");
setUpscaledBatchFolderPath("");
};
// 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
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) {
logit("🖼 Selected Image Path: ", path);
SetImagePath(path);
2022-11-11 21:39:28 +01:00
var dirname = path.match(/(.*)[\/\\]/)[1] || "";
logit("📁 Selected Image Directory: ", dirname);
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) {
logit("🖼 Selected Folder Path: ", path);
2022-11-11 21:39:28 +01:00
setBatchFolderPath(path);
2022-11-23 19:24:30 +01:00
setOutputPath(path + "_upscayled");
2023-05-01 08:34:45 +02:00
} else {
logit("🚫 Folder selection cancelled");
2023-05-01 08:34:45 +02:00
setBatchFolderPath("");
setOutputPath("");
2022-11-11 21:39:28 +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);
logit("🔀 Model changed: ", 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) => {
logit("📂 OPEN_FOLDER: ", upscaledBatchFolderPath);
2022-11-11 21:39:28 +01:00
window.electron.send(commands.OPEN_FOLDER, upscaledBatchFolderPath);
};
const handleDrop = (e) => {
e.preventDefault();
resetImagePaths();
2023-04-20 20:34:49 +02:00
if (
e.dataTransfer.items.length === 0 ||
e.dataTransfer.files.length === 0
) {
logit("👎 No valid files dropped");
2023-04-20 20:34:49 +02:00
alert("Please drag and drop an image");
return;
}
2022-11-11 21:39:28 +01:00
const type = e.dataTransfer.items[0].type;
const filePath = e.dataTransfer.files[0].path;
const extension = e.dataTransfer.files[0].name.split(".").at(-1);
logit("⤵️ Dropped file: ", JSON.stringify({ type, filePath, extension }));
2022-11-11 21:39:28 +01:00
if (
2023-08-14 12:55:30 +02:00
!type.includes("image") ||
!allowedFileTypes.includes(extension.toLowerCase())
2022-11-11 21:39:28 +01:00
) {
logit("🚫 Invalid file dropped");
2022-11-11 21:39:28 +01:00
alert("Please drag and drop an image");
} else {
2023-08-14 12:55:30 +02:00
logit("🖼 Setting image path: ", filePath);
SetImagePath(filePath);
2022-11-25 07:54:30 +01:00
2022-11-11 21:39:28 +01:00
var dirname = filePath.match(/(.*)[\/\\]/)[1] || "";
logit("🗂 Setting output path: ", dirname);
2022-11-23 19:24:30 +01:00
setOutputPath(dirname);
2022-11-11 21:39:28 +01:00
}
};
const handlePaste = (e) => {
resetImagePaths();
e.preventDefault();
2022-11-11 21:39:28 +01:00
const type = e.clipboardData.items[0].type;
const filePath = e.clipboardData.files[0].path;
const extension = e.clipboardData.files[0].name.split(".").at(-1);
logit("📋 Pasted file: ", JSON.stringify({ type, filePath, extension }));
2022-11-11 21:39:28 +01:00
if (
!type.includes("image") &&
!allowedFileTypes.includes(extension.toLowerCase())
) {
alert("Please drag and drop an image");
} else {
SetImagePath(filePath);
2022-11-11 21:39:28 +01:00
var dirname = filePath.match(/(.*)[\/\\]/)[1] || "";
logit("🗂 Setting output path: ", dirname);
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) {
logit("🗂 Setting Output Path: ", path);
2022-11-23 19:24:30 +01:00
setOutputPath(path);
2023-04-28 14:47:51 +02:00
const rememberOutputFolder = localStorage.getItem("rememberOutputFolder");
2023-04-28 14:47:51 +02:00
if (rememberOutputFolder) {
logit("🧠 Remembering Output Folder: ", path);
2023-04-28 14:47:51 +02:00
localStorage.setItem("lastOutputFolderPath", path);
}
2022-11-11 21:39:28 +01:00
} else {
2023-05-01 08:34:45 +02:00
setOutputPath("");
2022-11-11 21:39:28 +01:00
}
};
const upscaylHandler = async () => {
2023-08-14 12:55:30 +02:00
logit("🔄 Resetting Upscaled Image Path");
setUpscaledImagePath("");
2023-03-12 08:41:43 +01:00
2023-08-14 12:55:30 +02:00
if (imagePath !== "" || batchFolderPath !== "") {
2022-11-11 21:39:28 +01:00
setProgress("Hold on...");
if (doubleUpscayl) {
2023-04-14 12:31:37 +02:00
window.electron.send(commands.DOUBLE_UPSCAYL, {
2022-11-11 21:39:28 +01:00
imagePath,
outputPath,
model,
2022-12-16 17:20:46 +01:00
gpuId: gpuId.length === 0 ? null : gpuId,
saveImageAs,
2023-04-14 12:31:37 +02:00
scale,
2022-11-11 21:39:28 +01:00
});
logit("🏁 DOUBLE_UPSCAYL");
2022-11-11 21:39:28 +01:00
} else if (batchMode) {
setDoubleUpscayl(false);
2023-04-14 12:31:37 +02:00
window.electron.send(commands.FOLDER_UPSCAYL, {
2022-11-11 21:39:28 +01:00
scaleFactor,
batchFolderPath,
outputPath,
model,
2022-12-16 17:20:46 +01:00
gpuId: gpuId.length === 0 ? null : gpuId,
saveImageAs,
2023-04-14 12:31:37 +02:00
scale,
2022-11-11 21:39:28 +01:00
});
logit("🏁 FOLDER_UPSCAYL");
2022-11-11 21:39:28 +01:00
} else {
2023-04-14 12:31:37 +02:00
window.electron.send(commands.UPSCAYL, {
2022-11-11 21:39:28 +01:00
scaleFactor,
imagePath,
outputPath,
model,
2022-12-16 17:20:46 +01:00
gpuId: gpuId.length === 0 ? null : gpuId,
saveImageAs,
2023-04-14 12:31:37 +02:00
scale,
2023-08-27 18:11:01 +02:00
overwrite,
2022-11-11 21:39:28 +01:00
});
logit("🏁 UPSCAYL");
2022-11-11 21:39:28 +01:00
}
2023-04-14 12:31:37 +02:00
}
// else if (isVideo && videoPath !== "") {
// window.electron.send(commands.UPSCAYL_VIDEO, {
// scaleFactor,
// videoPath,
// outputPath,
// model,
// gpuId: gpuId.length === 0 ? null : gpuId,
// saveImageAs,
// });
// }
else {
2023-08-14 12:55:30 +02:00
alert(`Please select an image to upscale`);
logit("🚫 No valid image selected");
2022-11-11 21:39:28 +01:00
}
};
2023-04-28 20:21:42 +02:00
const stopHandler = () => {
window.electron.send(commands.STOP);
logit("🛑 Stopping Upscayl");
2023-04-28 20:21:42 +02:00
resetImagePaths();
};
2022-12-16 17:20:46 +01:00
const allowedFileTypes = ["png", "jpg", "jpeg", "webp"];
2023-08-30 06:54:16 +02:00
if (typeof window === "undefined") {
return (
<img
src="/icon.png"
alt="Upscayl icon"
className="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-36 animate-pulse"
/>
);
}
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">
2023-08-30 06:54:16 +02:00
<div className={`flex h-screen w-128 flex-col bg-base-100`}>
2023-08-30 07:35:40 +02:00
<UpscaylCloudModal show={showCloudModal} setShow={setShowCloudModal} />
2023-08-30 06:54:16 +02:00
{window.electron.platform === "mac" && (
<div className="pt-8 mac-titlebar"></div>
)}
2022-11-11 21:39:28 +01:00
{/* HEADER */}
2023-08-30 09:58:15 +02:00
<Header version={version} />
2023-08-30 07:35:40 +02:00
<button
className="mb-5 rounded-btn p-1 mx-5 bg-success shadow-lg shadow-success/40 text-slate-50 animate-pulse text-sm"
onClick={() => {
setShowCloudModal(true);
}}>
Introducing Upscayl Cloud
</button>
2023-03-18 18:08:50 +01:00
<Tabs selectedTab={selectedTab} setSelectedTab={setSelectedTab} />
2023-08-14 12:55:30 +02:00
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}
outputHandler={outputHandler}
upscaylHandler={upscaylHandler}
batchMode={batchMode}
setBatchMode={setBatchMode}
imagePath={imagePath}
outputPath={outputPath}
doubleUpscayl={doubleUpscayl}
setDoubleUpscayl={setDoubleUpscayl}
2022-12-24 08:17:54 +01:00
dimensions={dimensions}
2023-05-01 11:23:11 +02:00
setGpuId={setGpuId}
setModel={setModel}
setSaveImageAs={setSaveImageAs}
2022-11-23 19:24:30 +01:00
/>
)}
2023-03-18 18:08:50 +01:00
{selectedTab === 1 && (
<SettingsTab
batchMode={batchMode}
setModel={setModel}
quality={quality}
setQuality={setQuality}
2023-03-18 18:08:50 +01:00
gpuId={gpuId}
setGpuId={setGpuId}
saveImageAs={saveImageAs}
setSaveImageAs={setSaveImageAs}
2023-04-08 08:53:32 +02:00
logData={logData}
2023-08-10 12:17:35 +02:00
overwrite={overwrite}
setOverwrite={setOverwrite}
2023-08-14 12:55:30 +02:00
os={os}
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)}
onPaste={(e) => handlePaste(e)}>
2023-08-30 06:54:16 +02:00
{window.electron.platform === "mac" && (
<div className="absolute top-0 w-full h-8 mac-titlebar"></div>
)}
2022-11-11 21:39:28 +01:00
{progress.length > 0 &&
upscaledImagePath.length === 0 &&
2023-08-14 12:55:30 +02:00
upscaledBatchFolderPath.length === 0 ? (
2022-12-02 15:21:42 +01:00
<ProgressBar
batchMode={batchMode}
2022-12-02 15:21:42 +01:00
progress={progress}
doubleUpscaylCounter={doubleUpscaylCounter}
2023-04-28 20:21:42 +02:00
stopHandler={stopHandler}
2022-12-02 15:21:42 +01:00
/>
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 */}
2023-08-14 12:55:30 +02:00
{((!batchMode &&
imagePath.length === 0 &&
2022-11-11 21:39:28 +01:00
upscaledImagePath.length === 0) ||
2023-08-14 12:55:30 +02:00
(batchMode &&
batchFolderPath.length === 0 &&
2023-08-14 12:55:30 +02:00
upscaledBatchFolderPath.length === 0)) && (
<RightPaneInfo version={version} batchMode={batchMode} />
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 &&
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.replace(
/([^/\\]+)$/i,
encodeURIComponent(
upscaledImagePath.match(/[^/\\]+$/i)[0]
)
)
: imagePath.replace(
/([^/\\]+)$/i,
encodeURIComponent(imagePath.match(/[^/\\]+$/i)[0])
)
}`
2022-12-24 08:40:45 +01:00
}
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-12-24 08:40:45 +01:00
/>
</>
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
2023-08-26 09:27:15 +02:00
className="btn btn-primary bg-gradient-blue rounded-btn p-3 font-medium text-white/90 transition-colors"
onClick={openFolderHandler}>
2022-11-11 21:39:28 +01:00
Open Upscayled Folder
</button>
</>
)}
2022-11-25 08:30:03 +01:00
{/* COMPARISON SLIDER */}
2023-08-14 12:55:30 +02:00
{!batchMode && imagePath.length > 0 && upscaledImagePath.length > 0 && (
<>
<ImageOptions
zoomAmount={zoomAmount}
setZoomAmount={setZoomAmount}
resetImagePaths={resetImagePaths}
/>
<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>
<img
/* USE REGEX TO GET THE FILENAME AND ENCODE IT INTO PROPER FORM IN ORDER TO AVOID ERRORS DUE TO SPECIAL CHARACTERS */
src={
"file:///" +
imagePath.replace(
/([^/\\]+)$/i,
encodeURIComponent(imagePath.match(/[^/\\]+$/i)[0])
)
}
alt="Original"
onMouseMove={handleMouseMove}
style={{
objectFit: "contain",
backgroundPosition: "0% 0%",
transformOrigin: backgroundPosition,
}}
className={`h-full w-full bg-[#1d1c23] transition-transform group-hover:scale-[${zoomAmount}]`}
/>
</>
}
itemTwo={
<>
<p className="absolute bottom-1 right-1 rounded-md bg-black p-1 text-sm font-medium text-white opacity-30">
Upscayled
</p>
<img
/* USE REGEX TO GET THE FILENAME AND ENCODE IT INTO PROPER FORM IN ORDER TO AVOID ERRORS DUE TO SPECIAL CHARACTERS */
src={
"file://" +
upscaledImagePath.replace(
/([^/\\]+)$/i,
encodeURIComponent(
upscaledImagePath.match(/[^/\\]+$/i)[0]
)
2023-08-14 12:55:30 +02:00
)
}
alt="Upscayl"
style={{
objectFit: "contain",
backgroundPosition: "0% 0%",
transformOrigin: backgroundPosition,
}}
onMouseMove={handleMouseMove}
className={`h-full w-full bg-[#1d1c23] transition-transform group-hover:scale-[${zoomAmount}]`}
/>
</>
}
2023-08-14 12:55:30 +02:00
className="group h-screen"
/>
2023-08-14 12:55:30 +02:00
</>
2022-11-11 21:39:28 +01:00
)}
</div>
</div>
);
};
export default Home;