mirror of
https://github.com/upscayl/upscayl.git
synced 2024-11-23 23:21:05 +01:00
Try fixing overwrite
This commit is contained in:
parent
c798ffc7db
commit
847757ef70
@ -9,9 +9,9 @@ import COMMAND from "../constants/commands";
|
||||
import getModels from "../utils/get-models";
|
||||
import { getMainWindow } from "../main-window";
|
||||
|
||||
const mainWindow = getMainWindow();
|
||||
|
||||
const customModelsSelect = async (event, message) => {
|
||||
const mainWindow = getMainWindow();
|
||||
|
||||
if (!mainWindow) return;
|
||||
const { canceled, filePaths: folderPaths } = await dialog.showOpenDialog({
|
||||
properties: ["openDirectory"],
|
||||
|
@ -7,9 +7,9 @@ import {
|
||||
import getModels from "../utils/get-models";
|
||||
import logit from "../utils/logit";
|
||||
|
||||
const mainWindow = getMainWindow();
|
||||
|
||||
const getModelsList = async (event, payload) => {
|
||||
const mainWindow = getMainWindow();
|
||||
|
||||
if (!mainWindow) return;
|
||||
if (payload) {
|
||||
setCustomModelsFolderPath(payload);
|
||||
|
@ -20,7 +20,6 @@ import { spawnUpscayl } from "../utils/spawn-upscayl";
|
||||
import { parse } from "path";
|
||||
import DEFAULT_MODELS from "../constants/models";
|
||||
import { getMainWindow } from "../main-window";
|
||||
import stop from "./stop";
|
||||
|
||||
const imageUpscayl = async (event, payload) => {
|
||||
const mainWindow = getMainWindow();
|
||||
@ -73,18 +72,18 @@ const imageUpscayl = async (event, payload) => {
|
||||
saveImageAs;
|
||||
|
||||
// GET OVERWRITE SETTINGS FROM LOCAL STORAGE
|
||||
|
||||
mainWindow.webContents
|
||||
.executeJavaScript('localStorage.getItem("overwrite");', true)
|
||||
.then((lastSavedOverwrite: boolean | null) => {
|
||||
if (lastSavedOverwrite !== null) {
|
||||
console.log("Overwrite: ", lastSavedOverwrite);
|
||||
setOverwrite(lastSavedOverwrite);
|
||||
console.log("NEW OVERWRITE: ", overwrite);
|
||||
}
|
||||
});
|
||||
|
||||
// UPSCALE
|
||||
if (fs.existsSync(outFile) && overwrite === false) {
|
||||
if (fs.existsSync(outFile) && !overwrite) {
|
||||
// If already upscayled, just output that file
|
||||
logit("✅ Already upscayled at: ", outFile);
|
||||
mainWindow.webContents.send(
|
||||
|
@ -3,9 +3,9 @@ import { getMainWindow } from "../main-window";
|
||||
import { imagePath, setImagePath } from "../utils/config-variables";
|
||||
import logit from "../utils/logit";
|
||||
|
||||
const mainWindow = getMainWindow();
|
||||
|
||||
const selectFile = async () => {
|
||||
const mainWindow = getMainWindow();
|
||||
|
||||
const { canceled, filePaths } = await dialog.showOpenDialog({
|
||||
properties: ["openFile", "multiSelections"],
|
||||
title: "Select Image",
|
||||
|
@ -2,9 +2,9 @@ import { getMainWindow } from "../main-window";
|
||||
import { childProcesses, setStopped } from "../utils/config-variables";
|
||||
import logit from "../utils/logit";
|
||||
|
||||
const mainWindow = getMainWindow();
|
||||
|
||||
const stop = async (event, payload) => {
|
||||
const mainWindow = getMainWindow();
|
||||
|
||||
setStopped(true);
|
||||
mainWindow && mainWindow.setProgressBar(-1);
|
||||
childProcesses.forEach((child) => {
|
||||
|
@ -20,10 +20,12 @@ import getModelsList from "./commands/get-models-list";
|
||||
import customModelsSelect from "./commands/custom-models-select";
|
||||
import imageUpscayl from "./commands/image-upscayl";
|
||||
import {
|
||||
overwrite,
|
||||
setCustomModelsFolderPath,
|
||||
setFolderPath,
|
||||
setImagePath,
|
||||
setOutputFolderPath,
|
||||
setOverwrite,
|
||||
setQuality,
|
||||
setSaveOutputFolder,
|
||||
setStopped,
|
||||
@ -50,6 +52,99 @@ app.whenReady().then(async () => {
|
||||
if (!electronIsDev) {
|
||||
autoUpdater.checkForUpdates();
|
||||
}
|
||||
|
||||
const mainWindow = getMainWindow();
|
||||
|
||||
if (!mainWindow) {
|
||||
console.log("No main window");
|
||||
return;
|
||||
}
|
||||
|
||||
const url = electronIsDev
|
||||
? "http://localhost:8000"
|
||||
: (new URL("file:///").pathname = join(
|
||||
__dirname,
|
||||
"../renderer/out/index.html"
|
||||
)).toString();
|
||||
mainWindow.loadURL(url);
|
||||
|
||||
mainWindow.webContents.setWindowOpenHandler(({ url }) => {
|
||||
shell.openExternal(url);
|
||||
return { action: "deny" };
|
||||
});
|
||||
|
||||
mainWindow.once("ready-to-show", () => {
|
||||
if (!mainWindow) return;
|
||||
mainWindow.show();
|
||||
});
|
||||
|
||||
// GET LAST IMAGE PATH TO LOCAL STORAGE
|
||||
mainWindow.webContents
|
||||
.executeJavaScript('localStorage.getItem("lastImagePath");', true)
|
||||
.then((lastImagePath: string | null) => {
|
||||
if (lastImagePath && lastImagePath.length > 0) {
|
||||
setImagePath(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");',
|
||||
true
|
||||
)
|
||||
.then((lastCustomModelsFolderPath: string | null) => {
|
||||
if (lastCustomModelsFolderPath && lastCustomModelsFolderPath.length > 0) {
|
||||
setCustomModelsFolderPath(lastCustomModelsFolderPath);
|
||||
}
|
||||
});
|
||||
// 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);
|
||||
}
|
||||
});
|
||||
// GET LAST SAVE OUTPUT FOLDER (BOOLEAN) TO LOCAL STORAGE
|
||||
mainWindow.webContents
|
||||
.executeJavaScript('localStorage.getItem("rememberOutputFolder");', true)
|
||||
.then((lastSaveOutputFolder: boolean | null) => {
|
||||
if (lastSaveOutputFolder !== null) {
|
||||
setSaveOutputFolder(lastSaveOutputFolder);
|
||||
}
|
||||
});
|
||||
// GET IMAGE QUALITY (NUMBER) TO LOCAL STORAGE
|
||||
mainWindow.webContents
|
||||
.executeJavaScript('localStorage.getItem("quality");', true)
|
||||
.then((lastSavedQuality: string | null) => {
|
||||
if (lastSavedQuality !== null) {
|
||||
if (parseInt(lastSavedQuality) === 100) {
|
||||
setQuality(99);
|
||||
} else {
|
||||
setQuality(parseInt(lastSavedQuality));
|
||||
}
|
||||
}
|
||||
});
|
||||
// GET IMAGE QUALITY (NUMBER) TO LOCAL STORAGE
|
||||
mainWindow.webContents
|
||||
.executeJavaScript('localStorage.getItem("overwrite");', true)
|
||||
.then((lastSavedOverwrite: string | null) => {
|
||||
if (lastSavedOverwrite !== null) {
|
||||
console.log("Setting Overwrite: ", lastSavedOverwrite);
|
||||
setOverwrite(lastSavedOverwrite === "true");
|
||||
console.log("Set Overwrite: ", overwrite);
|
||||
}
|
||||
});
|
||||
|
||||
mainWindow.webContents.send(COMMAND.OS, getPlatform());
|
||||
});
|
||||
|
||||
// Quit the app once all windows are closed
|
||||
|
@ -34,89 +34,6 @@ const createMainWindow = () => {
|
||||
});
|
||||
|
||||
mainWindow.setMenuBarVisibility(false);
|
||||
|
||||
const url = electronIsDev
|
||||
? "http://localhost:8000"
|
||||
: (new URL("file:///").pathname = join(
|
||||
__dirname,
|
||||
"../renderer/out/index.html"
|
||||
)).toString();
|
||||
mainWindow.loadURL(url);
|
||||
|
||||
mainWindow.webContents.setWindowOpenHandler(({ url }) => {
|
||||
shell.openExternal(url);
|
||||
return { action: "deny" };
|
||||
});
|
||||
|
||||
mainWindow.once("ready-to-show", () => {
|
||||
if (!mainWindow) return;
|
||||
mainWindow.show();
|
||||
});
|
||||
|
||||
// GET LAST IMAGE PATH TO LOCAL STORAGE
|
||||
mainWindow.webContents
|
||||
.executeJavaScript('localStorage.getItem("lastImagePath");', true)
|
||||
.then((lastImagePath: string | null) => {
|
||||
if (lastImagePath && lastImagePath.length > 0) {
|
||||
setImagePath(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");',
|
||||
true
|
||||
)
|
||||
.then((lastCustomModelsFolderPath: string | null) => {
|
||||
if (lastCustomModelsFolderPath && lastCustomModelsFolderPath.length > 0) {
|
||||
setCustomModelsFolderPath(lastCustomModelsFolderPath);
|
||||
}
|
||||
});
|
||||
// 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);
|
||||
}
|
||||
});
|
||||
// GET LAST SAVE OUTPUT FOLDER (BOOLEAN) TO LOCAL STORAGE
|
||||
mainWindow.webContents
|
||||
.executeJavaScript('localStorage.getItem("rememberOutputFolder");', true)
|
||||
.then((lastSaveOutputFolder: boolean | null) => {
|
||||
if (lastSaveOutputFolder !== null) {
|
||||
setSaveOutputFolder(lastSaveOutputFolder);
|
||||
}
|
||||
});
|
||||
// GET IMAGE QUALITY (NUMBER) TO LOCAL STORAGE
|
||||
mainWindow.webContents
|
||||
.executeJavaScript('localStorage.getItem("quality");', true)
|
||||
.then((lastSavedQuality: string | null) => {
|
||||
if (lastSavedQuality !== null) {
|
||||
if (parseInt(lastSavedQuality) === 100) {
|
||||
setQuality(99);
|
||||
} else {
|
||||
setQuality(parseInt(lastSavedQuality));
|
||||
}
|
||||
}
|
||||
});
|
||||
// GET IMAGE QUALITY (NUMBER) TO LOCAL STORAGE
|
||||
mainWindow.webContents
|
||||
.executeJavaScript('localStorage.getItem("overwrite");', true)
|
||||
.then((lastSavedOverwrite: string | null) => {
|
||||
if (lastSavedOverwrite !== null) {
|
||||
setOverwrite(lastSavedOverwrite === "true");
|
||||
}
|
||||
});
|
||||
mainWindow.webContents.send(COMMAND.OS, getPlatform());
|
||||
};
|
||||
|
||||
const getMainWindow = () => {
|
||||
|
@ -13,6 +13,18 @@ export let childProcesses: {
|
||||
kill: () => boolean;
|
||||
}[] = [];
|
||||
|
||||
console.log({
|
||||
imagePath,
|
||||
folderPath,
|
||||
customModelsFolderPath,
|
||||
outputFolderPath,
|
||||
saveOutputFolder,
|
||||
quality,
|
||||
overwrite,
|
||||
stopped,
|
||||
childProcesses,
|
||||
});
|
||||
|
||||
export function setImagePath(value: string | undefined): void {
|
||||
imagePath = value;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user