mirror of
https://github.com/upscayl/upscayl.git
synced 2025-02-15 10:22:37 +01:00
Update code
This commit is contained in:
parent
8eebe9955a
commit
5e5f60728b
17
renderer/components/hooks/use-custom-models.ts
Normal file
17
renderer/components/hooks/use-custom-models.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import ELECTRON_COMMANDS from "@common/commands";
|
||||||
|
import { useEffect } from "react";
|
||||||
|
import useLog from "./useLog";
|
||||||
|
|
||||||
|
export const initCustomModels = () => {
|
||||||
|
const { logit } = useLog();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const customModelsPath = JSON.parse(
|
||||||
|
localStorage.getItem("customModelsPath"),
|
||||||
|
);
|
||||||
|
if (customModelsPath !== null) {
|
||||||
|
window.electron.send(ELECTRON_COMMANDS.GET_MODELS_LIST, customModelsPath);
|
||||||
|
logit("🎯 GET_MODELS_LIST: ", customModelsPath);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
};
|
@ -1,8 +1,5 @@
|
|||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
import { useAtomValue } from "jotai";
|
|
||||||
import { translationAtom } from "@/atoms/translations-atom";
|
|
||||||
import ELECTRON_COMMANDS from "@common/commands";
|
import ELECTRON_COMMANDS from "@common/commands";
|
||||||
import useLog from "./useLog";
|
|
||||||
|
|
||||||
const useElectron = ({
|
const useElectron = ({
|
||||||
command,
|
command,
|
||||||
|
@ -1,24 +1,14 @@
|
|||||||
import useLog from "../hooks/useLog";
|
import useLog from "../hooks/useLog";
|
||||||
import { useState, useCallback, useMemo, useRef } from "react";
|
import { useState, useCallback, useMemo, useRef } from "react";
|
||||||
import ELECTRON_COMMANDS from "../../../common/commands";
|
import ELECTRON_COMMANDS from "../../../common/commands";
|
||||||
import { useAtom, useAtomValue, useSetAtom } from "jotai";
|
import { useAtomValue, useSetAtom } from "jotai";
|
||||||
import { logAtom } from "../../atoms/logAtom";
|
|
||||||
import { modelsListAtom } from "../../atoms/modelsListAtom";
|
|
||||||
import {
|
import {
|
||||||
batchModeAtom,
|
batchModeAtom,
|
||||||
lensSizeAtom,
|
lensSizeAtom,
|
||||||
compressionAtom,
|
|
||||||
dontShowCloudModalAtom,
|
|
||||||
noImageProcessingAtom,
|
|
||||||
savedOutputPathAtom,
|
savedOutputPathAtom,
|
||||||
progressAtom,
|
progressAtom,
|
||||||
scaleAtom,
|
|
||||||
viewTypeAtom,
|
viewTypeAtom,
|
||||||
rememberOutputFolderAtom,
|
rememberOutputFolderAtom,
|
||||||
customWidthAtom,
|
|
||||||
useCustomWidthAtom,
|
|
||||||
tileSizeAtom,
|
|
||||||
showSidebarAtom,
|
|
||||||
} from "../../atoms/userSettingsAtom";
|
} from "../../atoms/userSettingsAtom";
|
||||||
import { useToast } from "@/components/ui/use-toast";
|
import { useToast } from "@/components/ui/use-toast";
|
||||||
import { sanitizePath } from "@common/sanitize-path";
|
import { sanitizePath } from "@common/sanitize-path";
|
||||||
@ -45,10 +35,28 @@ const MainContent = ({
|
|||||||
batchFolderPath,
|
batchFolderPath,
|
||||||
doubleUpscaylCounter,
|
doubleUpscaylCounter,
|
||||||
setDimensions,
|
setDimensions,
|
||||||
|
}: {
|
||||||
|
imagePath: string;
|
||||||
|
resetImagePaths: () => void;
|
||||||
|
upscaledBatchFolderPath: string;
|
||||||
|
setImagePath: React.Dispatch<React.SetStateAction<string>>;
|
||||||
|
validateImagePath: (path: string) => void;
|
||||||
|
selectFolderHandler: () => void;
|
||||||
|
selectImageHandler: () => void;
|
||||||
|
upscaledImagePath: string;
|
||||||
|
batchFolderPath: string;
|
||||||
|
doubleUpscaylCounter: number;
|
||||||
|
setDimensions: React.Dispatch<
|
||||||
|
React.SetStateAction<{
|
||||||
|
width: number;
|
||||||
|
height: number;
|
||||||
|
}>
|
||||||
|
>;
|
||||||
}) => {
|
}) => {
|
||||||
const t = useAtomValue(translationAtom);
|
const t = useAtomValue(translationAtom);
|
||||||
const { logit } = useLog();
|
const { logit } = useLog();
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
|
const version = useUpscaylVersion();
|
||||||
|
|
||||||
const upscaledImageRef = useRef<HTMLImageElement>(null);
|
const upscaledImageRef = useRef<HTMLImageElement>(null);
|
||||||
|
|
||||||
@ -63,7 +71,6 @@ const MainContent = ({
|
|||||||
const lensSize = useAtomValue(lensSizeAtom);
|
const lensSize = useAtomValue(lensSizeAtom);
|
||||||
const rememberOutputFolder = useAtomValue(rememberOutputFolderAtom);
|
const rememberOutputFolder = useAtomValue(rememberOutputFolderAtom);
|
||||||
const [zoomAmount, setZoomAmount] = useState("100");
|
const [zoomAmount, setZoomAmount] = useState("100");
|
||||||
const version = useUpscaylVersion();
|
|
||||||
|
|
||||||
const sanitizedUpscaledImagePath = useMemo(
|
const sanitizedUpscaledImagePath = useMemo(
|
||||||
() => sanitizePath(upscaledImagePath),
|
() => sanitizePath(upscaledImagePath),
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useAtom, useAtomValue } from "jotai";
|
import { useAtom, useAtomValue, useSetAtom } from "jotai";
|
||||||
import {
|
import {
|
||||||
batchModeAtom,
|
batchModeAtom,
|
||||||
lensSizeAtom,
|
|
||||||
compressionAtom,
|
compressionAtom,
|
||||||
dontShowCloudModalAtom,
|
dontShowCloudModalAtom,
|
||||||
noImageProcessingAtom,
|
noImageProcessingAtom,
|
||||||
@ -11,8 +10,6 @@ import {
|
|||||||
overwriteAtom,
|
overwriteAtom,
|
||||||
progressAtom,
|
progressAtom,
|
||||||
scaleAtom,
|
scaleAtom,
|
||||||
viewTypeAtom,
|
|
||||||
rememberOutputFolderAtom,
|
|
||||||
customWidthAtom,
|
customWidthAtom,
|
||||||
useCustomWidthAtom,
|
useCustomWidthAtom,
|
||||||
tileSizeAtom,
|
tileSizeAtom,
|
||||||
@ -37,11 +34,10 @@ import Header from "../Header";
|
|||||||
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react";
|
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { logAtom } from "@/atoms/logAtom";
|
import { logAtom } from "@/atoms/logAtom";
|
||||||
import { modelsListAtom } from "@/atoms/modelsListAtom";
|
|
||||||
import ELECTRON_COMMANDS from "@common/commands";
|
import ELECTRON_COMMANDS from "@common/commands";
|
||||||
|
import useUpscaylVersion from "../hooks/use-upscayl-version";
|
||||||
|
|
||||||
const Sidebar = ({
|
const Sidebar = ({
|
||||||
upscaledImagePath,
|
|
||||||
setUpscaledImagePath,
|
setUpscaledImagePath,
|
||||||
batchFolderPath,
|
batchFolderPath,
|
||||||
setUpscaledBatchFolderPath,
|
setUpscaledBatchFolderPath,
|
||||||
@ -50,7 +46,6 @@ const Sidebar = ({
|
|||||||
selectImageHandler,
|
selectImageHandler,
|
||||||
selectFolderHandler,
|
selectFolderHandler,
|
||||||
}: {
|
}: {
|
||||||
upscaledImagePath: string;
|
|
||||||
setUpscaledImagePath: React.Dispatch<React.SetStateAction<string>>;
|
setUpscaledImagePath: React.Dispatch<React.SetStateAction<string>>;
|
||||||
batchFolderPath: string;
|
batchFolderPath: string;
|
||||||
setUpscaledBatchFolderPath: React.Dispatch<React.SetStateAction<string>>;
|
setUpscaledBatchFolderPath: React.Dispatch<React.SetStateAction<string>>;
|
||||||
@ -65,11 +60,12 @@ const Sidebar = ({
|
|||||||
const t = useAtomValue(translationAtom);
|
const t = useAtomValue(translationAtom);
|
||||||
const { logit } = useLog();
|
const { logit } = useLog();
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
|
const version = useUpscaylVersion();
|
||||||
|
|
||||||
// LOCAL STATES
|
// LOCAL STATES
|
||||||
|
// TODO: Add electron handler for os
|
||||||
const [os, setOs] = useState<"linux" | "mac" | "win" | undefined>(undefined);
|
const [os, setOs] = useState<"linux" | "mac" | "win" | undefined>(undefined);
|
||||||
const [model, setModel] = useState("realesrgan-x4plus");
|
const [model, setModel] = useState("realesrgan-x4plus");
|
||||||
const [version, setVersion] = useState("");
|
|
||||||
const [doubleUpscayl, setDoubleUpscayl] = useState(false);
|
const [doubleUpscayl, setDoubleUpscayl] = useState(false);
|
||||||
const overwrite = useAtomValue(overwriteAtom);
|
const overwrite = useAtomValue(overwriteAtom);
|
||||||
const [gpuId, setGpuId] = useState("");
|
const [gpuId, setGpuId] = useState("");
|
||||||
@ -79,22 +75,16 @@ const Sidebar = ({
|
|||||||
const [showCloudModal, setShowCloudModal] = useState(false);
|
const [showCloudModal, setShowCloudModal] = useState(false);
|
||||||
|
|
||||||
// ATOMIC STATES
|
// ATOMIC STATES
|
||||||
const [outputPath, setOutputPath] = useAtom(savedOutputPathAtom);
|
const outputPath = useAtomValue(savedOutputPathAtom);
|
||||||
const [compression, setCompression] = useAtom(compressionAtom);
|
const [compression, setCompression] = useAtom(compressionAtom);
|
||||||
const [progress, setProgress] = useAtom(progressAtom);
|
const setProgress = useSetAtom(progressAtom);
|
||||||
const [batchMode, setBatchMode] = useAtom(batchModeAtom);
|
const [batchMode, setBatchMode] = useAtom(batchModeAtom);
|
||||||
const [logData, setLogData] = useAtom(logAtom);
|
const logData = useAtomValue(logAtom);
|
||||||
const [modelOptions, setModelOptions] = useAtom(modelsListAtom);
|
|
||||||
const [scale] = useAtom(scaleAtom);
|
const [scale] = useAtom(scaleAtom);
|
||||||
const [dontShowCloudModal, setDontShowCloudModal] = useAtom(
|
const setDontShowCloudModal = useSetAtom(dontShowCloudModalAtom);
|
||||||
dontShowCloudModalAtom,
|
|
||||||
);
|
|
||||||
const noImageProcessing = useAtomValue(noImageProcessingAtom);
|
const noImageProcessing = useAtomValue(noImageProcessingAtom);
|
||||||
const [news, setNews] = useAtom(newsAtom);
|
const [news, setNews] = useAtom(newsAtom);
|
||||||
const [showNewsModal, setShowNewsModal] = useAtom(showNewsModalAtom);
|
const [showNewsModal, setShowNewsModal] = useAtom(showNewsModalAtom);
|
||||||
const viewType = useAtomValue(viewTypeAtom);
|
|
||||||
const lensSize = useAtomValue(lensSizeAtom);
|
|
||||||
const rememberOutputFolder = useAtomValue(rememberOutputFolderAtom);
|
|
||||||
const customWidth = useAtomValue(customWidthAtom);
|
const customWidth = useAtomValue(customWidthAtom);
|
||||||
const useCustomWidth = useAtomValue(useCustomWidthAtom);
|
const useCustomWidth = useAtomValue(useCustomWidthAtom);
|
||||||
const tileSize = useAtomValue(tileSizeAtom);
|
const tileSize = useAtomValue(tileSizeAtom);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import ELECTRON_COMMANDS from "../../common/commands";
|
import ELECTRON_COMMANDS from "../../common/commands";
|
||||||
import { useAtom, useAtomValue } from "jotai";
|
import { useAtom, useAtomValue, useSetAtom } from "jotai";
|
||||||
import { modelsListAtom } from "../atoms/modelsListAtom";
|
import { modelsListAtom } from "../atoms/modelsListAtom";
|
||||||
import {
|
import {
|
||||||
batchModeAtom,
|
batchModeAtom,
|
||||||
@ -21,32 +21,38 @@ import MainContent from "@/components/main-content";
|
|||||||
import getDirectoryFromPath from "@common/get-directory-from-path";
|
import getDirectoryFromPath from "@common/get-directory-from-path";
|
||||||
import { FEATURE_FLAGS } from "@common/feature-flags";
|
import { FEATURE_FLAGS } from "@common/feature-flags";
|
||||||
import { VALID_IMAGE_FORMATS } from "@/lib/valid-formats";
|
import { VALID_IMAGE_FORMATS } from "@/lib/valid-formats";
|
||||||
|
import { initCustomModels } from "@/components/hooks/use-custom-models";
|
||||||
|
|
||||||
const Home = () => {
|
const Home = () => {
|
||||||
const t = useAtomValue(translationAtom);
|
const t = useAtomValue(translationAtom);
|
||||||
const { logit } = useLog();
|
const { logit } = useLog();
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
|
|
||||||
// * SHARED HOOKS AND STATES
|
initCustomModels();
|
||||||
|
|
||||||
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
|
|
||||||
const [imagePath, setImagePath] = useState("");
|
const [imagePath, setImagePath] = useState("");
|
||||||
const rememberOutputFolder = useAtomValue(rememberOutputFolderAtom);
|
const [upscaledImagePath, setUpscaledImagePath] = useState("");
|
||||||
const [outputPath, setOutputPath] = useAtom(savedOutputPathAtom);
|
|
||||||
const [dimensions, setDimensions] = useState({
|
const [dimensions, setDimensions] = useState({
|
||||||
width: null,
|
width: null,
|
||||||
height: null,
|
height: null,
|
||||||
});
|
});
|
||||||
const [progress, setProgress] = useAtom(progressAtom);
|
const setOutputPath = useSetAtom(savedOutputPathAtom);
|
||||||
const [upscaledImagePath, setUpscaledImagePath] = useState("");
|
const rememberOutputFolder = useAtomValue(rememberOutputFolderAtom);
|
||||||
|
|
||||||
|
const batchMode = useAtomValue(batchModeAtom);
|
||||||
const [batchFolderPath, setBatchFolderPath] = useState("");
|
const [batchFolderPath, setBatchFolderPath] = useState("");
|
||||||
const [upscaledBatchFolderPath, setUpscaledBatchFolderPath] = useState("");
|
const [upscaledBatchFolderPath, setUpscaledBatchFolderPath] = useState("");
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
|
||||||
|
const setProgress = useSetAtom(progressAtom);
|
||||||
const [doubleUpscaylCounter, setDoubleUpscaylCounter] = useState(0);
|
const [doubleUpscaylCounter, setDoubleUpscaylCounter] = useState(0);
|
||||||
|
|
||||||
const [modelOptions, setModelOptions] = useAtom(modelsListAtom);
|
const [modelOptions, setModelOptions] = useAtom(modelsListAtom);
|
||||||
|
|
||||||
const [news, setNews] = useAtom(newsAtom);
|
const [news, setNews] = useAtom(newsAtom);
|
||||||
const [showNewsModal, setShowNewsModal] = useAtom(showNewsModalAtom);
|
const [showNewsModal, setShowNewsModal] = useAtom(showNewsModalAtom);
|
||||||
const [batchMode, setBatchMode] = useAtom(batchModeAtom);
|
|
||||||
|
|
||||||
// * SHARED FUNCTIONS
|
|
||||||
const selectImageHandler = async () => {
|
const selectImageHandler = async () => {
|
||||||
resetImagePaths();
|
resetImagePaths();
|
||||||
var path = await window.electron.invoke(ELECTRON_COMMANDS.SELECT_FILE);
|
var path = await window.electron.invoke(ELECTRON_COMMANDS.SELECT_FILE);
|
||||||
@ -62,22 +68,7 @@ const Home = () => {
|
|||||||
}
|
}
|
||||||
validateImagePath(path);
|
validateImagePath(path);
|
||||||
};
|
};
|
||||||
const validateImagePath = (path: string) => {
|
|
||||||
if (path.length > 0) {
|
|
||||||
logit("🖼 imagePath: ", path);
|
|
||||||
const extension = path.toLocaleLowerCase().split(".").pop();
|
|
||||||
logit("🔤 Extension: ", extension);
|
|
||||||
if (!VALID_IMAGE_FORMATS.includes(extension.toLowerCase())) {
|
|
||||||
toast({
|
|
||||||
title: t("ERRORS.INVALID_IMAGE_ERROR.TITLE"),
|
|
||||||
description: t("ERRORS.INVALID_IMAGE_ERROR.DESCRIPTION"),
|
|
||||||
});
|
|
||||||
resetImagePaths();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
resetImagePaths();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
const selectFolderHandler = async () => {
|
const selectFolderHandler = async () => {
|
||||||
resetImagePaths();
|
resetImagePaths();
|
||||||
var path = await window.electron.invoke(ELECTRON_COMMANDS.SELECT_FOLDER);
|
var path = await window.electron.invoke(ELECTRON_COMMANDS.SELECT_FOLDER);
|
||||||
@ -96,6 +87,23 @@ const Home = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const validateImagePath = (path: string) => {
|
||||||
|
if (path.length > 0) {
|
||||||
|
logit("🖼 imagePath: ", path);
|
||||||
|
const extension = path.toLocaleLowerCase().split(".").pop();
|
||||||
|
logit("🔤 Extension: ", extension);
|
||||||
|
if (!VALID_IMAGE_FORMATS.includes(extension.toLowerCase())) {
|
||||||
|
toast({
|
||||||
|
title: t("ERRORS.INVALID_IMAGE_ERROR.TITLE"),
|
||||||
|
description: t("ERRORS.INVALID_IMAGE_ERROR.DESCRIPTION"),
|
||||||
|
});
|
||||||
|
resetImagePaths();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
resetImagePaths();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// ELECTRON EVENT LISTENERS
|
// ELECTRON EVENT LISTENERS
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleErrors = (data: string) => {
|
const handleErrors = (data: string) => {
|
||||||
@ -271,17 +279,6 @@ const Home = () => {
|
|||||||
);
|
);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// FETCH CUSTOM MODELS FROM CUSTOM MODELS PATH
|
|
||||||
useEffect(() => {
|
|
||||||
const customModelsPath = JSON.parse(
|
|
||||||
localStorage.getItem("customModelsPath"),
|
|
||||||
);
|
|
||||||
if (customModelsPath !== null) {
|
|
||||||
window.electron.send(ELECTRON_COMMANDS.GET_MODELS_LIST, customModelsPath);
|
|
||||||
logit("🎯 GET_MODELS_LIST: ", customModelsPath);
|
|
||||||
}
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
// FETCH NEWS
|
// FETCH NEWS
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// TODO: ADD AN ABOUT TAB
|
// TODO: ADD AN ABOUT TAB
|
||||||
@ -342,10 +339,6 @@ const Home = () => {
|
|||||||
setUpscaledBatchFolderPath("");
|
setUpscaledBatchFolderPath("");
|
||||||
};
|
};
|
||||||
|
|
||||||
// UTILS
|
|
||||||
|
|
||||||
// HANDLERS
|
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return (
|
return (
|
||||||
<Logo className="absolute left-1/2 top-1/2 w-36 -translate-x-1/2 -translate-y-1/2 animate-pulse" />
|
<Logo className="absolute left-1/2 top-1/2 w-36 -translate-x-1/2 -translate-y-1/2 animate-pulse" />
|
||||||
@ -357,7 +350,6 @@ const Home = () => {
|
|||||||
<Sidebar
|
<Sidebar
|
||||||
imagePath={imagePath}
|
imagePath={imagePath}
|
||||||
dimensions={dimensions}
|
dimensions={dimensions}
|
||||||
upscaledImagePath={upscaledImagePath}
|
|
||||||
setUpscaledImagePath={setUpscaledImagePath}
|
setUpscaledImagePath={setUpscaledImagePath}
|
||||||
batchFolderPath={batchFolderPath}
|
batchFolderPath={batchFolderPath}
|
||||||
setUpscaledBatchFolderPath={setUpscaledBatchFolderPath}
|
setUpscaledBatchFolderPath={setUpscaledBatchFolderPath}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user