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";
|
2024-04-24 21:29:51 +02:00
|
|
|
import { customModelsPathAtom, 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-10-25 13:44:22 +02:00
|
|
|
import { featureFlags } from "@common/feature-flags";
|
2024-01-16 08:33:43 +01:00
|
|
|
import TurnOffNotificationsToggle from "./TurnOffNotificationsToggle";
|
2024-04-18 20:45:12 +02:00
|
|
|
import { cn } from "@/lib/utils";
|
2024-04-20 17:44:42 +02:00
|
|
|
import { CustomResolutionInput } from "./CustomResolutionInput";
|
2024-04-24 21:40:48 +02:00
|
|
|
import { TileSizeInput } from "./TileSizeInput";
|
2024-08-31 15:39:05 +02:00
|
|
|
import LanguageSwitcher from "./language-switcher";
|
2024-09-01 14:01:45 +02:00
|
|
|
import { translationAtom } from "@/atoms/translations-atom";
|
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-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-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 [isCopied, setIsCopied] = useState(false);
|
|
|
|
|
|
|
|
const [customModelsPath, setCustomModelsPath] = useAtom(customModelsPathAtom);
|
|
|
|
const modelOptions = useAtomValue(modelsListAtom);
|
|
|
|
const [scale, setScale] = useAtom(scaleAtom);
|
2024-04-18 20:45:12 +02:00
|
|
|
const [enableScrollbar, setEnableScrollbar] = useState(true);
|
|
|
|
const [timeoutId, setTimeoutId] = useState(null);
|
2024-09-01 14:01:45 +02:00
|
|
|
const t = useAtomValue(translationAtom);
|
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: ",
|
2024-02-08 15:57:35 +01:00
|
|
|
currentlySavedImageFormat,
|
2023-07-22 13:07:53 +02:00
|
|
|
);
|
|
|
|
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 {
|
2023-09-25 05:39:21 +02:00
|
|
|
let currentlySavedModel = JSON.parse(
|
2024-02-08 15:57:35 +01:00
|
|
|
localStorage.getItem("model"),
|
2023-07-22 13:07:53 +02:00
|
|
|
) as (typeof modelOptions)[0];
|
2023-09-25 05:39:21 +02:00
|
|
|
if (
|
|
|
|
modelOptions.find(
|
2024-02-08 15:57:35 +01:00
|
|
|
(model) => model.value === currentlySavedModel.value,
|
2023-09-25 05:39:21 +02:00
|
|
|
) === undefined
|
|
|
|
) {
|
|
|
|
localStorage.setItem("model", JSON.stringify(modelOptions[0]));
|
|
|
|
logit("🔀 Setting model to", modelOptions[0].value);
|
|
|
|
currentlySavedModel = modelOptions[0];
|
|
|
|
}
|
2023-07-22 13:07:53 +02:00
|
|
|
setCurrentModel(currentlySavedModel);
|
|
|
|
setModel(currentlySavedModel.value);
|
|
|
|
logit(
|
2023-09-13 16:07:45 +02:00
|
|
|
"⚙️ Getting model from localStorage: ",
|
2024-02-08 15:57:35 +01:00
|
|
|
JSON.stringify(currentlySavedModel),
|
2023-07-22 13:07:53 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
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-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);
|
|
|
|
};
|
|
|
|
|
2024-01-31 12:20:46 +01:00
|
|
|
const upscaylVersion = navigator?.userAgent?.match(
|
2024-02-08 15:57:35 +01:00
|
|
|
/Upscayl\/([\d\.]+\d+)/,
|
2024-01-31 12:20:46 +01:00
|
|
|
)[1];
|
|
|
|
|
2024-04-18 20:45:12 +02:00
|
|
|
function disableScrolling() {
|
|
|
|
if (timeoutId !== null) {
|
|
|
|
clearTimeout(timeoutId);
|
|
|
|
}
|
|
|
|
|
|
|
|
setTimeoutId(
|
|
|
|
setTimeout(function () {
|
|
|
|
setEnableScrollbar(false);
|
|
|
|
}, 1000),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function enableScrolling() {
|
|
|
|
if (timeoutId !== null) {
|
|
|
|
clearTimeout(timeoutId);
|
|
|
|
}
|
|
|
|
|
|
|
|
setEnableScrollbar(true);
|
|
|
|
}
|
|
|
|
|
2023-07-22 13:07:53 +02:00
|
|
|
return (
|
2024-04-18 20:45:12 +02:00
|
|
|
<div
|
|
|
|
className={cn(
|
|
|
|
"animate-step-in animate z-50 flex h-screen flex-col gap-7 overflow-y-auto overflow-x-hidden p-5",
|
|
|
|
enableScrollbar ? "" : "hide-scrollbar",
|
|
|
|
)}
|
|
|
|
onScroll={() => {
|
|
|
|
if (enableScrollbar) disableScrolling();
|
|
|
|
}}
|
|
|
|
onWheel={() => {
|
|
|
|
enableScrolling();
|
|
|
|
}}
|
|
|
|
>
|
2024-01-31 12:20:46 +01:00
|
|
|
<div className="flex flex-col gap-2 text-sm font-medium uppercase">
|
2024-09-03 09:34:58 +02:00
|
|
|
<p>{t("SETTINGS.SUPPORT.TITLE")}</p>
|
2023-07-23 08:32:22 +02:00
|
|
|
<a
|
2024-02-08 15:57:35 +01:00
|
|
|
className="btn btn-primary"
|
2024-04-24 22:28:03 +02:00
|
|
|
href="https://docs.upscayl.org/"
|
2024-02-08 15:57:35 +01:00
|
|
|
target="_blank"
|
|
|
|
>
|
2024-09-03 09:34:58 +02:00
|
|
|
{t("SETTINGS.SUPPORT.DOCS_BUTTON_TITLE")}
|
2023-07-23 08:32:22 +02:00
|
|
|
</a>
|
2024-01-15 18:52:16 +01:00
|
|
|
{featureFlags.APP_STORE_BUILD && (
|
|
|
|
<a
|
2024-02-08 15:57:35 +01:00
|
|
|
className="btn btn-primary"
|
2024-01-31 12:20:46 +01:00
|
|
|
href={`mailto:upscayl@gmail.com?subject=Upscayl%20Issue%3A%20%3CIssue%20name%20here%3E&body=Device%20Name%3A%20%3CYOUR%20DEVICE%20MODEL%3E%0AOperating%20System%3A%20%3CYOUR%20OPERATING%20SYSTEM%20VERSION%3E%0AUpscayl%20Version%3A%20${upscaylVersion}%0A%0AHi%2C%20I'm%20having%20an%20issue%20with%20Upscayl.%20%3CDESCRIBE%20ISSUE%20HERE%3E`}
|
2024-02-08 15:57:35 +01:00
|
|
|
target="_blank"
|
|
|
|
>
|
2024-09-03 09:34:58 +02:00
|
|
|
{t("SETTINGS.SUPPORT.EMAIL_BUTTON_TITLE")}
|
2024-01-15 18:52:16 +01:00
|
|
|
</a>
|
|
|
|
)}
|
2023-10-25 13:44:22 +02:00
|
|
|
{!featureFlags.APP_STORE_BUILD && <DonateButton />}
|
2023-07-23 08:32:22 +02:00
|
|
|
</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 />
|
|
|
|
|
2024-08-31 15:39:05 +02:00
|
|
|
<LanguageSwitcher />
|
|
|
|
|
2023-07-23 11:07:18 +02:00
|
|
|
{/* IMAGE FORMAT BUTTONS */}
|
|
|
|
<ImageFormatSelect
|
|
|
|
batchMode={batchMode}
|
|
|
|
saveImageAs={saveImageAs}
|
|
|
|
setExportType={setExportType}
|
|
|
|
/>
|
|
|
|
|
2024-04-09 20:21:54 +02:00
|
|
|
{/* IMAGE SCALE */}
|
|
|
|
<ImageScaleSelect scale={scale} setScale={setScale} />
|
2024-02-08 15:57:35 +01:00
|
|
|
|
2024-04-20 17:44:42 +02:00
|
|
|
<CustomResolutionInput />
|
|
|
|
|
2024-04-09 20:21:54 +02:00
|
|
|
<CompressionInput
|
|
|
|
compression={compression}
|
|
|
|
handleCompressionChange={handleCompressionChange}
|
|
|
|
/>
|
2023-09-18 20:30:43 +02:00
|
|
|
|
2024-02-14 07:32:52 +01:00
|
|
|
<SaveOutputFolderToggle />
|
2023-07-22 13:07:53 +02:00
|
|
|
|
2024-01-15 10:07:22 +01:00
|
|
|
<OverwriteToggle />
|
2024-01-16 08:33:43 +01:00
|
|
|
<TurnOffNotificationsToggle />
|
2023-08-10 12:17:35 +02:00
|
|
|
|
2023-07-22 13:07:53 +02:00
|
|
|
{/* GPU ID INPUT */}
|
|
|
|
<GpuIdInput gpuId={gpuId} handleGpuIdChange={handleGpuIdChange} />
|
|
|
|
|
2024-04-24 21:40:48 +02:00
|
|
|
<TileSizeInput />
|
|
|
|
|
2023-07-22 13:07:53 +02:00
|
|
|
{/* CUSTOM MODEL */}
|
|
|
|
<CustomModelsFolderSelect
|
|
|
|
customModelsPath={customModelsPath}
|
|
|
|
setCustomModelsPath={setCustomModelsPath}
|
|
|
|
/>
|
2023-09-03 11:16:48 +02:00
|
|
|
|
|
|
|
{/* RESET SETTINGS */}
|
|
|
|
<ResetSettings />
|
|
|
|
|
2023-11-02 16:03:21 +01:00
|
|
|
{featureFlags.SHOW_UPSCAYL_CLOUD_INFO && (
|
|
|
|
<>
|
|
|
|
<button
|
2024-04-20 17:44:42 +02:00
|
|
|
className="mx-5 mb-5 animate-pulse rounded-btn bg-success p-1 text-sm text-slate-50 shadow-lg shadow-success/40"
|
2023-11-02 16:03:21 +01:00
|
|
|
onClick={() => {
|
|
|
|
setShow(true);
|
2024-02-08 15:57:35 +01:00
|
|
|
}}
|
|
|
|
>
|
2024-09-03 09:34:58 +02:00
|
|
|
{t("INTRO")}
|
2023-11-02 16:03:21 +01:00
|
|
|
</button>
|
2023-09-03 11:16:48 +02:00
|
|
|
|
2023-11-02 16:03:21 +01:00
|
|
|
<UpscaylCloudModal
|
|
|
|
show={show}
|
|
|
|
setShow={setShow}
|
|
|
|
setDontShowCloudModal={setDontShowCloudModal}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
)}
|
2023-07-22 13:07:53 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default SettingsTab;
|