mirror of
https://github.com/upscayl/upscayl.git
synced 2024-11-27 17:00:52 +01:00
Fix scale and config vars
This commit is contained in:
parent
b846c76afe
commit
0fe8bf8ba4
@ -2,10 +2,10 @@ import fs from "fs";
|
||||
import { getMainWindow } from "../main-window";
|
||||
import {
|
||||
childProcesses,
|
||||
customModelsFolderPath,
|
||||
savedCustomModelsPath,
|
||||
customWidth,
|
||||
noImageProcessing,
|
||||
saveOutputFolder,
|
||||
rememberOutputFolder,
|
||||
setCompression,
|
||||
setNoImageProcessing,
|
||||
setStopped,
|
||||
@ -37,7 +37,7 @@ const batchUpscayl = async (event, payload: BatchUpscaylPayload) => {
|
||||
let inputDir = payload.batchFolderPath;
|
||||
// GET THE OUTPUT DIRECTORY
|
||||
let outputFolderPath = payload.outputPath;
|
||||
if (saveOutputFolder === true && outputFolderPath) {
|
||||
if (rememberOutputFolder === true && outputFolderPath) {
|
||||
outputFolderPath = outputFolderPath;
|
||||
}
|
||||
// ! 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);
|
||||
|
||||
let initialScale = getModelScale(model);
|
||||
const scale = payload.scale;
|
||||
|
||||
const desiredScale = useCustomWidth
|
||||
? customWidth || payload.scale
|
||||
: payload.scale;
|
||||
|
||||
const outputFolderName = `upscayl_${saveImageAs}_${model}_${noImageProcessing ? initialScale : desiredScale}${useCustomWidth ? "px" : "x"}`;
|
||||
const outputFolderName = `upscayl_${saveImageAs}_${model}_${scale}${useCustomWidth ? "px" : "x"}`;
|
||||
outputFolderPath += slash + outputFolderName;
|
||||
if (!fs.existsSync(outputFolderPath)) {
|
||||
fs.mkdirSync(outputFolderPath, { recursive: true });
|
||||
@ -72,15 +68,17 @@ const batchUpscayl = async (event, payload: BatchUpscaylPayload) => {
|
||||
|
||||
// UPSCALE
|
||||
const upscayl = spawnUpscayl(
|
||||
getBatchArguments(
|
||||
getBatchArguments({
|
||||
inputDir,
|
||||
outputFolderPath,
|
||||
isDefaultModel ? modelsPath : customModelsFolderPath ?? modelsPath,
|
||||
outputDir: outputFolderPath,
|
||||
modelsPath: isDefaultModel
|
||||
? modelsPath
|
||||
: savedCustomModelsPath ?? modelsPath,
|
||||
model,
|
||||
gpuId,
|
||||
saveImageAs,
|
||||
initialScale,
|
||||
),
|
||||
scale,
|
||||
}),
|
||||
logit,
|
||||
);
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { MessageBoxOptions, dialog } from "electron";
|
||||
import {
|
||||
customModelsFolderPath,
|
||||
setCustomModelsFolderPath,
|
||||
savedCustomModelsPath,
|
||||
setSavedCustomModelsPath,
|
||||
} from "../utils/config-variables";
|
||||
import logit from "../utils/logit";
|
||||
import slash from "../utils/slash";
|
||||
@ -22,7 +22,7 @@ const customModelsSelect = async (event, message) => {
|
||||
} = await dialog.showOpenDialog({
|
||||
properties: ["openDirectory"],
|
||||
title: "Select Custom Models Folder",
|
||||
defaultPath: customModelsFolderPath,
|
||||
defaultPath: savedCustomModelsPath,
|
||||
securityScopedBookmarks: true,
|
||||
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");
|
||||
return null;
|
||||
} else {
|
||||
setCustomModelsFolderPath(folderPaths[0]);
|
||||
setSavedCustomModelsPath(folderPaths[0]);
|
||||
|
||||
if (
|
||||
!folderPaths[0].endsWith(slash + "models") &&
|
||||
@ -54,11 +54,11 @@ const customModelsSelect = async (event, message) => {
|
||||
return null;
|
||||
}
|
||||
|
||||
const models = await getModels(customModelsFolderPath);
|
||||
const models = await getModels(savedCustomModelsPath);
|
||||
mainWindow.webContents.send(COMMAND.CUSTOM_MODEL_FILES_LIST, models);
|
||||
|
||||
logit("📁 Custom Folder Path: ", customModelsFolderPath);
|
||||
return customModelsFolderPath;
|
||||
logit("📁 Custom Folder Path: ", savedCustomModelsPath);
|
||||
return savedCustomModelsPath;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -2,12 +2,12 @@ import path, { parse } from "path";
|
||||
import { getMainWindow } from "../main-window";
|
||||
import {
|
||||
childProcesses,
|
||||
customModelsFolderPath,
|
||||
savedCustomModelsPath,
|
||||
customWidth,
|
||||
folderPath,
|
||||
savedBatchUpscaylFolderPath,
|
||||
noImageProcessing,
|
||||
outputFolderPath,
|
||||
saveOutputFolder,
|
||||
savedOutputPath,
|
||||
rememberOutputFolder,
|
||||
setCompression,
|
||||
setNoImageProcessing,
|
||||
setStopped,
|
||||
@ -39,8 +39,8 @@ const doubleUpscayl = async (event, payload: DoubleUpscaylPayload) => {
|
||||
let inputDir = (imagePath.match(/(.*)[\/\\]/) || [""])[1];
|
||||
let outputDir = path.normalize(payload.outputPath);
|
||||
|
||||
if (saveOutputFolder === true && outputFolderPath) {
|
||||
outputDir = outputFolderPath;
|
||||
if (rememberOutputFolder === true && savedOutputPath) {
|
||||
outputDir = savedOutputPath;
|
||||
}
|
||||
const gpuId = payload.gpuId as string;
|
||||
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 fileName = parse(fullfileName).name;
|
||||
|
||||
let initialScale = getModelScale(model);
|
||||
|
||||
const desiredScale = useCustomWidth
|
||||
? customWidth || parseInt(payload.scale) * parseInt(payload.scale)
|
||||
: parseInt(payload.scale) * parseInt(payload.scale);
|
||||
const scale = parseInt(payload.scale) * parseInt(payload.scale);
|
||||
|
||||
const outFile =
|
||||
outputDir +
|
||||
slash +
|
||||
fileName +
|
||||
"_upscayl_" +
|
||||
(noImageProcessing
|
||||
? parseInt(initialScale) * parseInt(initialScale)
|
||||
: desiredScale) +
|
||||
scale +
|
||||
(useCustomWidth ? "px_" : "x_") +
|
||||
model +
|
||||
"." +
|
||||
@ -76,16 +70,18 @@ const doubleUpscayl = async (event, payload: DoubleUpscaylPayload) => {
|
||||
|
||||
// UPSCALE
|
||||
let upscayl = spawnUpscayl(
|
||||
getDoubleUpscaleArguments(
|
||||
getDoubleUpscaleArguments({
|
||||
inputDir,
|
||||
fullfileName,
|
||||
outFile,
|
||||
isDefaultModel ? modelsPath : customModelsFolderPath ?? modelsPath,
|
||||
modelsPath: isDefaultModel
|
||||
? modelsPath
|
||||
: savedCustomModelsPath ?? modelsPath,
|
||||
model,
|
||||
gpuId,
|
||||
saveImageAs,
|
||||
initialScale,
|
||||
),
|
||||
scale: scale.toString(),
|
||||
}),
|
||||
logit,
|
||||
);
|
||||
|
||||
@ -180,15 +176,17 @@ const doubleUpscayl = async (event, payload: DoubleUpscaylPayload) => {
|
||||
if (!failed && !stopped) {
|
||||
// UPSCALE
|
||||
let upscayl2 = spawnUpscayl(
|
||||
getDoubleUpscaleSecondPassArguments(
|
||||
getDoubleUpscaleSecondPassArguments({
|
||||
isAlpha,
|
||||
outFile,
|
||||
isDefaultModel ? modelsPath : customModelsFolderPath ?? modelsPath,
|
||||
modelsPath: isDefaultModel
|
||||
? modelsPath
|
||||
: savedCustomModelsPath ?? modelsPath,
|
||||
model,
|
||||
gpuId,
|
||||
saveImageAs,
|
||||
initialScale,
|
||||
),
|
||||
scale: scale.toString(),
|
||||
}),
|
||||
logit,
|
||||
);
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
import COMMAND from "../../common/commands";
|
||||
import { getMainWindow } from "../main-window";
|
||||
import {
|
||||
customModelsFolderPath,
|
||||
setCustomModelsFolderPath,
|
||||
savedCustomModelsPath,
|
||||
setSavedCustomModelsPath,
|
||||
} from "../utils/config-variables";
|
||||
import getModels from "../utils/get-models";
|
||||
import logit from "../utils/logit";
|
||||
@ -12,9 +12,9 @@ const getModelsList = async (event, payload) => {
|
||||
|
||||
if (!mainWindow) return;
|
||||
if (payload) {
|
||||
setCustomModelsFolderPath(payload);
|
||||
setSavedCustomModelsPath(payload);
|
||||
|
||||
logit("📁 Custom Models Folder Path: ", customModelsFolderPath);
|
||||
logit("📁 Custom Models Folder Path: ", savedCustomModelsPath);
|
||||
const models = await getModels(payload);
|
||||
|
||||
mainWindow.webContents.send(COMMAND.CUSTOM_MODEL_FILES_LIST, models);
|
||||
|
@ -2,13 +2,13 @@ import fs from "fs";
|
||||
import { modelsPath } from "../utils/get-resource-paths";
|
||||
import COMMAND from "../../common/commands";
|
||||
import {
|
||||
compression,
|
||||
customModelsFolderPath,
|
||||
savedCompression,
|
||||
savedCustomModelsPath,
|
||||
customWidth,
|
||||
folderPath,
|
||||
savedBatchUpscaylFolderPath,
|
||||
noImageProcessing,
|
||||
outputFolderPath,
|
||||
saveOutputFolder,
|
||||
savedOutputPath,
|
||||
rememberOutputFolder,
|
||||
setChildProcesses,
|
||||
setCompression,
|
||||
setNoImageProcessing,
|
||||
@ -25,7 +25,6 @@ import { getMainWindow } from "../main-window";
|
||||
import { ImageUpscaylPayload } from "../../common/types/types";
|
||||
import { ImageFormat } from "../utils/types";
|
||||
import getModelScale from "../../common/check-model-scale";
|
||||
import removeFileExtension from "../utils/remove-file-extension";
|
||||
import showNotification from "../utils/show-notification";
|
||||
import { DEFAULT_MODELS } from "../../common/models-list";
|
||||
|
||||
@ -40,29 +39,27 @@ const imageUpscayl = async (event, payload: ImageUpscaylPayload) => {
|
||||
setNoImageProcessing(payload.noImageProcessing);
|
||||
setCompression(parseInt(payload.compression));
|
||||
|
||||
// GET VARIABLES
|
||||
const model = payload.model as string;
|
||||
const gpuId = payload.gpuId as string;
|
||||
const saveImageAs = payload.saveImageAs as ImageFormat;
|
||||
console.log("🚀 => saveImageAs:", saveImageAs);
|
||||
|
||||
const overwrite = payload.overwrite as boolean;
|
||||
|
||||
let inputDir = (payload.imagePath.match(/(.*)[\/\\]/)?.[1] || "") as string;
|
||||
let outputDir: string | undefined =
|
||||
folderPath || (payload.outputPath as string);
|
||||
|
||||
if (saveOutputFolder === true && outputFolderPath) {
|
||||
outputDir = outputFolderPath;
|
||||
savedBatchUpscaylFolderPath || (payload.outputPath as string);
|
||||
if (
|
||||
rememberOutputFolder === true &&
|
||||
savedOutputPath &&
|
||||
savedOutputPath?.length > 0
|
||||
) {
|
||||
logit("🧠 Using saved output path");
|
||||
outputDir = savedOutputPath;
|
||||
}
|
||||
|
||||
const isDefaultModel = DEFAULT_MODELS.includes(model);
|
||||
logit("Is Default Model? : ", isDefaultModel);
|
||||
const fullfileName = payload.imagePath.replace(/^.*[\\\/]/, "") as string;
|
||||
const fileName = parse(fullfileName).name;
|
||||
const fileExt = parse(fullfileName).ext;
|
||||
|
||||
let initialScale = getModelScale(model);
|
||||
|
||||
const desiredScale = useCustomWidth
|
||||
? customWidth || payload.scale
|
||||
: payload.scale;
|
||||
@ -72,7 +69,7 @@ const imageUpscayl = async (event, payload: ImageUpscaylPayload) => {
|
||||
slash +
|
||||
fileName +
|
||||
"_upscayl_" +
|
||||
(noImageProcessing ? initialScale : desiredScale) +
|
||||
desiredScale +
|
||||
(useCustomWidth ? "px_" : "x_") +
|
||||
model +
|
||||
"." +
|
||||
@ -100,23 +97,25 @@ const imageUpscayl = async (event, payload: ImageUpscaylPayload) => {
|
||||
outputDir,
|
||||
fullfileName,
|
||||
fileName,
|
||||
initialScale: initialScale,
|
||||
scale: desiredScale,
|
||||
desiredScale,
|
||||
outFile,
|
||||
compression,
|
||||
compression: savedCompression,
|
||||
}),
|
||||
);
|
||||
const upscayl = spawnUpscayl(
|
||||
getSingleImageArguments(
|
||||
getSingleImageArguments({
|
||||
inputDir,
|
||||
fullfileName,
|
||||
outFile,
|
||||
isDefaultModel ? modelsPath : customModelsFolderPath ?? modelsPath,
|
||||
modelsPath: isDefaultModel
|
||||
? modelsPath
|
||||
: savedCustomModelsPath ?? modelsPath,
|
||||
model,
|
||||
initialScale,
|
||||
scale: desiredScale,
|
||||
gpuId,
|
||||
saveImageAs,
|
||||
),
|
||||
}),
|
||||
logit,
|
||||
);
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { MessageBoxOptions, app, dialog } from "electron";
|
||||
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 settings from "electron-settings";
|
||||
import { featureFlags } from "../../common/feature-flags";
|
||||
@ -11,7 +11,7 @@ const selectFile = async () => {
|
||||
const { canceled, filePaths, bookmarks } = await dialog.showOpenDialog({
|
||||
properties: ["openFile"],
|
||||
title: "Select Image",
|
||||
defaultPath: imagePath,
|
||||
defaultPath: savedImagePath,
|
||||
securityScopedBookmarks: true,
|
||||
message: "Select Image to Upscale",
|
||||
filters: [
|
||||
@ -40,7 +40,7 @@ const selectFile = async () => {
|
||||
logit("🚫 File Operation Cancelled");
|
||||
return null;
|
||||
} else {
|
||||
setImagePath(filePaths[0]);
|
||||
setSavedImagePath(filePaths[0]);
|
||||
|
||||
let isValid = false;
|
||||
// READ SELECTED FILES
|
||||
|
@ -1,5 +1,8 @@
|
||||
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 settings from "electron-settings";
|
||||
import { featureFlags } from "../../common/feature-flags";
|
||||
@ -11,7 +14,7 @@ const selectFolder = async (event, message) => {
|
||||
logit("🚨 Folder Bookmarks: ", folderBookmarks);
|
||||
try {
|
||||
closeAccess = app.startAccessingSecurityScopedResource(
|
||||
folderBookmarks as string
|
||||
folderBookmarks as string,
|
||||
);
|
||||
} catch (error) {
|
||||
logit("📁 Folder Bookmarks Error: ", error);
|
||||
@ -24,7 +27,7 @@ const selectFolder = async (event, message) => {
|
||||
bookmarks,
|
||||
} = await dialog.showOpenDialog({
|
||||
properties: ["openDirectory"],
|
||||
defaultPath: folderPath,
|
||||
defaultPath: savedBatchUpscaylFolderPath,
|
||||
securityScopedBookmarks: true,
|
||||
});
|
||||
|
||||
@ -37,8 +40,8 @@ const selectFolder = async (event, message) => {
|
||||
logit("🚫 Select Folder Operation Cancelled");
|
||||
return null;
|
||||
} else {
|
||||
setFolderPath(folderPaths[0]);
|
||||
logit("📁 Selected Folder Path: ", folderPath);
|
||||
setSavedBatchUpscaylFolderPath(folderPaths[0]);
|
||||
logit("📁 Selected Folder Path: ", savedBatchUpscaylFolderPath);
|
||||
return folderPaths[0];
|
||||
}
|
||||
};
|
||||
|
@ -2,52 +2,81 @@ import { ChildProcessWithoutNullStreams } from "child_process";
|
||||
import { getMainWindow } from "../main-window";
|
||||
import logit from "./logit";
|
||||
|
||||
export let imagePath: string | undefined = "";
|
||||
export let folderPath: string | undefined = undefined;
|
||||
export let customModelsFolderPath: string | undefined = undefined;
|
||||
export let outputFolderPath: string | undefined = undefined;
|
||||
export let saveOutputFolder = false;
|
||||
export let compression = 0;
|
||||
/**
|
||||
* The saved image path so that the select image dialog can open to the last used path.
|
||||
*/
|
||||
export let savedImagePath: string | undefined = "";
|
||||
export function setSavedImagePath(value: string | undefined): void {
|
||||
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 childProcesses: {
|
||||
process: ChildProcessWithoutNullStreams;
|
||||
kill: () => boolean;
|
||||
}[] = [];
|
||||
|
||||
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 function setTurnOffNotifications(value: boolean): void {
|
||||
turnOffNotifications = value;
|
||||
logit("🔕 Updating Turn Off Notifications: ", turnOffNotifications);
|
||||
}
|
||||
|
||||
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 function setImagePath(value: string | undefined): void {
|
||||
imagePath = value;
|
||||
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);
|
||||
export function setUseCustomWidth(value: boolean): void {
|
||||
useCustomWidth = value;
|
||||
logit("📏 Updating Use Custom Width: ", useCustomWidth);
|
||||
}
|
||||
|
||||
// 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 {
|
||||
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
|
||||
export function fetchLocalStorage(): void {
|
||||
const mainWindow = getMainWindow();
|
||||
@ -98,34 +107,37 @@ export function fetchLocalStorage(): void {
|
||||
.executeJavaScript('localStorage.getItem("lastImagePath");', true)
|
||||
.then((lastImagePath: string | null) => {
|
||||
if (lastImagePath && lastImagePath.length > 0) {
|
||||
setImagePath(lastImagePath);
|
||||
setSavedImagePath(lastImagePath);
|
||||
}
|
||||
});
|
||||
// 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
|
||||
.executeJavaScript(
|
||||
'localStorage.getItem("lastCustomModelsFolderPath");',
|
||||
'localStorage.getItem("lastSavedBatchUpscaylFolderPath");',
|
||||
true,
|
||||
)
|
||||
.then((lastCustomModelsFolderPath: string | null) => {
|
||||
if (lastCustomModelsFolderPath && lastCustomModelsFolderPath.length > 0) {
|
||||
setCustomModelsFolderPath(lastCustomModelsFolderPath);
|
||||
.then((lastSavedBatchUpscaylFolderPath: string | null) => {
|
||||
if (
|
||||
lastSavedBatchUpscaylFolderPath &&
|
||||
lastSavedBatchUpscaylFolderPath.length > 0
|
||||
) {
|
||||
setSavedBatchUpscaylFolderPath(lastSavedBatchUpscaylFolderPath);
|
||||
}
|
||||
});
|
||||
// GET LAST CUSTOM MODELS FOLDER PATH TO LOCAL STORAGE
|
||||
mainWindow.webContents
|
||||
.executeJavaScript('localStorage.getItem("lastOutputFolderPath");', true)
|
||||
.then((lastOutputFolderPath: string | null) => {
|
||||
if (lastOutputFolderPath && lastOutputFolderPath.length > 0) {
|
||||
setOutputFolderPath(lastOutputFolderPath);
|
||||
.executeJavaScript('localStorage.getItem("customModelsFolderPath");', true)
|
||||
.then((value: string | null) => {
|
||||
if (value && value.length > 0) {
|
||||
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
|
||||
@ -133,7 +145,7 @@ export function fetchLocalStorage(): void {
|
||||
.executeJavaScript('localStorage.getItem("rememberOutputFolder");', true)
|
||||
.then((lastSaveOutputFolder: boolean | null) => {
|
||||
if (lastSaveOutputFolder !== null) {
|
||||
setSaveOutputFolder(lastSaveOutputFolder);
|
||||
setRememberOutputFolder(lastSaveOutputFolder);
|
||||
}
|
||||
});
|
||||
// GET IMAGE COMPRESSION (NUMBER) FROM LOCAL STORAGE
|
||||
|
@ -2,16 +2,25 @@ import { getPlatform } from "./get-device-specs";
|
||||
import { ImageFormat } from "./types";
|
||||
const slash: string = getPlatform() === "win" ? "\\" : "/";
|
||||
|
||||
export const getSingleImageArguments = (
|
||||
inputDir: string,
|
||||
fullfileName: string,
|
||||
outFile: string,
|
||||
modelsPath: string,
|
||||
model: string,
|
||||
scale: any,
|
||||
gpuId: string,
|
||||
saveImageAs: ImageFormat,
|
||||
) => {
|
||||
export const getSingleImageArguments = ({
|
||||
inputDir,
|
||||
fullfileName,
|
||||
outFile,
|
||||
modelsPath,
|
||||
model,
|
||||
scale,
|
||||
gpuId,
|
||||
saveImageAs,
|
||||
}: {
|
||||
inputDir: string;
|
||||
fullfileName: string;
|
||||
outFile: string;
|
||||
modelsPath: string;
|
||||
model: string;
|
||||
scale: any;
|
||||
gpuId: string;
|
||||
saveImageAs: ImageFormat;
|
||||
}) => {
|
||||
return [
|
||||
"-i",
|
||||
inputDir + slash + fullfileName,
|
||||
@ -30,43 +39,25 @@ export const getSingleImageArguments = (
|
||||
];
|
||||
};
|
||||
|
||||
export const getSingleImageSharpenArguments = (
|
||||
inputDir: string,
|
||||
fullfileName: string,
|
||||
outFile: string,
|
||||
modelsPath: string,
|
||||
model: string,
|
||||
scale: any,
|
||||
gpuId: string,
|
||||
saveImageAs: ImageFormat,
|
||||
) => {
|
||||
return [
|
||||
"-i",
|
||||
inputDir + slash + fullfileName,
|
||||
"-o",
|
||||
outFile,
|
||||
"-s",
|
||||
scale,
|
||||
"-x",
|
||||
"-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,
|
||||
) => {
|
||||
export const getDoubleUpscaleArguments = ({
|
||||
inputDir,
|
||||
fullfileName,
|
||||
outFile,
|
||||
modelsPath,
|
||||
model,
|
||||
gpuId,
|
||||
saveImageAs,
|
||||
scale,
|
||||
}: {
|
||||
inputDir: string;
|
||||
fullfileName: string;
|
||||
outFile: string;
|
||||
modelsPath: string;
|
||||
model: string;
|
||||
gpuId: string;
|
||||
saveImageAs: ImageFormat;
|
||||
scale: string;
|
||||
}) => {
|
||||
return [
|
||||
"-i",
|
||||
inputDir + slash + fullfileName,
|
||||
@ -85,15 +76,23 @@ export const getDoubleUpscaleArguments = (
|
||||
];
|
||||
};
|
||||
|
||||
export const getDoubleUpscaleSecondPassArguments = (
|
||||
isAlpha: boolean,
|
||||
outFile: string,
|
||||
modelsPath: string,
|
||||
model: string,
|
||||
gpuId: string,
|
||||
saveImageAs: ImageFormat,
|
||||
scale: string,
|
||||
) => {
|
||||
export const getDoubleUpscaleSecondPassArguments = ({
|
||||
isAlpha,
|
||||
outFile,
|
||||
modelsPath,
|
||||
model,
|
||||
gpuId,
|
||||
saveImageAs,
|
||||
scale,
|
||||
}: {
|
||||
isAlpha: boolean;
|
||||
outFile: string;
|
||||
modelsPath: string;
|
||||
model: string;
|
||||
gpuId: string;
|
||||
saveImageAs: ImageFormat;
|
||||
scale: string;
|
||||
}) => {
|
||||
return [
|
||||
"-i",
|
||||
isAlpha ? outFile + ".png" : outFile,
|
||||
@ -112,15 +111,23 @@ export const getDoubleUpscaleSecondPassArguments = (
|
||||
];
|
||||
};
|
||||
|
||||
export const getBatchArguments = (
|
||||
inputDir: string,
|
||||
outputDir: string,
|
||||
modelsPath: string,
|
||||
model: string,
|
||||
gpuId: string,
|
||||
saveImageAs: ImageFormat,
|
||||
scale: string,
|
||||
) => {
|
||||
export const getBatchArguments = ({
|
||||
inputDir,
|
||||
outputDir,
|
||||
modelsPath,
|
||||
model,
|
||||
gpuId,
|
||||
saveImageAs,
|
||||
scale,
|
||||
}: {
|
||||
inputDir: string;
|
||||
outputDir: string;
|
||||
modelsPath: string;
|
||||
model: string;
|
||||
gpuId: string;
|
||||
saveImageAs: ImageFormat;
|
||||
scale: string;
|
||||
}) => {
|
||||
return [
|
||||
"-i",
|
||||
inputDir,
|
||||
|
@ -5,12 +5,16 @@ export const customModelsPathAtom = atomWithStorage<string | null>(
|
||||
"customModelsPath",
|
||||
null,
|
||||
);
|
||||
|
||||
export const scaleAtom = atomWithStorage<"2" | "3" | "4">("scale", "4");
|
||||
|
||||
export const batchModeAtom = atom<boolean>(false);
|
||||
export const outputPathAtom = atomWithStorage<string | null>(
|
||||
"lastOutputFolderPath",
|
||||
|
||||
export const savedOutputPathAtom = atomWithStorage<string | null>(
|
||||
"savedOutputPath",
|
||||
null,
|
||||
);
|
||||
|
||||
export const progressAtom = atom<string>("");
|
||||
|
||||
export const rememberOutputFolderAtom = atomWithStorage<boolean>(
|
||||
|
@ -1,11 +1,11 @@
|
||||
import {
|
||||
outputPathAtom,
|
||||
savedOutputPathAtom,
|
||||
rememberOutputFolderAtom,
|
||||
} from "@/atoms/userSettingsAtom";
|
||||
import { useAtom } from "jotai";
|
||||
|
||||
export function SaveOutputFolderToggle() {
|
||||
const [outputPath, setOutputPath] = useAtom(outputPathAtom);
|
||||
const [outputPath, setOutputPath] = useAtom(savedOutputPathAtom);
|
||||
const [rememberOutputFolder, setRememberOutputFolder] = useAtom(
|
||||
rememberOutputFolderAtom,
|
||||
);
|
||||
|
@ -7,7 +7,7 @@ import { modelsListAtom } from "../../../atoms/modelsListAtom";
|
||||
import useLog from "../../hooks/useLog";
|
||||
import {
|
||||
noImageProcessingAtom,
|
||||
outputPathAtom,
|
||||
savedOutputPathAtom,
|
||||
progressAtom,
|
||||
rememberOutputFolderAtom,
|
||||
scaleAtom,
|
||||
@ -63,7 +63,7 @@ function LeftPaneImageSteps({
|
||||
const modelOptions = useAtomValue(modelsListAtom);
|
||||
const scale = useAtomValue(scaleAtom);
|
||||
const noImageProcessing = useAtomValue(noImageProcessingAtom);
|
||||
const [outputPath, setOutputPath] = useAtom(outputPathAtom);
|
||||
const [outputPath, setOutputPath] = useAtom(savedOutputPathAtom);
|
||||
const [progress, setProgress] = useAtom(progressAtom);
|
||||
const rememberOutputFolder = useAtomValue(rememberOutputFolderAtom);
|
||||
|
||||
|
@ -19,7 +19,7 @@ import {
|
||||
compressionAtom,
|
||||
dontShowCloudModalAtom,
|
||||
noImageProcessingAtom,
|
||||
outputPathAtom,
|
||||
savedOutputPathAtom,
|
||||
overwriteAtom,
|
||||
progressAtom,
|
||||
scaleAtom,
|
||||
@ -67,7 +67,7 @@ const Home = () => {
|
||||
const [cursorPosition, setCursorPosition] = useState({ x: 0, y: 0 });
|
||||
|
||||
// ATOMIC STATES
|
||||
const [outputPath, setOutputPath] = useAtom(outputPathAtom);
|
||||
const [outputPath, setOutputPath] = useAtom(savedOutputPathAtom);
|
||||
const [compression, setCompression] = useAtom(compressionAtom);
|
||||
const [progress, setProgress] = useAtom(progressAtom);
|
||||
const [batchMode, setBatchMode] = useAtom(batchModeAtom);
|
||||
|
Loading…
Reference in New Issue
Block a user