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

Fix scale and config vars

This commit is contained in:
Nayam Amarshe 2024-04-09 23:41:24 +05:30
parent b846c76afe
commit 0fe8bf8ba4
13 changed files with 245 additions and 224 deletions

View File

@ -2,10 +2,10 @@ import fs from "fs";
import { getMainWindow } from "../main-window"; import { getMainWindow } from "../main-window";
import { import {
childProcesses, childProcesses,
customModelsFolderPath, savedCustomModelsPath,
customWidth, customWidth,
noImageProcessing, noImageProcessing,
saveOutputFolder, rememberOutputFolder,
setCompression, setCompression,
setNoImageProcessing, setNoImageProcessing,
setStopped, setStopped,
@ -37,7 +37,7 @@ const batchUpscayl = async (event, payload: BatchUpscaylPayload) => {
let inputDir = payload.batchFolderPath; let inputDir = payload.batchFolderPath;
// GET THE OUTPUT DIRECTORY // GET THE OUTPUT DIRECTORY
let outputFolderPath = payload.outputPath; let outputFolderPath = payload.outputPath;
if (saveOutputFolder === true && outputFolderPath) { if (rememberOutputFolder === true && outputFolderPath) {
outputFolderPath = outputFolderPath; outputFolderPath = outputFolderPath;
} }
// ! Don't do fetchLocalStorage() again, it causes the values to be reset // ! Don't do fetchLocalStorage() again, it causes the values to be reset
@ -46,13 +46,9 @@ const batchUpscayl = async (event, payload: BatchUpscaylPayload) => {
const isDefaultModel = DEFAULT_MODELS.includes(model); const isDefaultModel = DEFAULT_MODELS.includes(model);
let initialScale = getModelScale(model); const scale = payload.scale;
const desiredScale = useCustomWidth const outputFolderName = `upscayl_${saveImageAs}_${model}_${scale}${useCustomWidth ? "px" : "x"}`;
? customWidth || payload.scale
: payload.scale;
const outputFolderName = `upscayl_${saveImageAs}_${model}_${noImageProcessing ? initialScale : desiredScale}${useCustomWidth ? "px" : "x"}`;
outputFolderPath += slash + outputFolderName; outputFolderPath += slash + outputFolderName;
if (!fs.existsSync(outputFolderPath)) { if (!fs.existsSync(outputFolderPath)) {
fs.mkdirSync(outputFolderPath, { recursive: true }); fs.mkdirSync(outputFolderPath, { recursive: true });
@ -72,15 +68,17 @@ const batchUpscayl = async (event, payload: BatchUpscaylPayload) => {
// UPSCALE // UPSCALE
const upscayl = spawnUpscayl( const upscayl = spawnUpscayl(
getBatchArguments( getBatchArguments({
inputDir, inputDir,
outputFolderPath, outputDir: outputFolderPath,
isDefaultModel ? modelsPath : customModelsFolderPath ?? modelsPath, modelsPath: isDefaultModel
? modelsPath
: savedCustomModelsPath ?? modelsPath,
model, model,
gpuId, gpuId,
saveImageAs, saveImageAs,
initialScale, scale,
), }),
logit, logit,
); );

View File

@ -1,7 +1,7 @@
import { MessageBoxOptions, dialog } from "electron"; import { MessageBoxOptions, dialog } from "electron";
import { import {
customModelsFolderPath, savedCustomModelsPath,
setCustomModelsFolderPath, setSavedCustomModelsPath,
} from "../utils/config-variables"; } from "../utils/config-variables";
import logit from "../utils/logit"; import logit from "../utils/logit";
import slash from "../utils/slash"; import slash from "../utils/slash";
@ -22,7 +22,7 @@ const customModelsSelect = async (event, message) => {
} = await dialog.showOpenDialog({ } = await dialog.showOpenDialog({
properties: ["openDirectory"], properties: ["openDirectory"],
title: "Select Custom Models Folder", title: "Select Custom Models Folder",
defaultPath: customModelsFolderPath, defaultPath: savedCustomModelsPath,
securityScopedBookmarks: true, securityScopedBookmarks: true,
message: "Select Custom Models Folder that is named 'models'", message: "Select Custom Models Folder that is named 'models'",
}); });
@ -36,7 +36,7 @@ const customModelsSelect = async (event, message) => {
logit("🚫 Select Custom Models Folder Operation Cancelled"); logit("🚫 Select Custom Models Folder Operation Cancelled");
return null; return null;
} else { } else {
setCustomModelsFolderPath(folderPaths[0]); setSavedCustomModelsPath(folderPaths[0]);
if ( if (
!folderPaths[0].endsWith(slash + "models") && !folderPaths[0].endsWith(slash + "models") &&
@ -54,11 +54,11 @@ const customModelsSelect = async (event, message) => {
return null; return null;
} }
const models = await getModels(customModelsFolderPath); const models = await getModels(savedCustomModelsPath);
mainWindow.webContents.send(COMMAND.CUSTOM_MODEL_FILES_LIST, models); mainWindow.webContents.send(COMMAND.CUSTOM_MODEL_FILES_LIST, models);
logit("📁 Custom Folder Path: ", customModelsFolderPath); logit("📁 Custom Folder Path: ", savedCustomModelsPath);
return customModelsFolderPath; return savedCustomModelsPath;
} }
}; };

View File

@ -2,12 +2,12 @@ import path, { parse } from "path";
import { getMainWindow } from "../main-window"; import { getMainWindow } from "../main-window";
import { import {
childProcesses, childProcesses,
customModelsFolderPath, savedCustomModelsPath,
customWidth, customWidth,
folderPath, savedBatchUpscaylFolderPath,
noImageProcessing, noImageProcessing,
outputFolderPath, savedOutputPath,
saveOutputFolder, rememberOutputFolder,
setCompression, setCompression,
setNoImageProcessing, setNoImageProcessing,
setStopped, setStopped,
@ -39,8 +39,8 @@ const doubleUpscayl = async (event, payload: DoubleUpscaylPayload) => {
let inputDir = (imagePath.match(/(.*)[\/\\]/) || [""])[1]; let inputDir = (imagePath.match(/(.*)[\/\\]/) || [""])[1];
let outputDir = path.normalize(payload.outputPath); let outputDir = path.normalize(payload.outputPath);
if (saveOutputFolder === true && outputFolderPath) { if (rememberOutputFolder === true && savedOutputPath) {
outputDir = outputFolderPath; outputDir = savedOutputPath;
} }
const gpuId = payload.gpuId as string; const gpuId = payload.gpuId as string;
const saveImageAs = payload.saveImageAs as ImageFormat; const saveImageAs = payload.saveImageAs as ImageFormat;
@ -55,20 +55,14 @@ const doubleUpscayl = async (event, payload: DoubleUpscaylPayload) => {
const fullfileName = imagePath.split(slash).slice(-1)[0] as string; const fullfileName = imagePath.split(slash).slice(-1)[0] as string;
const fileName = parse(fullfileName).name; const fileName = parse(fullfileName).name;
let initialScale = getModelScale(model); const scale = parseInt(payload.scale) * parseInt(payload.scale);
const desiredScale = useCustomWidth
? customWidth || parseInt(payload.scale) * parseInt(payload.scale)
: parseInt(payload.scale) * parseInt(payload.scale);
const outFile = const outFile =
outputDir + outputDir +
slash + slash +
fileName + fileName +
"_upscayl_" + "_upscayl_" +
(noImageProcessing scale +
? parseInt(initialScale) * parseInt(initialScale)
: desiredScale) +
(useCustomWidth ? "px_" : "x_") + (useCustomWidth ? "px_" : "x_") +
model + model +
"." + "." +
@ -76,16 +70,18 @@ const doubleUpscayl = async (event, payload: DoubleUpscaylPayload) => {
// UPSCALE // UPSCALE
let upscayl = spawnUpscayl( let upscayl = spawnUpscayl(
getDoubleUpscaleArguments( getDoubleUpscaleArguments({
inputDir, inputDir,
fullfileName, fullfileName,
outFile, outFile,
isDefaultModel ? modelsPath : customModelsFolderPath ?? modelsPath, modelsPath: isDefaultModel
? modelsPath
: savedCustomModelsPath ?? modelsPath,
model, model,
gpuId, gpuId,
saveImageAs, saveImageAs,
initialScale, scale: scale.toString(),
), }),
logit, logit,
); );
@ -180,15 +176,17 @@ const doubleUpscayl = async (event, payload: DoubleUpscaylPayload) => {
if (!failed && !stopped) { if (!failed && !stopped) {
// UPSCALE // UPSCALE
let upscayl2 = spawnUpscayl( let upscayl2 = spawnUpscayl(
getDoubleUpscaleSecondPassArguments( getDoubleUpscaleSecondPassArguments({
isAlpha, isAlpha,
outFile, outFile,
isDefaultModel ? modelsPath : customModelsFolderPath ?? modelsPath, modelsPath: isDefaultModel
? modelsPath
: savedCustomModelsPath ?? modelsPath,
model, model,
gpuId, gpuId,
saveImageAs, saveImageAs,
initialScale, scale: scale.toString(),
), }),
logit, logit,
); );

View File

@ -1,8 +1,8 @@
import COMMAND from "../../common/commands"; import COMMAND from "../../common/commands";
import { getMainWindow } from "../main-window"; import { getMainWindow } from "../main-window";
import { import {
customModelsFolderPath, savedCustomModelsPath,
setCustomModelsFolderPath, setSavedCustomModelsPath,
} from "../utils/config-variables"; } from "../utils/config-variables";
import getModels from "../utils/get-models"; import getModels from "../utils/get-models";
import logit from "../utils/logit"; import logit from "../utils/logit";
@ -12,9 +12,9 @@ const getModelsList = async (event, payload) => {
if (!mainWindow) return; if (!mainWindow) return;
if (payload) { if (payload) {
setCustomModelsFolderPath(payload); setSavedCustomModelsPath(payload);
logit("📁 Custom Models Folder Path: ", customModelsFolderPath); logit("📁 Custom Models Folder Path: ", savedCustomModelsPath);
const models = await getModels(payload); const models = await getModels(payload);
mainWindow.webContents.send(COMMAND.CUSTOM_MODEL_FILES_LIST, models); mainWindow.webContents.send(COMMAND.CUSTOM_MODEL_FILES_LIST, models);

View File

@ -2,13 +2,13 @@ import fs from "fs";
import { modelsPath } from "../utils/get-resource-paths"; import { modelsPath } from "../utils/get-resource-paths";
import COMMAND from "../../common/commands"; import COMMAND from "../../common/commands";
import { import {
compression, savedCompression,
customModelsFolderPath, savedCustomModelsPath,
customWidth, customWidth,
folderPath, savedBatchUpscaylFolderPath,
noImageProcessing, noImageProcessing,
outputFolderPath, savedOutputPath,
saveOutputFolder, rememberOutputFolder,
setChildProcesses, setChildProcesses,
setCompression, setCompression,
setNoImageProcessing, setNoImageProcessing,
@ -25,7 +25,6 @@ import { getMainWindow } from "../main-window";
import { ImageUpscaylPayload } from "../../common/types/types"; import { ImageUpscaylPayload } from "../../common/types/types";
import { ImageFormat } from "../utils/types"; import { ImageFormat } from "../utils/types";
import getModelScale from "../../common/check-model-scale"; import getModelScale from "../../common/check-model-scale";
import removeFileExtension from "../utils/remove-file-extension";
import showNotification from "../utils/show-notification"; import showNotification from "../utils/show-notification";
import { DEFAULT_MODELS } from "../../common/models-list"; import { DEFAULT_MODELS } from "../../common/models-list";
@ -40,29 +39,27 @@ const imageUpscayl = async (event, payload: ImageUpscaylPayload) => {
setNoImageProcessing(payload.noImageProcessing); setNoImageProcessing(payload.noImageProcessing);
setCompression(parseInt(payload.compression)); setCompression(parseInt(payload.compression));
// GET VARIABLES
const model = payload.model as string; const model = payload.model as string;
const gpuId = payload.gpuId as string; const gpuId = payload.gpuId as string;
const saveImageAs = payload.saveImageAs as ImageFormat; const saveImageAs = payload.saveImageAs as ImageFormat;
console.log("🚀 => saveImageAs:", saveImageAs);
const overwrite = payload.overwrite as boolean; const overwrite = payload.overwrite as boolean;
let inputDir = (payload.imagePath.match(/(.*)[\/\\]/)?.[1] || "") as string; let inputDir = (payload.imagePath.match(/(.*)[\/\\]/)?.[1] || "") as string;
let outputDir: string | undefined = let outputDir: string | undefined =
folderPath || (payload.outputPath as string); savedBatchUpscaylFolderPath || (payload.outputPath as string);
if (
if (saveOutputFolder === true && outputFolderPath) { rememberOutputFolder === true &&
outputDir = outputFolderPath; savedOutputPath &&
savedOutputPath?.length > 0
) {
logit("🧠 Using saved output path");
outputDir = savedOutputPath;
} }
const isDefaultModel = DEFAULT_MODELS.includes(model); const isDefaultModel = DEFAULT_MODELS.includes(model);
logit("Is Default Model? : ", isDefaultModel); logit("Is Default Model? : ", isDefaultModel);
const fullfileName = payload.imagePath.replace(/^.*[\\\/]/, "") as string; const fullfileName = payload.imagePath.replace(/^.*[\\\/]/, "") as string;
const fileName = parse(fullfileName).name; const fileName = parse(fullfileName).name;
const fileExt = parse(fullfileName).ext; const fileExt = parse(fullfileName).ext;
let initialScale = getModelScale(model);
const desiredScale = useCustomWidth const desiredScale = useCustomWidth
? customWidth || payload.scale ? customWidth || payload.scale
: payload.scale; : payload.scale;
@ -72,7 +69,7 @@ const imageUpscayl = async (event, payload: ImageUpscaylPayload) => {
slash + slash +
fileName + fileName +
"_upscayl_" + "_upscayl_" +
(noImageProcessing ? initialScale : desiredScale) + desiredScale +
(useCustomWidth ? "px_" : "x_") + (useCustomWidth ? "px_" : "x_") +
model + model +
"." + "." +
@ -100,23 +97,25 @@ const imageUpscayl = async (event, payload: ImageUpscaylPayload) => {
outputDir, outputDir,
fullfileName, fullfileName,
fileName, fileName,
initialScale: initialScale, scale: desiredScale,
desiredScale, desiredScale,
outFile, outFile,
compression, compression: savedCompression,
}), }),
); );
const upscayl = spawnUpscayl( const upscayl = spawnUpscayl(
getSingleImageArguments( getSingleImageArguments({
inputDir, inputDir,
fullfileName, fullfileName,
outFile, outFile,
isDefaultModel ? modelsPath : customModelsFolderPath ?? modelsPath, modelsPath: isDefaultModel
? modelsPath
: savedCustomModelsPath ?? modelsPath,
model, model,
initialScale, scale: desiredScale,
gpuId, gpuId,
saveImageAs, saveImageAs,
), }),
logit, logit,
); );

View File

@ -1,6 +1,6 @@
import { MessageBoxOptions, app, dialog } from "electron"; import { MessageBoxOptions, app, dialog } from "electron";
import { getMainWindow } from "../main-window"; import { getMainWindow } from "../main-window";
import { imagePath, setImagePath } from "../utils/config-variables"; import { savedImagePath, setSavedImagePath } from "../utils/config-variables";
import logit from "../utils/logit"; import logit from "../utils/logit";
import settings from "electron-settings"; import settings from "electron-settings";
import { featureFlags } from "../../common/feature-flags"; import { featureFlags } from "../../common/feature-flags";
@ -11,7 +11,7 @@ const selectFile = async () => {
const { canceled, filePaths, bookmarks } = await dialog.showOpenDialog({ const { canceled, filePaths, bookmarks } = await dialog.showOpenDialog({
properties: ["openFile"], properties: ["openFile"],
title: "Select Image", title: "Select Image",
defaultPath: imagePath, defaultPath: savedImagePath,
securityScopedBookmarks: true, securityScopedBookmarks: true,
message: "Select Image to Upscale", message: "Select Image to Upscale",
filters: [ filters: [
@ -40,7 +40,7 @@ const selectFile = async () => {
logit("🚫 File Operation Cancelled"); logit("🚫 File Operation Cancelled");
return null; return null;
} else { } else {
setImagePath(filePaths[0]); setSavedImagePath(filePaths[0]);
let isValid = false; let isValid = false;
// READ SELECTED FILES // READ SELECTED FILES

View File

@ -1,5 +1,8 @@
import { app, dialog } from "electron"; import { app, dialog } from "electron";
import { folderPath, setFolderPath } from "../utils/config-variables"; import {
savedBatchUpscaylFolderPath,
setSavedBatchUpscaylFolderPath,
} from "../utils/config-variables";
import logit from "../utils/logit"; import logit from "../utils/logit";
import settings from "electron-settings"; import settings from "electron-settings";
import { featureFlags } from "../../common/feature-flags"; import { featureFlags } from "../../common/feature-flags";
@ -11,7 +14,7 @@ const selectFolder = async (event, message) => {
logit("🚨 Folder Bookmarks: ", folderBookmarks); logit("🚨 Folder Bookmarks: ", folderBookmarks);
try { try {
closeAccess = app.startAccessingSecurityScopedResource( closeAccess = app.startAccessingSecurityScopedResource(
folderBookmarks as string folderBookmarks as string,
); );
} catch (error) { } catch (error) {
logit("📁 Folder Bookmarks Error: ", error); logit("📁 Folder Bookmarks Error: ", error);
@ -24,7 +27,7 @@ const selectFolder = async (event, message) => {
bookmarks, bookmarks,
} = await dialog.showOpenDialog({ } = await dialog.showOpenDialog({
properties: ["openDirectory"], properties: ["openDirectory"],
defaultPath: folderPath, defaultPath: savedBatchUpscaylFolderPath,
securityScopedBookmarks: true, securityScopedBookmarks: true,
}); });
@ -37,8 +40,8 @@ const selectFolder = async (event, message) => {
logit("🚫 Select Folder Operation Cancelled"); logit("🚫 Select Folder Operation Cancelled");
return null; return null;
} else { } else {
setFolderPath(folderPaths[0]); setSavedBatchUpscaylFolderPath(folderPaths[0]);
logit("📁 Selected Folder Path: ", folderPath); logit("📁 Selected Folder Path: ", savedBatchUpscaylFolderPath);
return folderPaths[0]; return folderPaths[0];
} }
}; };

View File

@ -2,52 +2,81 @@ import { ChildProcessWithoutNullStreams } from "child_process";
import { getMainWindow } from "../main-window"; import { getMainWindow } from "../main-window";
import logit from "./logit"; import logit from "./logit";
export let imagePath: string | undefined = ""; /**
export let folderPath: string | undefined = undefined; * The saved image path so that the select image dialog can open to the last used path.
export let customModelsFolderPath: string | undefined = undefined; */
export let outputFolderPath: string | undefined = undefined; export let savedImagePath: string | undefined = "";
export let saveOutputFolder = false; export function setSavedImagePath(value: string | undefined): void {
export let compression = 0; savedImagePath = value;
logit("🖼️ Updating Image Path: ", savedImagePath);
}
/**
* The saved folder path so that the select folder to upscayl dialog can open to the last used path.
*/
export let savedBatchUpscaylFolderPath: string | undefined = undefined;
export function setSavedBatchUpscaylFolderPath(
value: string | undefined,
): void {
savedBatchUpscaylFolderPath = value;
logit("📁 Updating Folder Path: ", savedBatchUpscaylFolderPath);
}
export let savedCustomModelsPath: string | undefined = undefined;
export function setSavedCustomModelsPath(value: string | undefined): void {
savedCustomModelsPath = value;
logit("📁 Updating Custom Models Folder Path: ", savedCustomModelsPath);
}
export let savedOutputPath: string | undefined = undefined;
export function setSavedOutputPath(value: string | undefined): void {
savedOutputPath = value;
logit("📁 Updating Output Folder Path: ", savedOutputPath);
}
export let rememberOutputFolder = false;
export function setRememberOutputFolder(value: boolean): void {
rememberOutputFolder = value;
logit("💾 Updating Remember Output Folder: ", rememberOutputFolder);
}
export let savedCompression = 0;
export function setCompression(value: number): void {
savedCompression = value;
logit("📐 Updating Compression: ", savedCompression);
}
export let stopped = false; export let stopped = false;
export let childProcesses: { export let childProcesses: {
process: ChildProcessWithoutNullStreams; process: ChildProcessWithoutNullStreams;
kill: () => boolean; kill: () => boolean;
}[] = []; }[] = [];
export let noImageProcessing: boolean = false; export let noImageProcessing: boolean = false;
export function setNoImageProcessing(value: boolean): void {
noImageProcessing = value;
logit("🖼️ Updating No Image Processing: ", noImageProcessing);
}
export let turnOffNotifications: boolean = false; export let turnOffNotifications: boolean = false;
export function setTurnOffNotifications(value: boolean): void {
turnOffNotifications = value;
logit("🔕 Updating Turn Off Notifications: ", turnOffNotifications);
}
export let customWidth: string | null = null; export let customWidth: string | null = null;
export function setCustomWidth(value: string | null): void {
customWidth = value;
logit("📏 Updating Custom Width: ", customWidth);
}
export let useCustomWidth: boolean = false; export let useCustomWidth: boolean = false;
export function setUseCustomWidth(value: boolean): void {
export function setImagePath(value: string | undefined): void { useCustomWidth = value;
imagePath = value; logit("📏 Updating Use Custom Width: ", useCustomWidth);
logit("🖼️ Updating Image Path: ", imagePath);
}
export function setFolderPath(value: string | undefined): void {
folderPath = value;
logit("📁 Updating Folder Path: ", folderPath);
}
export function setCustomModelsFolderPath(value: string | undefined): void {
customModelsFolderPath = value;
logit("📁 Updating Custom Models Folder Path: ", customModelsFolderPath);
} }
// SETTERS // SETTERS
export function setOutputFolderPath(value: string | undefined): void {
outputFolderPath = value;
logit("📁 Updating Output Folder Path: ", outputFolderPath);
}
export function setSaveOutputFolder(value: boolean): void {
saveOutputFolder = value;
logit("💾 Updating Save Output Folder: ", saveOutputFolder);
}
export function setCompression(value: number): void {
compression = value;
logit("📐 Updating Compression: ", compression);
}
export function setStopped(value: boolean): void { export function setStopped(value: boolean): void {
stopped = value; stopped = value;
@ -68,26 +97,6 @@ export function setChildProcesses(value: {
); );
} }
export function setNoImageProcessing(value: boolean): void {
noImageProcessing = value;
logit("🖼️ Updating No Image Processing: ", noImageProcessing);
}
export function setTurnOffNotifications(value: boolean): void {
turnOffNotifications = value;
logit("🔕 Updating Turn Off Notifications: ", turnOffNotifications);
}
export function setCustomWidth(value: string | null): void {
customWidth = value;
logit("📏 Updating Custom Width: ", customWidth);
}
export function setUseCustomWidth(value: boolean): void {
useCustomWidth = value;
logit("📏 Updating Use Custom Width: ", useCustomWidth);
}
// LOCAL STORAGE // LOCAL STORAGE
export function fetchLocalStorage(): void { export function fetchLocalStorage(): void {
const mainWindow = getMainWindow(); const mainWindow = getMainWindow();
@ -98,34 +107,37 @@ export function fetchLocalStorage(): void {
.executeJavaScript('localStorage.getItem("lastImagePath");', true) .executeJavaScript('localStorage.getItem("lastImagePath");', true)
.then((lastImagePath: string | null) => { .then((lastImagePath: string | null) => {
if (lastImagePath && lastImagePath.length > 0) { if (lastImagePath && lastImagePath.length > 0) {
setImagePath(lastImagePath); setSavedImagePath(lastImagePath);
} }
}); });
// GET LAST FOLDER PATH TO LOCAL STORAGE // GET LAST FOLDER PATH TO LOCAL STORAGE
mainWindow.webContents
.executeJavaScript('localStorage.getItem("lastFolderPath");', true)
.then((lastFolderPath: string | null) => {
if (lastFolderPath && lastFolderPath.length > 0) {
setFolderPath(lastFolderPath);
}
});
// GET LAST CUSTOM MODELS FOLDER PATH TO LOCAL STORAGE
mainWindow.webContents mainWindow.webContents
.executeJavaScript( .executeJavaScript(
'localStorage.getItem("lastCustomModelsFolderPath");', 'localStorage.getItem("lastSavedBatchUpscaylFolderPath");',
true, true,
) )
.then((lastCustomModelsFolderPath: string | null) => { .then((lastSavedBatchUpscaylFolderPath: string | null) => {
if (lastCustomModelsFolderPath && lastCustomModelsFolderPath.length > 0) { if (
setCustomModelsFolderPath(lastCustomModelsFolderPath); lastSavedBatchUpscaylFolderPath &&
lastSavedBatchUpscaylFolderPath.length > 0
) {
setSavedBatchUpscaylFolderPath(lastSavedBatchUpscaylFolderPath);
} }
}); });
// GET LAST CUSTOM MODELS FOLDER PATH TO LOCAL STORAGE // GET LAST CUSTOM MODELS FOLDER PATH TO LOCAL STORAGE
mainWindow.webContents mainWindow.webContents
.executeJavaScript('localStorage.getItem("lastOutputFolderPath");', true) .executeJavaScript('localStorage.getItem("customModelsFolderPath");', true)
.then((lastOutputFolderPath: string | null) => { .then((value: string | null) => {
if (lastOutputFolderPath && lastOutputFolderPath.length > 0) { if (value && value.length > 0) {
setOutputFolderPath(lastOutputFolderPath); setSavedCustomModelsPath(value);
}
});
// GET LAST CUSTOM MODELS FOLDER PATH TO LOCAL STORAGE
mainWindow.webContents
.executeJavaScript('localStorage.getItem("savedOutputPath");', true)
.then((savedOutputPath: string | null) => {
if (savedOutputPath && savedOutputPath.length > 0) {
setSavedOutputPath(savedOutputPath);
} }
}); });
// GET LAST SAVE OUTPUT FOLDER (BOOLEAN) TO LOCAL STORAGE // GET LAST SAVE OUTPUT FOLDER (BOOLEAN) TO LOCAL STORAGE
@ -133,7 +145,7 @@ export function fetchLocalStorage(): void {
.executeJavaScript('localStorage.getItem("rememberOutputFolder");', true) .executeJavaScript('localStorage.getItem("rememberOutputFolder");', true)
.then((lastSaveOutputFolder: boolean | null) => { .then((lastSaveOutputFolder: boolean | null) => {
if (lastSaveOutputFolder !== null) { if (lastSaveOutputFolder !== null) {
setSaveOutputFolder(lastSaveOutputFolder); setRememberOutputFolder(lastSaveOutputFolder);
} }
}); });
// GET IMAGE COMPRESSION (NUMBER) FROM LOCAL STORAGE // GET IMAGE COMPRESSION (NUMBER) FROM LOCAL STORAGE

View File

@ -2,16 +2,25 @@ import { getPlatform } from "./get-device-specs";
import { ImageFormat } from "./types"; import { ImageFormat } from "./types";
const slash: string = getPlatform() === "win" ? "\\" : "/"; const slash: string = getPlatform() === "win" ? "\\" : "/";
export const getSingleImageArguments = ( export const getSingleImageArguments = ({
inputDir: string, inputDir,
fullfileName: string, fullfileName,
outFile: string, outFile,
modelsPath: string, modelsPath,
model: string, model,
scale: any, scale,
gpuId: string, gpuId,
saveImageAs: ImageFormat, saveImageAs,
) => { }: {
inputDir: string;
fullfileName: string;
outFile: string;
modelsPath: string;
model: string;
scale: any;
gpuId: string;
saveImageAs: ImageFormat;
}) => {
return [ return [
"-i", "-i",
inputDir + slash + fullfileName, inputDir + slash + fullfileName,
@ -30,43 +39,25 @@ export const getSingleImageArguments = (
]; ];
}; };
export const getSingleImageSharpenArguments = ( export const getDoubleUpscaleArguments = ({
inputDir: string, inputDir,
fullfileName: string, fullfileName,
outFile: string, outFile,
modelsPath: string, modelsPath,
model: string, model,
scale: any, gpuId,
gpuId: string, saveImageAs,
saveImageAs: ImageFormat, scale,
) => { }: {
return [ inputDir: string;
"-i", fullfileName: string;
inputDir + slash + fullfileName, outFile: string;
"-o", modelsPath: string;
outFile, model: string;
"-s", gpuId: string;
scale, saveImageAs: ImageFormat;
"-x", scale: string;
"-m", }) => {
modelsPath + slash + model,
gpuId ? "-g" : "",
gpuId ? gpuId : "",
"-f",
saveImageAs,
];
};
export const getDoubleUpscaleArguments = (
inputDir: string,
fullfileName: string,
outFile: string,
modelsPath: string,
model: string,
gpuId: string,
saveImageAs: ImageFormat,
scale: string,
) => {
return [ return [
"-i", "-i",
inputDir + slash + fullfileName, inputDir + slash + fullfileName,
@ -85,15 +76,23 @@ export const getDoubleUpscaleArguments = (
]; ];
}; };
export const getDoubleUpscaleSecondPassArguments = ( export const getDoubleUpscaleSecondPassArguments = ({
isAlpha: boolean, isAlpha,
outFile: string, outFile,
modelsPath: string, modelsPath,
model: string, model,
gpuId: string, gpuId,
saveImageAs: ImageFormat, saveImageAs,
scale: string, scale,
) => { }: {
isAlpha: boolean;
outFile: string;
modelsPath: string;
model: string;
gpuId: string;
saveImageAs: ImageFormat;
scale: string;
}) => {
return [ return [
"-i", "-i",
isAlpha ? outFile + ".png" : outFile, isAlpha ? outFile + ".png" : outFile,
@ -112,15 +111,23 @@ export const getDoubleUpscaleSecondPassArguments = (
]; ];
}; };
export const getBatchArguments = ( export const getBatchArguments = ({
inputDir: string, inputDir,
outputDir: string, outputDir,
modelsPath: string, modelsPath,
model: string, model,
gpuId: string, gpuId,
saveImageAs: ImageFormat, saveImageAs,
scale: string, scale,
) => { }: {
inputDir: string;
outputDir: string;
modelsPath: string;
model: string;
gpuId: string;
saveImageAs: ImageFormat;
scale: string;
}) => {
return [ return [
"-i", "-i",
inputDir, inputDir,

View File

@ -5,12 +5,16 @@ export const customModelsPathAtom = atomWithStorage<string | null>(
"customModelsPath", "customModelsPath",
null, null,
); );
export const scaleAtom = atomWithStorage<"2" | "3" | "4">("scale", "4"); export const scaleAtom = atomWithStorage<"2" | "3" | "4">("scale", "4");
export const batchModeAtom = atom<boolean>(false); export const batchModeAtom = atom<boolean>(false);
export const outputPathAtom = atomWithStorage<string | null>(
"lastOutputFolderPath", export const savedOutputPathAtom = atomWithStorage<string | null>(
"savedOutputPath",
null, null,
); );
export const progressAtom = atom<string>(""); export const progressAtom = atom<string>("");
export const rememberOutputFolderAtom = atomWithStorage<boolean>( export const rememberOutputFolderAtom = atomWithStorage<boolean>(

View File

@ -1,11 +1,11 @@
import { import {
outputPathAtom, savedOutputPathAtom,
rememberOutputFolderAtom, rememberOutputFolderAtom,
} from "@/atoms/userSettingsAtom"; } from "@/atoms/userSettingsAtom";
import { useAtom } from "jotai"; import { useAtom } from "jotai";
export function SaveOutputFolderToggle() { export function SaveOutputFolderToggle() {
const [outputPath, setOutputPath] = useAtom(outputPathAtom); const [outputPath, setOutputPath] = useAtom(savedOutputPathAtom);
const [rememberOutputFolder, setRememberOutputFolder] = useAtom( const [rememberOutputFolder, setRememberOutputFolder] = useAtom(
rememberOutputFolderAtom, rememberOutputFolderAtom,
); );

View File

@ -7,7 +7,7 @@ import { modelsListAtom } from "../../../atoms/modelsListAtom";
import useLog from "../../hooks/useLog"; import useLog from "../../hooks/useLog";
import { import {
noImageProcessingAtom, noImageProcessingAtom,
outputPathAtom, savedOutputPathAtom,
progressAtom, progressAtom,
rememberOutputFolderAtom, rememberOutputFolderAtom,
scaleAtom, scaleAtom,
@ -63,7 +63,7 @@ function LeftPaneImageSteps({
const modelOptions = useAtomValue(modelsListAtom); const modelOptions = useAtomValue(modelsListAtom);
const scale = useAtomValue(scaleAtom); const scale = useAtomValue(scaleAtom);
const noImageProcessing = useAtomValue(noImageProcessingAtom); const noImageProcessing = useAtomValue(noImageProcessingAtom);
const [outputPath, setOutputPath] = useAtom(outputPathAtom); const [outputPath, setOutputPath] = useAtom(savedOutputPathAtom);
const [progress, setProgress] = useAtom(progressAtom); const [progress, setProgress] = useAtom(progressAtom);
const rememberOutputFolder = useAtomValue(rememberOutputFolderAtom); const rememberOutputFolder = useAtomValue(rememberOutputFolderAtom);

View File

@ -19,7 +19,7 @@ import {
compressionAtom, compressionAtom,
dontShowCloudModalAtom, dontShowCloudModalAtom,
noImageProcessingAtom, noImageProcessingAtom,
outputPathAtom, savedOutputPathAtom,
overwriteAtom, overwriteAtom,
progressAtom, progressAtom,
scaleAtom, scaleAtom,
@ -67,7 +67,7 @@ const Home = () => {
const [cursorPosition, setCursorPosition] = useState({ x: 0, y: 0 }); const [cursorPosition, setCursorPosition] = useState({ x: 0, y: 0 });
// ATOMIC STATES // ATOMIC STATES
const [outputPath, setOutputPath] = useAtom(outputPathAtom); const [outputPath, setOutputPath] = useAtom(savedOutputPathAtom);
const [compression, setCompression] = useAtom(compressionAtom); const [compression, setCompression] = useAtom(compressionAtom);
const [progress, setProgress] = useAtom(progressAtom); const [progress, setProgress] = useAtom(progressAtom);
const [batchMode, setBatchMode] = useAtom(batchModeAtom); const [batchMode, setBatchMode] = useAtom(batchModeAtom);