import React, { useEffect, useState } from "react"; import { themeChange } from "theme-change"; import commands from "../../electron/commands"; import { useAtom, useAtomValue } from "jotai"; import { customModelsPathAtom, scaleAtom } from "../atoms/userSettingsAtom"; import { modelsListAtom } from "../atoms/modelsListAtom"; import useLog from "./hooks/useLog"; interface IProps { batchMode: boolean; setModel: React.Dispatch>; saveImageAs: string; setSaveImageAs: React.Dispatch>; gpuId: string; setGpuId: React.Dispatch>; logData: string[]; } function SettingsTab({ batchMode, setModel, gpuId, setGpuId, saveImageAs, setSaveImageAs, logData, }: IProps) { // STATES const [currentModel, setCurrentModel] = useState<{ label: string; value: string; }>({ label: null, value: null, }); const [rememberOutputFolder, setRememberOutputFolder] = useState(false); const [isCopied, setIsCopied] = useState(false); const [customModelsPath, setCustomModelsPath] = useAtom(customModelsPathAtom); const modelOptions = useAtomValue(modelsListAtom); const [scale, setScale] = useAtom(scaleAtom); const { logit } = useLog(); useEffect(() => { themeChange(false); if (!localStorage.getItem("saveImageAs")) { logit("📢 Setting saveImageAs to png"); localStorage.setItem("saveImageAs", "png"); } else { const currentlySavedImageFormat = localStorage.getItem("saveImageAs"); logit( "📢 Getting saveImageAs from localStorage", currentlySavedImageFormat ); setSaveImageAs(currentlySavedImageFormat); } if (!localStorage.getItem("model")) { setCurrentModel(modelOptions[0]); setModel(modelOptions[0].value); localStorage.setItem("model", JSON.stringify(modelOptions[0])); logit("📢 Setting model to", modelOptions[0].value); } else { const currentlySavedModel = JSON.parse( localStorage.getItem("model") ) as (typeof modelOptions)[0]; setCurrentModel(currentlySavedModel); setModel(currentlySavedModel.value); logit( "📢 Getting model from localStorage", JSON.stringify(currentlySavedModel) ); } if (!localStorage.getItem("gpuId")) { localStorage.setItem("gpuId", ""); logit("📢 Setting gpuId to empty string"); } else { const currentlySavedGpuId = localStorage.getItem("gpuId"); setGpuId(currentlySavedGpuId); logit("📢 Getting gpuId from localStorage", currentlySavedGpuId); } if (!localStorage.getItem("rememberOutputFolder")) { logit("📢 Setting rememberOutputFolder to false"); localStorage.setItem("rememberOutputFolder", "false"); } else { const currentlySavedRememberOutputFolder = localStorage.getItem( "rememberOutputFolder" ); logit( "📢 Getting rememberOutputFolder from localStorage", currentlySavedRememberOutputFolder ); setRememberOutputFolder( currentlySavedRememberOutputFolder === "true" ? true : false ); } }, []); // HANDLERS const setExportType = (format: string) => { setSaveImageAs(format); localStorage.setItem("saveImageAs", format); }; const handleGpuIdChange = (e) => { setGpuId(e.target.value); localStorage.setItem("gpuId", e.target.value); }; const copyOnClickHandler = () => { navigator.clipboard.writeText(logData.join("\n")); setIsCopied(true); setTimeout(() => { setIsCopied(false); }, 2000); }; const availableThemes = [ { label: "light", value: "light" }, { label: "dark", value: "dark" }, { label: "cupcake", value: "cupcake" }, { label: "bumblebee", value: "bumblebee" }, { label: "emerald", value: "emerald" }, { label: "corporate", value: "corporate" }, { label: "synthwave", value: "synthwave" }, { label: "retro", value: "retro" }, { label: "cyberpunk", value: "cyberpunk" }, { label: "valentine", value: "valentine" }, { label: "halloween", value: "halloween" }, { label: "garden", value: "garden" }, { label: "forest", value: "forest" }, { label: "aqua", value: "aqua" }, { label: "lofi", value: "lofi" }, { label: "pastel", value: "pastel" }, { label: "fantasy", value: "fantasy" }, { label: "wireframe", value: "wireframe" }, { label: "black", value: "black" }, { label: "luxury", value: "luxury" }, { label: "dracula", value: "dracula" }, { label: "cmyk", value: "cmyk" }, { label: "autumn", value: "autumn" }, { label: "business", value: "business" }, { label: "acid", value: "acid" }, { label: "lemonade", value: "lemonade" }, { label: "night", value: "night" }, { label: "coffee", value: "coffee" }, { label: "winter", value: "winter" }, ]; return (
{/* THEME SELECTOR */}

UPSCAYL THEME

SAVE OUTPUT FOLDER (PERMANENTLY)

{ setRememberOutputFolder((oldValue) => { if (oldValue === true) { localStorage.removeItem("lastOutputFolderPath"); } return !oldValue; }); localStorage.setItem( "rememberOutputFolder", JSON.stringify(!rememberOutputFolder) ); }} />
{/* GPU ID INPUT */}

GPU ID

{/* CUSTOM MODEL */}

ADD CUSTOM MODELS

{customModelsPath}

{/* IMAGE FORMAT BUTTONS */}

SAVE IMAGE AS

EXPERIMENTAL

{batchMode && (

Only PNG is supported in Batch Upscale

)}
{/* PNG */} {/* JPG */} {/* WEBP */}
{/* IMAGE SCALE */}

IMAGE SCALE

EXPERIMENTAL

{ setScale(e.target.value.toString()); }} step="1" className="range range-primary mt-2" />
2x 3x 4x

LOGS

{logData.length === 0 && (

No logs to show

)} {logData.map((logLine) => { console.log(logData); return

{logLine}

; })}
{/* DONATE BUTTON */}

If you like what we do :)

); } export default SettingsTab;