1
0
mirror of https://github.com/upscayl/upscayl.git synced 2024-11-23 23:21:05 +01:00

Fix commands

This commit is contained in:
Nayam Amarshe 2023-09-10 23:12:18 +05:30
parent 80ed1516aa
commit c798ffc7db
13 changed files with 203 additions and 219 deletions

View File

@ -1,20 +1,22 @@
import { MessageBoxOptions, dialog } from "electron"; import { MessageBoxOptions, dialog } from "electron";
import mainWindow from "../main-window";
import { import {
getCustomModelsFolderPath, customModelsFolderPath,
setCustomModelsFolderPath, setCustomModelsFolderPath,
} 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";
import COMMAND from "../constants/commands"; import COMMAND from "../constants/commands";
import getModels from "../utils/get-models"; import getModels from "../utils/get-models";
import { getMainWindow } from "../main-window";
const mainWindow = getMainWindow();
const customModelsSelect = async (event, message) => { const customModelsSelect = async (event, message) => {
if (!mainWindow) return; if (!mainWindow) return;
const { canceled, filePaths: folderPaths } = await dialog.showOpenDialog({ const { canceled, filePaths: folderPaths } = await dialog.showOpenDialog({
properties: ["openDirectory"], properties: ["openDirectory"],
title: "Select Custom Models Folder", title: "Select Custom Models Folder",
defaultPath: getCustomModelsFolderPath(), defaultPath: customModelsFolderPath,
}); });
if (canceled) { if (canceled) {
logit("🚫 Select Custom Models Folder Operation Cancelled"); logit("🚫 Select Custom Models Folder Operation Cancelled");
@ -40,11 +42,11 @@ const customModelsSelect = async (event, message) => {
mainWindow.webContents.send( mainWindow.webContents.send(
COMMAND.CUSTOM_MODEL_FILES_LIST, COMMAND.CUSTOM_MODEL_FILES_LIST,
getModels(getCustomModelsFolderPath()) getModels(customModelsFolderPath)
); );
logit("📁 Custom Folder Path: ", getCustomModelsFolderPath()); logit("📁 Custom Folder Path: ", customModelsFolderPath);
return getCustomModelsFolderPath(); return customModelsFolderPath;
} }
}; };

View File

@ -1,18 +1,20 @@
import COMMAND from "../constants/commands"; import COMMAND from "../constants/commands";
import mainWindow from "../main-window"; import { getMainWindow } from "../main-window";
import { import {
getCustomModelsFolderPath, customModelsFolderPath,
setCustomModelsFolderPath, setCustomModelsFolderPath,
} 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";
const mainWindow = getMainWindow();
const getModelsList = async (event, payload) => { const getModelsList = async (event, payload) => {
if (!mainWindow) return; if (!mainWindow) return;
if (payload) { if (payload) {
setCustomModelsFolderPath(payload); setCustomModelsFolderPath(payload);
logit("📁 Custom Models Folder Path: ", getCustomModelsFolderPath()); logit("📁 Custom Models Folder Path: ", customModelsFolderPath);
mainWindow.webContents.send( mainWindow.webContents.send(
COMMAND.CUSTOM_MODEL_FILES_LIST, COMMAND.CUSTOM_MODEL_FILES_LIST,

View File

@ -1,17 +1,16 @@
import fs from "fs"; import fs from "fs";
import { modelsPath } from "../binaries"; import { modelsPath } from "../binaries";
import COMMAND from "../constants/commands"; import COMMAND from "../constants/commands";
import mainWindow from "../main-window";
import { import {
getCustomModelsFolderPath, customModelsFolderPath,
getFolderPath, folderPath,
getOutputFolderPath, outputFolderPath,
getOverwrite, overwrite,
getSaveOutputFolder, saveOutputFolder,
getStop,
setChildProcesses, setChildProcesses,
setOverwrite, setOverwrite,
setStop, setStopped,
stopped,
} from "../utils/config-variables"; } from "../utils/config-variables";
import convertAndScale from "../utils/convert-and-scale"; import convertAndScale from "../utils/convert-and-scale";
import { getSingleImageArguments } from "../utils/get-arguments"; import { getSingleImageArguments } from "../utils/get-arguments";
@ -20,9 +19,20 @@ import slash from "../utils/slash";
import { spawnUpscayl } from "../utils/spawn-upscayl"; 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 stop from "./stop";
const imageUpscayl = async (event, payload) => { const imageUpscayl = async (event, payload) => {
if (!mainWindow) return; const mainWindow = getMainWindow();
if (!mainWindow) {
console.log("No main window");
return;
}
console.log({
overwrite: payload.overwrite,
});
setOverwrite(payload.overwrite); setOverwrite(payload.overwrite);
const model = payload.model as string; const model = payload.model as string;
const gpuId = payload.gpuId as string; const gpuId = payload.gpuId as string;
@ -30,10 +40,10 @@ const imageUpscayl = async (event, payload) => {
let inputDir = (payload.imagePath.match(/(.*)[\/\\]/)[1] || "") as string; let inputDir = (payload.imagePath.match(/(.*)[\/\\]/)[1] || "") as string;
let outputDir: string | undefined = let outputDir: string | undefined =
getFolderPath() || (payload.outputPath as string); folderPath || (payload.outputPath as string);
if (getSaveOutputFolder() === true && getOutputFolderPath()) { if (saveOutputFolder === true && outputFolderPath) {
outputDir = getOutputFolderPath(); outputDir = outputFolderPath;
} }
const isDefaultModel = DEFAULT_MODELS.includes(model); const isDefaultModel = DEFAULT_MODELS.includes(model);
@ -63,6 +73,7 @@ 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) => {
@ -73,7 +84,7 @@ const imageUpscayl = async (event, payload) => {
}); });
// UPSCALE // UPSCALE
if (fs.existsSync(outFile) && getOverwrite() === false) { if (fs.existsSync(outFile) && overwrite === false) {
// 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(
@ -90,7 +101,7 @@ const imageUpscayl = async (event, payload) => {
inputDir, inputDir,
fullfileName, fullfileName,
outFile, outFile,
isDefaultModel ? modelsPath : getCustomModelsFolderPath() ?? modelsPath, isDefaultModel ? modelsPath : customModelsFolderPath ?? modelsPath,
model, model,
scale, scale,
gpuId, gpuId,
@ -101,12 +112,11 @@ const imageUpscayl = async (event, payload) => {
setChildProcesses(upscayl); setChildProcesses(upscayl);
setStop(false); setStopped(false);
let isAlpha = false; let isAlpha = false;
let failed = false; let failed = false;
const onData = (data: string) => { const onData = (data: string) => {
if (!mainWindow) return;
logit("image upscayl: ", data.toString()); logit("image upscayl: ", data.toString());
mainWindow.setProgressBar(parseFloat(data.slice(0, data.length)) / 100); mainWindow.setProgressBar(parseFloat(data.slice(0, data.length)) / 100);
data = data.toString(); data = data.toString();
@ -130,15 +140,13 @@ const imageUpscayl = async (event, payload) => {
return; return;
}; };
const onClose = async () => { const onClose = async () => {
if (!failed && !getStop()) { if (!failed && !stopped) {
logit("💯 Done upscaling"); logit("💯 Done upscaling");
logit("♻ Scaling and converting now..."); logit("♻ Scaling and converting now...");
mainWindow && mainWindow.webContents.send(COMMAND.SCALING_AND_CONVERTING);
mainWindow.webContents.send(COMMAND.SCALING_AND_CONVERTING);
// Free up memory // Free up memory
upscayl.kill(); upscayl.kill();
try { try {
if (!mainWindow) return;
await convertAndScale( await convertAndScale(
inputDir + slash + fullfileName, inputDir + slash + fullfileName,
isAlpha ? outFile + ".png" : outFile, isAlpha ? outFile + ".png" : outFile,
@ -161,11 +169,10 @@ const imageUpscayl = async (event, payload) => {
error error
); );
upscayl.kill(); upscayl.kill();
mainWindow && mainWindow.webContents.send(
mainWindow.webContents.send( COMMAND.UPSCAYL_ERROR,
COMMAND.UPSCAYL_ERROR, "Error processing (scaling and converting) the image. Please report this error on Upscayl GitHub Issues page."
"Error processing (scaling and converting) the image. Please report this error on Upscayl GitHub Issues page." );
);
} }
} }
}; };

View File

@ -1,14 +1,15 @@
import { MessageBoxOptions, dialog } from "electron"; import { MessageBoxOptions, dialog } from "electron";
import mainWindow from "../main-window"; import { getMainWindow } from "../main-window";
import { getImagePath, 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 () => {
if (!mainWindow) return;
const { canceled, filePaths } = await dialog.showOpenDialog({ const { canceled, filePaths } = await dialog.showOpenDialog({
properties: ["openFile", "multiSelections"], properties: ["openFile", "multiSelections"],
title: "Select Image", title: "Select Image",
defaultPath: getImagePath(), defaultPath: imagePath,
}); });
if (canceled) { if (canceled) {
@ -43,6 +44,7 @@ const selectFile = async () => {
message: message:
"The selected file is not a valid image. Make sure you select a '.png', '.jpg', or '.webp' file.", "The selected file is not a valid image. Make sure you select a '.png', '.jpg', or '.webp' file.",
}; };
if (!mainWindow) return null;
dialog.showMessageBoxSync(mainWindow, options); dialog.showMessageBoxSync(mainWindow, options);
return null; return null;
} }

View File

@ -1,11 +1,11 @@
import { dialog } from "electron"; import { dialog } from "electron";
import { getFolderPath, setFolderPath } from "../utils/config-variables"; import { folderPath, setFolderPath } from "../utils/config-variables";
import logit from "../utils/logit"; import logit from "../utils/logit";
const selectFolder = async (event, message) => { const selectFolder = async (event, message) => {
const { canceled, filePaths: folderPaths } = await dialog.showOpenDialog({ const { canceled, filePaths: folderPaths } = await dialog.showOpenDialog({
properties: ["openDirectory"], properties: ["openDirectory"],
defaultPath: getFolderPath(), defaultPath: folderPath,
}); });
if (canceled) { if (canceled) {
@ -13,7 +13,7 @@ const selectFolder = async (event, message) => {
return null; return null;
} else { } else {
setFolderPath(folderPaths[0]); setFolderPath(folderPaths[0]);
logit("📁 Selected Folder Path: ", getFolderPath()); logit("📁 Selected Folder Path: ", folderPath);
return folderPaths[0]; return folderPaths[0];
} }
}; };

View File

@ -1,11 +1,13 @@
import mainWindow from "../main-window"; import { getMainWindow } from "../main-window";
import { getChildProcesses, setStop } 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) => {
setStop(true); setStopped(true);
mainWindow && mainWindow.setProgressBar(-1); mainWindow && mainWindow.setProgressBar(-1);
getChildProcesses().forEach((child) => { childProcesses.forEach((child) => {
logit("🛑 Stopping Upscaling Process", child.process.pid); logit("🛑 Stopping Upscaling Process", child.process.pid);
child.kill(); child.kill();
}); });

View File

@ -1,6 +1,15 @@
import prepareNext from "electron-next";
import { autoUpdater } from "electron-updater"; import { autoUpdater } from "electron-updater";
import log from "electron-log"; import log from "electron-log";
import { app, ipcMain, dialog, MessageBoxOptions } from "electron"; import {
app,
ipcMain,
dialog,
MessageBoxOptions,
shell,
protocol,
net,
} from "electron";
import COMMAND from "./constants/commands"; import COMMAND from "./constants/commands";
import logit from "./utils/logit"; import logit from "./utils/logit";
import openFolder from "./commands/open-folder"; import openFolder from "./commands/open-folder";
@ -10,19 +19,41 @@ import selectFile from "./commands/select-file";
import getModelsList from "./commands/get-models-list"; 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 { setStop } from "./utils/config-variables"; import {
setCustomModelsFolderPath,
setFolderPath,
setImagePath,
setOutputFolderPath,
setQuality,
setSaveOutputFolder,
setStopped,
} from "./utils/config-variables";
import { createMainWindow, getMainWindow } from "./main-window";
import electronIsDev from "electron-is-dev";
import { getPlatform } from "./get-device-specs";
import { join } from "path";
import { execPath, modelsPath } from "./binaries";
// INITIALIZATION // INITIALIZATION
setStop(false);
log.initialize({ preload: true }); log.initialize({ preload: true });
logit("🚃 App Path: ", app.getAppPath());
function escapeRegExp(string) { app.whenReady().then(async () => {
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); // $& means the whole matched string await prepareNext("./renderer");
} createMainWindow();
log.info("🚀 UPSCAYL EXEC PATH: ", execPath("realesrgan"));
log.info("🚀 MODELS PATH: ", modelsPath);
protocol.handle("file:", (request) => {
const pathname = decodeURI(request.url);
return net.fetch(pathname);
});
if (!electronIsDev) {
autoUpdater.checkForUpdates();
}
});
// Quit the app once all windows are closed // Quit the app once all windows are closed
app.on("window-all-closed", app.quit); app.on("window-all-closed", app.quit);
logit("🚃 App Path: ", app.getAppPath());
//------------------------Open Folder-----------------------------// //------------------------Open Folder-----------------------------//
ipcMain.on(COMMAND.OPEN_FOLDER, openFolder); ipcMain.on(COMMAND.OPEN_FOLDER, openFolder);

View File

@ -1,63 +1,46 @@
import prepareNext from "electron-next"; import { BrowserWindow, shell } from "electron";
import { BrowserWindow, app, net, protocol, shell } from "electron";
import COMMAND from "./constants/commands";
import { getPlatform } from "./get-device-specs"; import { getPlatform } from "./get-device-specs";
import { join } from "path"; import { join } from "path";
import { execPath, modelsPath } from "./binaries";
import log from "electron-log";
import isDev from "electron-is-dev";
import { autoUpdater } from "electron-updater";
import { import {
setCustomModelsFolderPath, setCustomModelsFolderPath,
setFolderPath, setFolderPath,
setImagePath, setImagePath,
setOutputFolderPath, setOutputFolderPath,
setOverwrite,
setQuality, setQuality,
setSaveOutputFolder, setSaveOutputFolder,
} from "./utils/config-variables"; } from "./utils/config-variables";
import COMMAND from "./constants/commands";
import electronIsDev from "electron-is-dev";
// Prepare the renderer once the app is ready let mainWindow: BrowserWindow | null;
let _mainWindow: BrowserWindow | null = null;
const getMainWindow = () => { const createMainWindow = () => {
if (!_mainWindow) { mainWindow = new BrowserWindow({
_mainWindow = new BrowserWindow({ icon: join(__dirname, "build", "icon.png"),
icon: join(__dirname, "build", "icon.png"), width: 1300,
width: 1300, height: 940,
height: 940, minHeight: 500,
minHeight: 500, minWidth: 500,
minWidth: 500, show: false,
show: false, backgroundColor: "#171717",
backgroundColor: "#171717", webPreferences: {
webPreferences: { nodeIntegration: true,
nodeIntegration: true, nodeIntegrationInWorker: true,
nodeIntegrationInWorker: true, webSecurity: false,
webSecurity: false, preload: join(__dirname, "preload.js"),
preload: join(__dirname, "preload.js"), },
}, titleBarStyle: getPlatform() === "mac" ? "hiddenInset" : "default",
titleBarStyle: getPlatform() === "mac" ? "hiddenInset" : "default", });
});
}
return _mainWindow; mainWindow.setMenuBarVisibility(false);
};
const mainWindow = getMainWindow(); const url = electronIsDev
app.on("ready", async () => {
await prepareNext("./renderer");
log.info("🚀 UPSCAYL EXEC PATH: ", execPath("realesrgan"));
log.info("🚀 MODELS PATH: ", modelsPath);
const url = isDev
? "http://localhost:8000" ? "http://localhost:8000"
: (new URL("file:///").pathname = join( : (new URL("file:///").pathname = join(
__dirname, __dirname,
"../renderer/out/index.html" "../renderer/out/index.html"
)).toString(); )).toString();
mainWindow.setMenuBarVisibility(false);
mainWindow.loadURL(url); mainWindow.loadURL(url);
mainWindow.webContents.setWindowOpenHandler(({ url }) => { mainWindow.webContents.setWindowOpenHandler(({ url }) => {
@ -68,21 +51,8 @@ app.on("ready", async () => {
mainWindow.once("ready-to-show", () => { mainWindow.once("ready-to-show", () => {
if (!mainWindow) return; if (!mainWindow) return;
mainWindow.show(); mainWindow.show();
mainWindow.webContents.setZoomFactor(1);
}); });
app.whenReady().then(() => {
protocol.handle("file", (request) => {
const pathname = decodeURI(request.url.replace("file:///", ""));
return net.fetch(pathname);
});
});
if (!isDev) {
autoUpdater.checkForUpdates();
}
// <------------------------Save Last Paths----------------------------->
// GET LAST IMAGE PATH TO LOCAL STORAGE // GET LAST IMAGE PATH TO LOCAL STORAGE
mainWindow.webContents mainWindow.webContents
.executeJavaScript('localStorage.getItem("lastImagePath");', true) .executeJavaScript('localStorage.getItem("lastImagePath");', true)
@ -138,7 +108,19 @@ app.on("ready", async () => {
} }
} }
}); });
// 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()); mainWindow.webContents.send(COMMAND.OS, getPlatform());
}); };
export default mainWindow; const getMainWindow = () => {
return mainWindow;
};
export { createMainWindow, getMainWindow };

View File

@ -1,89 +1,49 @@
import { ChildProcessWithoutNullStreams } from "child_process"; import { ChildProcessWithoutNullStreams } from "child_process";
let _imagePath: string | undefined = undefined; export let imagePath: string | undefined = "";
let _folderPath: string | undefined = undefined; export let folderPath: string | undefined = undefined;
let _customModelsFolderPath: string | undefined = undefined; export let customModelsFolderPath: string | undefined = undefined;
let _outputFolderPath: string | undefined = undefined; export let outputFolderPath: string | undefined = undefined;
let _saveOutputFolder = false; export let saveOutputFolder = false;
let _quality = 0; export let quality = 0;
let _overwrite = false; export let overwrite = false;
let _stop = false; export let stopped = false;
let childProcesses: { export let childProcesses: {
process: ChildProcessWithoutNullStreams; process: ChildProcessWithoutNullStreams;
kill: () => boolean; kill: () => boolean;
}[] = []; }[] = [];
// GETTERS
export function getImagePath(): string | undefined {
return _imagePath;
}
export function setImagePath(value: string | undefined): void { export function setImagePath(value: string | undefined): void {
_imagePath = value; imagePath = value;
}
export function getFolderPath(): string | undefined {
return _folderPath;
} }
export function setFolderPath(value: string | undefined): void { export function setFolderPath(value: string | undefined): void {
_folderPath = value; folderPath = value;
}
export function getCustomModelsFolderPath(): string | undefined {
return _customModelsFolderPath;
} }
export function setCustomModelsFolderPath(value: string | undefined): void { export function setCustomModelsFolderPath(value: string | undefined): void {
_customModelsFolderPath = value; customModelsFolderPath = value;
}
export function getOutputFolderPath(): string | undefined {
return _outputFolderPath;
}
export function getStop(): boolean {
return _stop;
}
export function getChildProcesses(): {
process: ChildProcessWithoutNullStreams;
kill: () => boolean;
}[] {
return childProcesses;
} }
// SETTERS // SETTERS
export function setOutputFolderPath(value: string | undefined): void { export function setOutputFolderPath(value: string | undefined): void {
_outputFolderPath = value; outputFolderPath = value;
}
export function getSaveOutputFolder(): boolean {
return _saveOutputFolder;
} }
export function setSaveOutputFolder(value: boolean): void { export function setSaveOutputFolder(value: boolean): void {
_saveOutputFolder = value; saveOutputFolder = value;
}
export function getQuality(): number {
return _quality;
} }
export function setQuality(value: number): void { export function setQuality(value: number): void {
_quality = value; quality = value;
}
export function getOverwrite(): boolean {
return _overwrite;
} }
export function setOverwrite(value: boolean): void { export function setOverwrite(value: boolean): void {
_overwrite = value; overwrite = value;
} }
export function setStop(value: boolean): void { export function setStopped(value: boolean): void {
_stop = value; stopped = value;
} }
export function setChildProcesses(value: { export function setChildProcesses(value: {

View File

@ -1,7 +1,7 @@
import sharp from "sharp"; import sharp from "sharp";
import mainWindow from "../main-window";
import { getQuality } from "./config-variables";
import logit from "./logit"; import logit from "./logit";
import { getMainWindow } from "../main-window";
import { quality } from "./config-variables";
const convertAndScale = async ( const convertAndScale = async (
originalImagePath: string, originalImagePath: string,
@ -11,6 +11,8 @@ const convertAndScale = async (
saveImageAs: string, saveImageAs: string,
onError: (error: any) => void onError: (error: any) => void
) => { ) => {
const mainWindow = getMainWindow();
const originalImage = await sharp(originalImagePath).metadata(); const originalImage = await sharp(originalImagePath).metadata();
if (!mainWindow || !originalImage) { if (!mainWindow || !originalImage) {
throw new Error("Could not grab the original image!"); throw new Error("Could not grab the original image!");
@ -24,10 +26,10 @@ const convertAndScale = async (
.withMetadata(); // Keep metadata .withMetadata(); // Keep metadata
// Change the output according to the saveImageAs // Change the output according to the saveImageAs
if (saveImageAs === "png") { if (saveImageAs === "png") {
newImage.png({ quality: 100 - getQuality() }); newImage.png({ quality: 100 - quality });
} else if (saveImageAs === "jpg") { } else if (saveImageAs === "jpg") {
console.log("Quality: ", getQuality()); console.log("Quality: ", quality);
newImage.jpeg({ quality: 100 - getQuality() }); newImage.jpeg({ quality: 100 - quality });
} }
// Save the image // Save the image
const buffer = await newImage.toBuffer(); const buffer = await newImage.toBuffer();

View File

@ -1,10 +1,11 @@
import Logger from "electron-log"; import log from "electron-log";
import mainWindow from "../main-window";
import COMMAND from "../constants/commands"; import COMMAND from "../constants/commands";
import { getMainWindow } from "../main-window";
const logit = (...args: any) => { const logit = (...args: any) => {
Logger.log(...args); const mainWindow = getMainWindow();
if (!mainWindow) return; if (!mainWindow) return;
log.log(...args);
mainWindow.webContents.send(COMMAND.LOG, args.join(" ")); mainWindow.webContents.send(COMMAND.LOG, args.join(" "));
}; };

View File

@ -20,7 +20,6 @@ const firebaseConfig = {
// Initialize Firebase // Initialize Firebase
const app = initializeApp(firebaseConfig); const app = initializeApp(firebaseConfig);
export const db = getFirestore(app); export const db = getFirestore(app);
console.log("🚀 => file: firebase.ts:23 => db:", db);
const createCollection = <T = DocumentData>(collectionName: string) => { const createCollection = <T = DocumentData>(collectionName: string) => {
return collection(db, collectionName) as CollectionReference<T>; return collection(db, collectionName) as CollectionReference<T>;

View File

@ -1,6 +1,6 @@
"use client"; "use client";
import { useState, useEffect, useCallback } from "react"; import { useState, useEffect, useCallback } from "react";
import commands from "../../electron/constants/commands"; import COMMAND from "../../electron/constants/commands";
import { ReactCompareSlider } from "react-compare-slider"; import { ReactCompareSlider } from "react-compare-slider";
import Header from "../components/Header"; import Header from "../components/Header";
import Footer from "../components/Footer"; import Footer from "../components/Footer";
@ -89,7 +89,7 @@ const Home = () => {
}; };
window.electron.on( window.electron.on(
commands.OS, COMMAND.OS,
(_, data: "linux" | "mac" | "win" | undefined) => { (_, data: "linux" | "mac" | "win" | undefined) => {
if (data) { if (data) {
setOs(data); setOs(data);
@ -98,21 +98,21 @@ const Home = () => {
); );
// LOG // LOG
window.electron.on(commands.LOG, (_, data: string) => { window.electron.on(COMMAND.LOG, (_, data: string) => {
logit(`🐞 BACKEND REPORTED: `, data); logit(`🐞 BACKEND REPORTED: `, data);
}); });
window.electron.on(commands.SCALING_AND_CONVERTING, (_, data: string) => { window.electron.on(COMMAND.SCALING_AND_CONVERTING, (_, data: string) => {
setProgress("Processing the image..."); setProgress("Processing the image...");
}); });
window.electron.on(commands.UPSCAYL_ERROR, (_, data: string) => { window.electron.on(COMMAND.UPSCAYL_ERROR, (_, data: string) => {
alert(data); alert(data);
resetImagePaths(); resetImagePaths();
}); });
// UPSCAYL PROGRESS // UPSCAYL PROGRESS
window.electron.on(commands.UPSCAYL_PROGRESS, (_, data: string) => { window.electron.on(COMMAND.UPSCAYL_PROGRESS, (_, data: string) => {
if (data.length > 0 && data.length < 10) { if (data.length > 0 && data.length < 10) {
setProgress(data); setProgress(data);
} else if (data.includes("converting")) { } else if (data.includes("converting")) {
@ -123,7 +123,7 @@ const Home = () => {
}); });
// FOLDER UPSCAYL PROGRESS // FOLDER UPSCAYL PROGRESS
window.electron.on(commands.FOLDER_UPSCAYL_PROGRESS, (_, data: string) => { window.electron.on(COMMAND.FOLDER_UPSCAYL_PROGRESS, (_, data: string) => {
if (data.length > 0 && data.length < 10) { if (data.length > 0 && data.length < 10) {
setProgress(data); setProgress(data);
} }
@ -132,7 +132,7 @@ const Home = () => {
}); });
// DOUBLE UPSCAYL PROGRESS // DOUBLE UPSCAYL PROGRESS
window.electron.on(commands.DOUBLE_UPSCAYL_PROGRESS, (_, data: string) => { window.electron.on(COMMAND.DOUBLE_UPSCAYL_PROGRESS, (_, data: string) => {
if (data.length > 0 && data.length < 10) { if (data.length > 0 && data.length < 10) {
if (data === "0.00%") { if (data === "0.00%") {
setDoubleUpscaylCounter(doubleUpscaylCounter + 1); setDoubleUpscaylCounter(doubleUpscaylCounter + 1);
@ -144,7 +144,7 @@ const Home = () => {
}); });
// UPSCAYL DONE // UPSCAYL DONE
window.electron.on(commands.UPSCAYL_DONE, (_, data: string) => { window.electron.on(COMMAND.UPSCAYL_DONE, (_, data: string) => {
setProgress(""); setProgress("");
setTimeout(() => setUpscaledImagePath(data), 500); setTimeout(() => setUpscaledImagePath(data), 500);
logit("upscaledImagePath: ", data); logit("upscaledImagePath: ", data);
@ -152,14 +152,14 @@ const Home = () => {
}); });
// FOLDER UPSCAYL DONE // FOLDER UPSCAYL DONE
window.electron.on(commands.FOLDER_UPSCAYL_DONE, (_, data: string) => { window.electron.on(COMMAND.FOLDER_UPSCAYL_DONE, (_, data: string) => {
setProgress(""); setProgress("");
setUpscaledBatchFolderPath(data); setUpscaledBatchFolderPath(data);
logit(`💯 FOLDER_UPSCAYL_DONE: `, data); logit(`💯 FOLDER_UPSCAYL_DONE: `, data);
}); });
// DOUBLE UPSCAYL DONE // DOUBLE UPSCAYL DONE
window.electron.on(commands.DOUBLE_UPSCAYL_DONE, (_, data: string) => { window.electron.on(COMMAND.DOUBLE_UPSCAYL_DONE, (_, data: string) => {
setProgress(""); setProgress("");
setDoubleUpscaylCounter(0); setDoubleUpscaylCounter(0);
setUpscaledImagePath(data); setUpscaledImagePath(data);
@ -167,27 +167,24 @@ const Home = () => {
}); });
// CUSTOM FOLDER LISTENER // CUSTOM FOLDER LISTENER
window.electron.on( window.electron.on(COMMAND.CUSTOM_MODEL_FILES_LIST, (_, data: string[]) => {
commands.CUSTOM_MODEL_FILES_LIST, logit(`📜 CUSTOM_MODEL_FILES_LIST: `, data);
(_, data: string[]) => { const newModelOptions = data.map((model) => {
logit(`📜 CUSTOM_MODEL_FILES_LIST: `, data); return {
const newModelOptions = data.map((model) => { value: model,
return { label: model,
value: model, };
label: model, });
};
});
// Add newModelsList to modelOptions and remove duplicates // Add newModelsList to modelOptions and remove duplicates
const combinedModelOptions = [...modelOptions, ...newModelOptions]; const combinedModelOptions = [...modelOptions, ...newModelOptions];
const uniqueModelOptions = combinedModelOptions.filter( const uniqueModelOptions = combinedModelOptions.filter(
// Check if any model in the array appears more than once // Check if any model in the array appears more than once
(model, index, array) => (model, index, array) =>
array.findIndex((t) => t.value === model.value) === index array.findIndex((t) => t.value === model.value) === index
); );
setModelOptions(uniqueModelOptions); setModelOptions(uniqueModelOptions);
} });
);
if (!localStorage.getItem("upscaylCloudModalShown")) { if (!localStorage.getItem("upscaylCloudModalShown")) {
logit("⚙️ upscayl cloud show to true"); logit("⚙️ upscayl cloud show to true");
localStorage.setItem("upscaylCloudModalShown", "true"); localStorage.setItem("upscaylCloudModalShown", "true");
@ -201,7 +198,7 @@ const Home = () => {
); );
if (customModelsPath !== null) { if (customModelsPath !== null) {
window.electron.send(commands.GET_MODELS_LIST, customModelsPath); window.electron.send(COMMAND.GET_MODELS_LIST, customModelsPath);
logit("🎯 GET_MODELS_LIST: ", customModelsPath); logit("🎯 GET_MODELS_LIST: ", customModelsPath);
} }
}, []); }, []);
@ -267,7 +264,7 @@ const Home = () => {
const selectImageHandler = async () => { const selectImageHandler = async () => {
resetImagePaths(); resetImagePaths();
var path = await window.electron.invoke(commands.SELECT_FILE); var path = await window.electron.invoke(COMMAND.SELECT_FILE);
if (path !== null) { if (path !== null) {
logit("🖼 Selected Image Path: ", path); logit("🖼 Selected Image Path: ", path);
@ -281,7 +278,7 @@ const Home = () => {
const selectFolderHandler = async () => { const selectFolderHandler = async () => {
resetImagePaths(); resetImagePaths();
var path = await window.electron.invoke(commands.SELECT_FOLDER); var path = await window.electron.invoke(COMMAND.SELECT_FOLDER);
if (path !== null) { if (path !== null) {
logit("🖼 Selected Folder Path: ", path); logit("🖼 Selected Folder Path: ", path);
@ -319,7 +316,7 @@ const Home = () => {
const openFolderHandler = (e) => { const openFolderHandler = (e) => {
logit("📂 OPEN_FOLDER: ", upscaledBatchFolderPath); logit("📂 OPEN_FOLDER: ", upscaledBatchFolderPath);
window.electron.send(commands.OPEN_FOLDER, upscaledBatchFolderPath); window.electron.send(COMMAND.OPEN_FOLDER, upscaledBatchFolderPath);
}; };
const handleDrop = (e) => { const handleDrop = (e) => {
@ -380,7 +377,7 @@ const Home = () => {
}; };
const outputHandler = async () => { const outputHandler = async () => {
var path = await window.electron.invoke(commands.SELECT_FOLDER); var path = await window.electron.invoke(COMMAND.SELECT_FOLDER);
if (path !== null) { if (path !== null) {
logit("🗂 Setting Output Path: ", path); logit("🗂 Setting Output Path: ", path);
setOutputPath(path); setOutputPath(path);
@ -405,7 +402,7 @@ const Home = () => {
setProgress("Hold on..."); setProgress("Hold on...");
if (doubleUpscayl) { if (doubleUpscayl) {
window.electron.send(commands.DOUBLE_UPSCAYL, { window.electron.send(COMMAND.DOUBLE_UPSCAYL, {
imagePath, imagePath,
outputPath, outputPath,
model, model,
@ -416,7 +413,7 @@ const Home = () => {
logit("🏁 DOUBLE_UPSCAYL"); logit("🏁 DOUBLE_UPSCAYL");
} else if (batchMode) { } else if (batchMode) {
setDoubleUpscayl(false); setDoubleUpscayl(false);
window.electron.send(commands.FOLDER_UPSCAYL, { window.electron.send(COMMAND.FOLDER_UPSCAYL, {
scaleFactor, scaleFactor,
batchFolderPath, batchFolderPath,
outputPath, outputPath,
@ -427,7 +424,7 @@ const Home = () => {
}); });
logit("🏁 FOLDER_UPSCAYL"); logit("🏁 FOLDER_UPSCAYL");
} else { } else {
window.electron.send(commands.UPSCAYL, { window.electron.send(COMMAND.UPSCAYL, {
scaleFactor, scaleFactor,
imagePath, imagePath,
outputPath, outputPath,
@ -457,7 +454,7 @@ const Home = () => {
}; };
const stopHandler = () => { const stopHandler = () => {
window.electron.send(commands.STOP); window.electron.send(COMMAND.STOP);
logit("🛑 Stopping Upscayl"); logit("🛑 Stopping Upscayl");
resetImagePaths(); resetImagePaths();
}; };
@ -588,10 +585,7 @@ const Home = () => {
hideZoomOptions={true} hideZoomOptions={true}
/> />
<img <img
src={ src={`file:///${imagePath}`}
"file://" +
`${upscaledImagePath ? upscaledImagePath : imagePath}`
}
onLoad={(e: any) => { onLoad={(e: any) => {
setDimensions({ setDimensions({
width: e.target.naturalWidth, width: e.target.naturalWidth,