2023-07-22 13:07:53 +02:00
|
|
|
import { ThemeSelect } from "./ThemeSelect";
|
|
|
|
import { SaveOutputFolderToggle } from "./SaveOutputFolderToggle";
|
|
|
|
import { GpuIdInput } from "./GpuIdInput";
|
|
|
|
import { CustomModelsFolderSelect } from "./CustomModelsFolderSelect";
|
|
|
|
import { LogArea } from "./LogArea";
|
|
|
|
import { ImageScaleSelect } from "./ImageScaleSelect";
|
|
|
|
import { ImageFormatSelect } from "./ImageFormatSelect";
|
|
|
|
import { DonateButton } from "./DonateButton";
|
|
|
|
import React, { useEffect, useState } from "react";
|
|
|
|
import { themeChange } from "theme-change";
|
|
|
|
import { useAtom, useAtomValue } from "jotai";
|
2023-09-18 20:30:43 +02:00
|
|
|
import {
|
|
|
|
customModelsPathAtom,
|
|
|
|
noImageProcessingAtom,
|
|
|
|
scaleAtom,
|
|
|
|
} from "../../atoms/userSettingsAtom";
|
2023-07-22 13:07:53 +02:00
|
|
|
import { modelsListAtom } from "../../atoms/modelsListAtom";
|
|
|
|
import useLog from "../hooks/useLog";
|
2023-09-16 12:34:35 +02:00
|
|
|
import { CompressionInput } from "./CompressionInput";
|
2023-09-18 20:30:43 +02:00
|
|
|
import OverwriteToggle from "./OverwriteToggle";
|
2023-09-03 11:16:48 +02:00
|
|
|
import { UpscaylCloudModal } from "../UpscaylCloudModal";
|
|
|
|
import { ResetSettings } from "./ResetSettings";
|
2023-09-18 20:30:43 +02:00
|
|
|
import ProcessImageToggle from "./ProcessImageToggle";
|
2023-07-22 13:07:53 +02:00
|
|
|
|
|
|
|
interface IProps {
|
|
|
|
batchMode: boolean;
|
|
|
|
setModel: React.Dispatch<React.SetStateAction<string>>;
|
|
|
|
saveImageAs: string;
|
|
|
|
setSaveImageAs: React.Dispatch<React.SetStateAction<string>>;
|
2023-09-13 16:07:45 +02:00
|
|
|
compression: number;
|
|
|
|
setCompression: React.Dispatch<React.SetStateAction<number>>;
|
2023-07-22 13:07:53 +02:00
|
|
|
gpuId: string;
|
|
|
|
setGpuId: React.Dispatch<React.SetStateAction<string>>;
|
|
|
|
logData: string[];
|
2023-08-10 12:17:35 +02:00
|
|
|
overwrite: boolean;
|
|
|
|
setOverwrite: (arg: any) => void;
|
2023-08-14 12:55:30 +02:00
|
|
|
os: "linux" | "mac" | "win" | undefined;
|
2023-09-03 11:16:48 +02:00
|
|
|
show: boolean;
|
|
|
|
setShow: React.Dispatch<React.SetStateAction<boolean>>;
|
|
|
|
setDontShowCloudModal: React.Dispatch<React.SetStateAction<boolean>>;
|
2023-07-22 13:07:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function SettingsTab({
|
|
|
|
batchMode,
|
|
|
|
setModel,
|
2023-09-13 16:07:45 +02:00
|
|
|
compression,
|
|
|
|
setCompression,
|
2023-07-22 13:07:53 +02:00
|
|
|
gpuId,
|
|
|
|
setGpuId,
|
|
|
|
saveImageAs,
|
|
|
|
setSaveImageAs,
|
|
|
|
logData,
|
2023-08-10 12:17:35 +02:00
|
|
|
overwrite,
|
|
|
|
setOverwrite,
|
2023-08-14 12:55:30 +02:00
|
|
|
os,
|
2023-09-03 11:16:48 +02:00
|
|
|
show,
|
|
|
|
setShow,
|
|
|
|
setDontShowCloudModal,
|
2023-07-22 13:07:53 +02:00
|
|
|
}: 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);
|
2023-09-18 20:30:43 +02:00
|
|
|
const [noImageProcessing, setNoImageProcessing] = useAtom(
|
|
|
|
noImageProcessingAtom
|
|
|
|
);
|
2023-07-22 13:07:53 +02:00
|
|
|
|
|
|
|
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(
|
2023-09-13 16:07:45 +02:00
|
|
|
"⚙️ Getting saveImageAs from localStorage: ",
|
2023-07-22 13:07:53 +02:00
|
|
|
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(
|
2023-09-13 16:07:45 +02:00
|
|
|
"⚙️ Getting model from localStorage: ",
|
2023-07-22 13:07:53 +02:00
|
|
|
JSON.stringify(currentlySavedModel)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!localStorage.getItem("gpuId")) {
|
|
|
|
localStorage.setItem("gpuId", "");
|
|
|
|
logit("⚙️ Setting gpuId to empty string");
|
|
|
|
} else {
|
|
|
|
const currentlySavedGpuId = localStorage.getItem("gpuId");
|
|
|
|
setGpuId(currentlySavedGpuId);
|
2023-09-13 16:07:45 +02:00
|
|
|
logit("⚙️ Getting gpuId from localStorage: ", currentlySavedGpuId);
|
2023-07-22 13:07:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!localStorage.getItem("rememberOutputFolder")) {
|
|
|
|
logit("⚙️ Setting rememberOutputFolder to false");
|
|
|
|
localStorage.setItem("rememberOutputFolder", "false");
|
|
|
|
} else {
|
|
|
|
const currentlySavedRememberOutputFolder = localStorage.getItem(
|
|
|
|
"rememberOutputFolder"
|
|
|
|
);
|
|
|
|
logit(
|
2023-09-13 16:07:45 +02:00
|
|
|
"⚙️ Getting rememberOutputFolder from localStorage: ",
|
2023-07-22 13:07:53 +02:00
|
|
|
currentlySavedRememberOutputFolder
|
|
|
|
);
|
|
|
|
setRememberOutputFolder(
|
|
|
|
currentlySavedRememberOutputFolder === "true" ? true : false
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-09-16 12:34:35 +02:00
|
|
|
if (!localStorage.getItem("compression")) {
|
|
|
|
logit("⚙️ Setting compression to 100%");
|
|
|
|
localStorage.setItem("compression", JSON.stringify(compression));
|
2023-09-09 12:13:16 +02:00
|
|
|
} else {
|
2023-09-16 12:34:35 +02:00
|
|
|
const currentlySavedCompression = localStorage.getItem("compression");
|
|
|
|
logit("⚙️ Getting compression from localStorage", compression);
|
|
|
|
if (currentlySavedCompression) {
|
|
|
|
setCompression(JSON.parse(currentlySavedCompression));
|
2023-09-09 12:13:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}, []);
|
|
|
|
|
2023-07-22 13:07:53 +02:00
|
|
|
// HANDLERS
|
|
|
|
const setExportType = (format: string) => {
|
|
|
|
setSaveImageAs(format);
|
|
|
|
localStorage.setItem("saveImageAs", format);
|
|
|
|
};
|
|
|
|
|
2023-09-16 12:34:35 +02:00
|
|
|
const handleCompressionChange = (e) => {
|
2023-09-13 16:07:45 +02:00
|
|
|
setCompression(e.target.value);
|
2023-09-16 12:34:35 +02:00
|
|
|
localStorage.setItem("compression", e.target.value);
|
2023-07-23 11:07:18 +02:00
|
|
|
};
|
|
|
|
|
2023-07-22 13:07:53 +02:00
|
|
|
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);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="animate-step-in animate flex h-screen flex-col gap-7 overflow-y-auto p-5 overflow-x-hidden">
|
2023-07-23 08:32:22 +02:00
|
|
|
<div className="flex flex-col gap-2 text-sm font-medium">
|
|
|
|
<p>Having issues?</p>
|
|
|
|
<a
|
|
|
|
className="btn-primary btn"
|
|
|
|
href="https://github.com/upscayl/upscayl/wiki/"
|
|
|
|
target="_blank">
|
|
|
|
Read Wiki Guide
|
|
|
|
</a>
|
|
|
|
<DonateButton />
|
|
|
|
</div>
|
2023-07-22 13:07:53 +02:00
|
|
|
|
2023-07-23 11:07:18 +02:00
|
|
|
<LogArea
|
|
|
|
copyOnClickHandler={copyOnClickHandler}
|
|
|
|
isCopied={isCopied}
|
|
|
|
logData={logData}
|
|
|
|
/>
|
|
|
|
|
2023-07-22 13:07:53 +02:00
|
|
|
{/* THEME SELECTOR */}
|
|
|
|
<ThemeSelect />
|
|
|
|
|
2023-07-23 11:07:18 +02:00
|
|
|
{/* IMAGE FORMAT BUTTONS */}
|
|
|
|
<ImageFormatSelect
|
|
|
|
batchMode={batchMode}
|
|
|
|
saveImageAs={saveImageAs}
|
|
|
|
setExportType={setExportType}
|
|
|
|
/>
|
|
|
|
|
2023-09-18 20:30:43 +02:00
|
|
|
<ProcessImageToggle
|
|
|
|
noImageProcessing={noImageProcessing}
|
|
|
|
setNoImageProcessing={setNoImageProcessing}
|
2023-07-23 11:07:18 +02:00
|
|
|
/>
|
|
|
|
|
2023-09-18 20:30:43 +02:00
|
|
|
{!noImageProcessing && (
|
|
|
|
<>
|
|
|
|
{/* IMAGE SCALE */}
|
|
|
|
<ImageScaleSelect scale={scale} setScale={setScale} />
|
|
|
|
|
|
|
|
<CompressionInput
|
|
|
|
compression={compression}
|
|
|
|
handleCompressionChange={handleCompressionChange}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
|
2023-07-22 13:07:53 +02:00
|
|
|
<SaveOutputFolderToggle
|
|
|
|
rememberOutputFolder={rememberOutputFolder}
|
|
|
|
setRememberOutputFolder={setRememberOutputFolder}
|
|
|
|
/>
|
|
|
|
|
2023-09-18 20:30:43 +02:00
|
|
|
<OverwriteToggle overwrite={overwrite} setOverwrite={setOverwrite} />
|
2023-08-10 12:17:35 +02:00
|
|
|
|
2023-07-22 13:07:53 +02:00
|
|
|
{/* GPU ID INPUT */}
|
|
|
|
<GpuIdInput gpuId={gpuId} handleGpuIdChange={handleGpuIdChange} />
|
|
|
|
|
|
|
|
{/* CUSTOM MODEL */}
|
|
|
|
<CustomModelsFolderSelect
|
|
|
|
customModelsPath={customModelsPath}
|
|
|
|
setCustomModelsPath={setCustomModelsPath}
|
|
|
|
/>
|
2023-09-03 11:16:48 +02:00
|
|
|
|
|
|
|
{/* RESET SETTINGS */}
|
|
|
|
<ResetSettings />
|
|
|
|
|
|
|
|
<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={() => {
|
|
|
|
setShow(true);
|
|
|
|
}}>
|
|
|
|
Introducing Upscayl Cloud
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<UpscaylCloudModal
|
|
|
|
show={show}
|
|
|
|
setShow={setShow}
|
|
|
|
setDontShowCloudModal={setDontShowCloudModal}
|
|
|
|
/>
|
2023-07-22 13:07:53 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default SettingsTab;
|