1
0
mirror of https://github.com/upscayl/upscayl.git synced 2024-11-28 01:10:52 +01:00

fixed remember output toggle

This commit is contained in:
TGS963 2023-04-27 23:48:44 +05:30
parent 68ba34b9d6
commit 6673c4f08e
3 changed files with 52 additions and 29 deletions

View File

@ -33,7 +33,7 @@ import commands from "./commands";
log.initialize({ preload: true }); log.initialize({ preload: true });
function escapeRegExp(string) { function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); // $& means the whole matched string
} }
// Prepare the renderer once the app is ready // Prepare the renderer once the app is ready
@ -164,7 +164,10 @@ ipcMain.handle(commands.SELECT_FILE, async () => {
} else { } else {
logit("Selected File Path: ", filePaths[0]); logit("Selected File Path: ", filePaths[0]);
const platform = getPlatform(); const platform = getPlatform();
imagePath = platform === "win" ? filePaths[0].replace(new RegExp(escapeRegExp('\\'), 'g'), '\\\\') : filePaths[0]; imagePath =
platform === "win"
? filePaths[0].replace(new RegExp(escapeRegExp("\\"), "g"), "\\\\")
: filePaths[0];
mainWindow.webContents mainWindow.webContents
.executeJavaScript( .executeJavaScript(
`localStorage.setItem("lastImagePath", "${imagePath}");`, `localStorage.setItem("lastImagePath", "${imagePath}");`,
@ -219,15 +222,23 @@ ipcMain.handle(commands.SELECT_FOLDER, async (event, message) => {
} else { } else {
logit("Selected Folder Path: ", folderPaths[0]); logit("Selected Folder Path: ", folderPaths[0]);
const platform = getPlatform(); const platform = getPlatform();
folderPath = platform === "win" ? folderPaths[0].replace(new RegExp(escapeRegExp('\\'), 'g'), '\\\\') : folderPaths[0]; folderPath =
platform === "win"
? folderPaths[0].replace(new RegExp(escapeRegExp("\\"), "g"), "\\\\")
: folderPaths[0];
mainWindow.webContents mainWindow.webContents
.executeJavaScript( .executeJavaScript('localStorage.getItem("rememberOutputFolder");', true)
`localStorage.setItem("lastFolderPath", "${folderPath}");`,
true
)
.then(() => { .then(() => {
logit(`Saved Last Folder Path (${folderPath}) to Local Storage`); mainWindow.webContents
.executeJavaScript(
`localStorage.setItem("lastFolderPath", "${folderPath}");`,
true
)
.then(() => {
logit(`Saved Last Folder Path (${folderPath}) to Local Storage`);
});
}); });
return folderPaths[0]; return folderPaths[0];
} }
}); });
@ -447,7 +458,7 @@ ipcMain.on(commands.UPSCAYL, async (event, payload) => {
const gpuId = payload.gpuId as string; const gpuId = payload.gpuId as string;
const saveImageAs = payload.saveImageAs as string; const saveImageAs = payload.saveImageAs as string;
let inputDir = (payload.imagePath.match(/(.*)[\/\\]/)[1] || "") as string; let inputDir = (payload.imagePath.match(/(.*)[\/\\]/)[1] || "") as string;
let outputDir = folderPath || payload.outputPath as string; let outputDir = folderPath || (payload.outputPath as string);
const isDefaultModel = defaultModels.includes(model); const isDefaultModel = defaultModels.includes(model);

View File

@ -2,16 +2,14 @@ import React, { useEffect, useState } from "react";
import { themeChange } from "theme-change"; import { themeChange } from "theme-change";
import commands from "../../electron/commands"; import commands from "../../electron/commands";
import { useAtom } from "jotai"; import { useAtom } from "jotai";
import { import { customModelsPathAtom, scaleAtom } from "../atoms/userSettingsAtom";
customModelsPathAtom,
rememberOutputFolderAtom,
scaleAtom,
} from "../atoms/userSettingsAtom";
import { modelsListAtom } from "../atoms/modelsListAtom"; import { modelsListAtom } from "../atoms/modelsListAtom";
interface IProps { interface IProps {
batchMode: boolean; batchMode: boolean;
setBatchMode: React.Dispatch<React.SetStateAction<boolean>>; setBatchMode: React.Dispatch<React.SetStateAction<boolean>>;
rememberOutputFolder: boolean;
setRememberOutputFolder: React.Dispatch<React.SetStateAction<boolean>>;
imagePath: string; imagePath: string;
setModel: React.Dispatch<React.SetStateAction<string>>; setModel: React.Dispatch<React.SetStateAction<string>>;
saveImageAs: string; saveImageAs: string;
@ -24,6 +22,8 @@ interface IProps {
function SettingsTab({ function SettingsTab({
batchMode, batchMode,
setBatchMode, setBatchMode,
rememberOutputFolder,
setRememberOutputFolder,
imagePath, imagePath,
setModel, setModel,
gpuId, gpuId,
@ -45,9 +45,6 @@ function SettingsTab({
const [customModelsPath, setCustomModelsPath] = useAtom(customModelsPathAtom); const [customModelsPath, setCustomModelsPath] = useAtom(customModelsPathAtom);
const [modelOptions, setModelOptions] = useAtom(modelsListAtom); const [modelOptions, setModelOptions] = useAtom(modelsListAtom);
const [rememberOutputFolder, setRememberOutputFolder] = useAtom(
rememberOutputFolderAtom
);
const [scale, setScale] = useAtom(scaleAtom); const [scale, setScale] = useAtom(scaleAtom);
@ -68,7 +65,7 @@ function SettingsTab({
} else { } else {
const currentlySavedModel = JSON.parse( const currentlySavedModel = JSON.parse(
localStorage.getItem("model") localStorage.getItem("model")
) as typeof modelOptions[0]; ) as (typeof modelOptions)[0];
setCurrentModel(currentlySavedModel); setCurrentModel(currentlySavedModel);
setModel(currentlySavedModel.value); setModel(currentlySavedModel.value);
} }
@ -91,6 +88,10 @@ function SettingsTab({
localStorage.setItem("saveImageAs", format); localStorage.setItem("saveImageAs", format);
}; };
const handleRememberOutputFolder = () => {
setRememberOutputFolder((oldValue) => !oldValue);
};
const handleGpuIdChange = (e) => { const handleGpuIdChange = (e) => {
setGpuId(e.target.value); setGpuId(e.target.value);
localStorage.setItem("gpuId", e.target.value); localStorage.setItem("gpuId", e.target.value);
@ -159,9 +160,7 @@ function SettingsTab({
type="checkbox" type="checkbox"
className="toggle-primary toggle" className="toggle-primary toggle"
defaultChecked={rememberOutputFolder} defaultChecked={rememberOutputFolder}
onChange={() => { onChange={handleRememberOutputFolder}
setRememberOutputFolder((oldValue) => !oldValue);
}}
/> />
</div> </div>
@ -192,7 +191,8 @@ function SettingsTab({
setCustomModelsPath(customModelPath); setCustomModelsPath(customModelPath);
window.electron.send(commands.GET_MODELS_LIST, customModelPath); window.electron.send(commands.GET_MODELS_LIST, customModelPath);
} }
}}> }}
>
Select Folder Select Folder
</button> </button>
</div> </div>
@ -217,7 +217,8 @@ function SettingsTab({
className={`btn-primary btn ${ className={`btn-primary btn ${
saveImageAs === "png" && "btn-accent" saveImageAs === "png" && "btn-accent"
}`} }`}
onClick={() => setExportType("png")}> onClick={() => setExportType("png")}
>
PNG PNG
</button> </button>
{/* JPG */} {/* JPG */}
@ -225,7 +226,8 @@ function SettingsTab({
className={`btn-primary btn ${ className={`btn-primary btn ${
saveImageAs === "jpg" && "btn-accent" saveImageAs === "jpg" && "btn-accent"
}`} }`}
onClick={() => setExportType("jpg")}> onClick={() => setExportType("jpg")}
>
JPG JPG
</button> </button>
{/* WEBP */} {/* WEBP */}
@ -233,7 +235,8 @@ function SettingsTab({
className={`btn-primary btn ${ className={`btn-primary btn ${
saveImageAs === "webp" && "btn-accent" saveImageAs === "webp" && "btn-accent"
}`} }`}
onClick={() => setExportType("webp")}> onClick={() => setExportType("webp")}
>
WEBP WEBP
</button> </button>
</div> </div>
@ -268,8 +271,9 @@ function SettingsTab({
<div className="relative flex flex-col gap-2"> <div className="relative flex flex-col gap-2">
<button <button
className="btn-primary btn-xs btn absolute top-10 right-2 z-10" className="btn-primary btn-xs btn absolute right-2 top-10 z-10"
onClick={copyOnClickHandler}> onClick={copyOnClickHandler}
>
{isCopied ? <span>Copied 📋</span> : <span>Copy 📋</span>} {isCopied ? <span>Copied 📋</span> : <span>Copy 📋</span>}
</button> </button>
<p className="text-sm font-medium">LOGS</p> <p className="text-sm font-medium">LOGS</p>

View File

@ -15,6 +15,7 @@ import { modelsListAtom } from "../atoms/modelsListAtom";
import { import {
batchModeAtom, batchModeAtom,
customModelsPathAtom, customModelsPathAtom,
rememberOutputFolderAtom,
scaleAtom, scaleAtom,
} from "../atoms/userSettingsAtom"; } from "../atoms/userSettingsAtom";
@ -29,6 +30,9 @@ const Home = () => {
const [loaded, setLoaded] = useState(false); const [loaded, setLoaded] = useState(false);
const [version, setVersion] = useState(""); const [version, setVersion] = useState("");
const [batchMode, setBatchMode] = useAtom(batchModeAtom); const [batchMode, setBatchMode] = useAtom(batchModeAtom);
const [rememberOutputFolder, setRememberOutputFolder] = useAtom(
rememberOutputFolderAtom
);
const [batchFolderPath, setBatchFolderPath] = useState(""); const [batchFolderPath, setBatchFolderPath] = useState("");
const [upscaledBatchFolderPath, setUpscaledBatchFolderPath] = useState(""); const [upscaledBatchFolderPath, setUpscaledBatchFolderPath] = useState("");
const [doubleUpscayl, setDoubleUpscayl] = useState(false); const [doubleUpscayl, setDoubleUpscayl] = useState(false);
@ -538,6 +542,8 @@ const Home = () => {
<SettingsTab <SettingsTab
batchMode={batchMode} batchMode={batchMode}
setBatchMode={setBatchMode} setBatchMode={setBatchMode}
rememberOutputFolder={rememberOutputFolder}
setRememberOutputFolder={setRememberOutputFolder}
imagePath={imagePath} imagePath={imagePath}
setModel={setModel} setModel={setModel}
gpuId={gpuId} gpuId={gpuId}
@ -558,7 +564,8 @@ const Home = () => {
onDragOver={(e) => handleDragOver(e)} onDragOver={(e) => handleDragOver(e)}
onDragEnter={(e) => handleDragEnter(e)} onDragEnter={(e) => handleDragEnter(e)}
onDragLeave={(e) => handleDragLeave(e)} onDragLeave={(e) => handleDragLeave(e)}
onPaste={(e) => handlePaste(e)}> onPaste={(e) => handlePaste(e)}
>
{progress.length > 0 && {progress.length > 0 &&
upscaledImagePath.length === 0 && upscaledImagePath.length === 0 &&
upscaledBatchFolderPath.length === 0 && upscaledBatchFolderPath.length === 0 &&
@ -635,7 +642,8 @@ const Home = () => {
</p> </p>
<button <button
className="bg-gradient-blue rounded-lg p-3 font-medium text-white/90 transition-colors" className="bg-gradient-blue rounded-lg p-3 font-medium text-white/90 transition-colors"
onClick={openFolderHandler}> onClick={openFolderHandler}
>
Open Upscayled Folder Open Upscayled Folder
</button> </button>
</> </>