mirror of
https://github.com/upscayl/upscayl.git
synced 2024-11-12 01:40:53 +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 getModels from "../utils/get-models";
|
||||||
import { getMainWindow } from "../main-window";
|
import { getMainWindow } from "../main-window";
|
||||||
|
|
||||||
const mainWindow = getMainWindow();
|
|
||||||
|
|
||||||
const customModelsSelect = async (event, message) => {
|
const customModelsSelect = async (event, message) => {
|
||||||
|
const mainWindow = getMainWindow();
|
||||||
|
|
||||||
if (!mainWindow) return;
|
if (!mainWindow) return;
|
||||||
const { canceled, filePaths: folderPaths } = await dialog.showOpenDialog({
|
const { canceled, filePaths: folderPaths } = await dialog.showOpenDialog({
|
||||||
properties: ["openDirectory"],
|
properties: ["openDirectory"],
|
||||||
|
@ -7,9 +7,9 @@ import {
|
|||||||
import getModels from "../utils/get-models";
|
import getModels from "../utils/get-models";
|
||||||
import logit from "../utils/logit";
|
import logit from "../utils/logit";
|
||||||
|
|
||||||
const mainWindow = getMainWindow();
|
|
||||||
|
|
||||||
const getModelsList = async (event, payload) => {
|
const getModelsList = async (event, payload) => {
|
||||||
|
const mainWindow = getMainWindow();
|
||||||
|
|
||||||
if (!mainWindow) return;
|
if (!mainWindow) return;
|
||||||
if (payload) {
|
if (payload) {
|
||||||
setCustomModelsFolderPath(payload);
|
setCustomModelsFolderPath(payload);
|
||||||
|
@ -20,7 +20,6 @@ import { spawnUpscayl } from "../utils/spawn-upscayl";
|
|||||||
import { parse } from "path";
|
import { parse } from "path";
|
||||||
import DEFAULT_MODELS from "../constants/models";
|
import DEFAULT_MODELS from "../constants/models";
|
||||||
import { getMainWindow } from "../main-window";
|
import { getMainWindow } from "../main-window";
|
||||||
import stop from "./stop";
|
|
||||||
|
|
||||||
const imageUpscayl = async (event, payload) => {
|
const imageUpscayl = async (event, payload) => {
|
||||||
const mainWindow = getMainWindow();
|
const mainWindow = getMainWindow();
|
||||||
@ -73,18 +72,18 @@ const imageUpscayl = async (event, payload) => {
|
|||||||
saveImageAs;
|
saveImageAs;
|
||||||
|
|
||||||
// GET OVERWRITE SETTINGS FROM LOCAL STORAGE
|
// GET OVERWRITE SETTINGS FROM LOCAL STORAGE
|
||||||
|
|
||||||
mainWindow.webContents
|
mainWindow.webContents
|
||||||
.executeJavaScript('localStorage.getItem("overwrite");', true)
|
.executeJavaScript('localStorage.getItem("overwrite");', true)
|
||||||
.then((lastSavedOverwrite: boolean | null) => {
|
.then((lastSavedOverwrite: boolean | null) => {
|
||||||
if (lastSavedOverwrite !== null) {
|
if (lastSavedOverwrite !== null) {
|
||||||
console.log("Overwrite: ", lastSavedOverwrite);
|
console.log("Overwrite: ", lastSavedOverwrite);
|
||||||
setOverwrite(lastSavedOverwrite);
|
setOverwrite(lastSavedOverwrite);
|
||||||
|
console.log("NEW OVERWRITE: ", overwrite);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// UPSCALE
|
// UPSCALE
|
||||||
if (fs.existsSync(outFile) && overwrite === false) {
|
if (fs.existsSync(outFile) && !overwrite) {
|
||||||
// If already upscayled, just output that file
|
// If already upscayled, just output that file
|
||||||
logit("✅ Already upscayled at: ", outFile);
|
logit("✅ Already upscayled at: ", outFile);
|
||||||
mainWindow.webContents.send(
|
mainWindow.webContents.send(
|
||||||
|
@ -3,9 +3,9 @@ import { getMainWindow } from "../main-window";
|
|||||||
import { imagePath, setImagePath } from "../utils/config-variables";
|
import { imagePath, setImagePath } from "../utils/config-variables";
|
||||||
import logit from "../utils/logit";
|
import logit from "../utils/logit";
|
||||||
|
|
||||||
const mainWindow = getMainWindow();
|
|
||||||
|
|
||||||
const selectFile = async () => {
|
const selectFile = async () => {
|
||||||
|
const mainWindow = getMainWindow();
|
||||||
|
|
||||||
const { canceled, filePaths } = await dialog.showOpenDialog({
|
const { canceled, filePaths } = await dialog.showOpenDialog({
|
||||||
properties: ["openFile", "multiSelections"],
|
properties: ["openFile", "multiSelections"],
|
||||||
title: "Select Image",
|
title: "Select Image",
|
||||||
|
@ -2,9 +2,9 @@ import { getMainWindow } from "../main-window";
|
|||||||
import { childProcesses, setStopped } from "../utils/config-variables";
|
import { childProcesses, setStopped } from "../utils/config-variables";
|
||||||
import logit from "../utils/logit";
|
import logit from "../utils/logit";
|
||||||
|
|
||||||
const mainWindow = getMainWindow();
|
|
||||||
|
|
||||||
const stop = async (event, payload) => {
|
const stop = async (event, payload) => {
|
||||||
|
const mainWindow = getMainWindow();
|
||||||
|
|
||||||
setStopped(true);
|
setStopped(true);
|
||||||
mainWindow && mainWindow.setProgressBar(-1);
|
mainWindow && mainWindow.setProgressBar(-1);
|
||||||
childProcesses.forEach((child) => {
|
childProcesses.forEach((child) => {
|
||||||
|
@ -20,10 +20,12 @@ import getModelsList from "./commands/get-models-list";
|
|||||||
import customModelsSelect from "./commands/custom-models-select";
|
import customModelsSelect from "./commands/custom-models-select";
|
||||||
import imageUpscayl from "./commands/image-upscayl";
|
import imageUpscayl from "./commands/image-upscayl";
|
||||||
import {
|
import {
|
||||||
|
overwrite,
|
||||||
setCustomModelsFolderPath,
|
setCustomModelsFolderPath,
|
||||||
setFolderPath,
|
setFolderPath,
|
||||||
setImagePath,
|
setImagePath,
|
||||||
setOutputFolderPath,
|
setOutputFolderPath,
|
||||||
|
setOverwrite,
|
||||||
setQuality,
|
setQuality,
|
||||||
setSaveOutputFolder,
|
setSaveOutputFolder,
|
||||||
setStopped,
|
setStopped,
|
||||||
@ -50,6 +52,99 @@ app.whenReady().then(async () => {
|
|||||||
if (!electronIsDev) {
|
if (!electronIsDev) {
|
||||||
autoUpdater.checkForUpdates();
|
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
|
// Quit the app once all windows are closed
|
||||||
|
@ -34,89 +34,6 @@ const createMainWindow = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
mainWindow.setMenuBarVisibility(false);
|
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 = () => {
|
const getMainWindow = () => {
|
||||||
|
@ -13,6 +13,18 @@ export let childProcesses: {
|
|||||||
kill: () => boolean;
|
kill: () => boolean;
|
||||||
}[] = [];
|
}[] = [];
|
||||||
|
|
||||||
|
console.log({
|
||||||
|
imagePath,
|
||||||
|
folderPath,
|
||||||
|
customModelsFolderPath,
|
||||||
|
outputFolderPath,
|
||||||
|
saveOutputFolder,
|
||||||
|
quality,
|
||||||
|
overwrite,
|
||||||
|
stopped,
|
||||||
|
childProcesses,
|
||||||
|
});
|
||||||
|
|
||||||
export function setImagePath(value: string | undefined): void {
|
export function setImagePath(value: string | undefined): void {
|
||||||
imagePath = value;
|
imagePath = value;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user