import { useAtom, useAtomValue } from "jotai"; import React, { useEffect, useMemo } from "react"; import { Tooltip } from "react-tooltip"; import { themeChange } from "theme-change"; import useLogger from "../../hooks/use-logger"; import { savedOutputPathAtom, progressAtom, rememberOutputFolderAtom, scaleAtom, customWidthAtom, useCustomWidthAtom, } from "../../../atoms/user-settings-atom"; import { FEATURE_FLAGS } from "@common/feature-flags"; import { ELECTRON_COMMANDS } from "@common/electron-commands"; import { useToast } from "@/components/ui/use-toast"; import { translationAtom } from "@/atoms/translations-atom"; import { SelectImageScale } from "../settings-tab/select-image-scale"; import SelectModel from "./select-model"; import { ImageFormat } from "@/lib/valid-formats"; interface IProps { selectImageHandler: () => Promise; selectFolderHandler: () => Promise; upscaylHandler: () => Promise; batchMode: boolean; setBatchMode: React.Dispatch>; imagePath: string; doubleUpscayl: boolean; setDoubleUpscayl: React.Dispatch>; dimensions: { width: number | null; height: number | null; }; setSaveImageAs: React.Dispatch>; setGpuId: React.Dispatch>; } function UpscaylSteps({ selectImageHandler, selectFolderHandler, upscaylHandler, batchMode, setBatchMode, imagePath, doubleUpscayl, setDoubleUpscayl, dimensions, }: IProps) { const [scale, setScale] = useAtom(scaleAtom); const [outputPath, setOutputPath] = useAtom(savedOutputPathAtom); const [progress, setProgress] = useAtom(progressAtom); const rememberOutputFolder = useAtomValue(rememberOutputFolderAtom); const customWidth = useAtomValue(customWidthAtom); const useCustomWidth = useAtomValue(useCustomWidthAtom); const logit = useLogger(); const { toast } = useToast(); const t = useAtomValue(translationAtom); const outputHandler = async () => { const path = await window.electron.invoke(ELECTRON_COMMANDS.SELECT_FOLDER); if (path !== null) { logit("🗂 Setting Output Path: ", path); setOutputPath(path); } else { setOutputPath(null); } }; useEffect(() => { themeChange(false); }, []); const upscaylResolution = useMemo(() => { const newDimensions = { width: dimensions.width, height: dimensions.height, }; let doubleScale = parseInt(scale) * parseInt(scale); let singleScale = parseInt(scale); if (doubleUpscayl) { if (useCustomWidth) { newDimensions.width = customWidth; newDimensions.height = Math.round( customWidth * (dimensions.height / dimensions.width), ); } else { const newWidth = dimensions.width * doubleScale; const newHeight = dimensions.height * doubleScale; newDimensions.width = newWidth; newDimensions.height = newHeight; } } else { if (useCustomWidth) { newDimensions.width = customWidth; newDimensions.height = Math.round( customWidth * (dimensions.height / dimensions.width), ); } else { newDimensions.width = dimensions.width * singleScale; newDimensions.height = dimensions.height * singleScale; } } return newDimensions; }, [dimensions.width, dimensions.height, doubleUpscayl, scale]); return (
{/* BATCH OPTION */}
{ if (!rememberOutputFolder) { setOutputPath(""); } setProgress(""); setBatchMode((oldValue) => !oldValue); }} >

{t("APP.BATCH_MODE.TITLE")}

{/* STEP 1 */}

{t("APP.FILE_SELECTION.TITLE")}

{/* STEP 2 */}

{t("APP.MODEL_SELECTION.TITLE")}

{t("APP.MODEL_SELECTION.DESCRIPTION")}

{!batchMode && (
{ if (e.target.checked) { setDoubleUpscayl(true); } else { setDoubleUpscayl(false); } }} />

{ setDoubleUpscayl(!doubleUpscayl); }} > {t("APP.DOUBLE_UPSCAYL.TITLE")}

)}
{/* STEP 3 */}
{t("APP.OUTPUT_PATH_SELECTION.TITLE")} {FEATURE_FLAGS.APP_STORE_BUILD && ( )}
{!outputPath && FEATURE_FLAGS.APP_STORE_BUILD && (
{t("APP.OUTPUT_PATH_SELECTION.NOT_SELECTED")}
)}
{!batchMode && !FEATURE_FLAGS.APP_STORE_BUILD && (

{!batchMode ? t("APP.OUTPUT_PATH_SELECTION.DEFAULT_IMG_PATH") : t("APP.OUTPUT_PATH_SELECTION.DEFAULT_FOLDER_PATH")}

)}
{/* STEP 4 */}

{t("APP.SCALE_SELECTION.TITLE")}

{dimensions.width && dimensions.height && (

{t("APP.SCALE_SELECTION.FROM_TITLE")} {dimensions.width}x{dimensions.height} {t("APP.SCALE_SELECTION.TO_TITLE")} {upscaylResolution.width}x{upscaylResolution.height}

)}
); } export default UpscaylSteps;