From f43b7e53db362ee870f94f8714598b7e104c09c6 Mon Sep 17 00:00:00 2001 From: Nayam Amarshe <25067102+NayamAmarshe@users.noreply.github.com> Date: Thu, 10 Aug 2023 15:14:44 +0530 Subject: [PATCH] Revert Refactor --- electron/index.ts | 566 ++++++++++++++++-- electron/utils/listener/customModelsSelect.ts | 61 -- electron/utils/listener/doubleUpscayl.ts | 198 ------ electron/utils/listener/folderUpscayl.ts | 106 ---- electron/utils/listener/getModelsList.ts | 29 - electron/utils/listener/imageUpscayl.ts | 162 ----- electron/utils/listener/selectFile.ts | 59 -- electron/utils/listener/selectFolder.ts | 25 - main/utils/listener/customModelsSelect.js | 48 ++ main/utils/listener/doubleUpscayl.js | 4 +- main/utils/listener/folderUpscayl.js | 3 +- main/utils/listener/getModelsList.js | 26 + main/utils/listener/imageUpscayl.js | 118 ++++ main/utils/listener/selectFile.js | 61 ++ main/utils/listener/selectFolder.js | 34 ++ renderer/components/Footer.tsx | 11 +- .../upscayl-tab/view/ImageOptions.tsx | 2 +- 17 files changed, 793 insertions(+), 720 deletions(-) delete mode 100644 electron/utils/listener/customModelsSelect.ts delete mode 100644 electron/utils/listener/doubleUpscayl.ts delete mode 100644 electron/utils/listener/folderUpscayl.ts delete mode 100644 electron/utils/listener/getModelsList.ts delete mode 100644 electron/utils/listener/imageUpscayl.ts delete mode 100644 electron/utils/listener/selectFile.ts delete mode 100644 electron/utils/listener/selectFolder.ts create mode 100644 main/utils/listener/customModelsSelect.js create mode 100644 main/utils/listener/getModelsList.js create mode 100644 main/utils/listener/imageUpscayl.js create mode 100644 main/utils/listener/selectFile.js create mode 100644 main/utils/listener/selectFolder.js diff --git a/electron/index.ts b/electron/index.ts index 282939b..357b9a7 100644 --- a/electron/index.ts +++ b/electron/index.ts @@ -1,7 +1,7 @@ // Native import { autoUpdater } from "electron-updater"; import getPlatform from "./getPlatform"; -import { join } from "path"; +import { join, parse } from "path"; import log from "electron-log"; import { format } from "url"; import fs from "fs"; @@ -22,13 +22,14 @@ import prepareNext from "electron-next"; import isDev from "electron-is-dev"; import commands from "./commands"; import { ChildProcessWithoutNullStreams } from "child_process"; -import doubleUpscayl from "./utils/listener/doubleUpscayl"; -import folderUpscayl from "./utils/listener/folderUpscayl"; -import imageUpscayl from "./utils/listener/imageUpscayl"; -import customModelsSelect from "./utils/listener/customModelsSelect"; -import getModelsList from "./utils/listener/getModelsList"; -import selectFile from "./utils/listener/selectFile"; -import selectFolder from "./utils/listener/selectFolder"; +import { + getBatchArguments, + getDoubleUpscaleArguments, + getDoubleUpscaleSecondPassArguments, + getSingleImageArguments, +} from "./utils/getArguments"; +import { spawnUpscayl } from "./upscayl"; +import Jimp from "jimp"; let childProcesses: { process: ChildProcessWithoutNullStreams; @@ -241,68 +242,501 @@ ipcMain.on(commands.STOP, async (event, payload) => { }); }); -if (mainWindow) { - selectFolder({ - folderPath, - logit, +//------------------------Select Folder-----------------------------// +ipcMain.handle(commands.SELECT_FOLDER, async (event, message) => { + const { canceled, filePaths: folderPaths } = await dialog.showOpenDialog({ + properties: ["openDirectory"], + defaultPath: folderPath, }); - selectFile({ - mainWindow, - imagePath, - logit, + + if (canceled) { + logit("🚫 Select Folder Operation Cancelled"); + return null; + } else { + folderPath = folderPaths[0]; + logit("📁 Selected Folder Path: ", folderPath); + return folderPaths[0]; + } +}); + +//------------------------Select File-----------------------------// +ipcMain.handle(commands.SELECT_FILE, async () => { + if (!mainWindow) return; + const { canceled, filePaths } = await dialog.showOpenDialog({ + properties: ["openFile", "multiSelections"], + title: "Select Image", + defaultPath: imagePath, }); - getModelsList({ - mainWindow, - customModelsFolderPath, - logit, - getModels, + + if (canceled) { + logit("🚫 File Operation Cancelled"); + return null; + } else { + imagePath = filePaths[0]; + + let isValid = false; + // READ SELECTED FILES + filePaths.forEach((file) => { + // log.log("Files in Folder: ", file); + if ( + file.endsWith(".png") || + file.endsWith(".jpg") || + file.endsWith(".jpeg") || + file.endsWith(".webp") || + file.endsWith(".JPG") || + file.endsWith(".PNG") || + file.endsWith(".JPEG") || + file.endsWith(".WEBP") + ) { + isValid = true; + } + }); + + if (!isValid) { + logit("❌ Invalid File Detected"); + const options: MessageBoxOptions = { + type: "error", + title: "Invalid File", + message: + "The selected file is not a valid image. Make sure you select a '.png', '.jpg', or '.webp' file.", + }; + dialog.showMessageBoxSync(mainWindow, options); + return null; + } + + logit("📄 Selected File Path: ", filePaths[0]); + // CREATE input AND upscaled FOLDER + return filePaths[0]; + } +}); + +//------------------------Get Models List-----------------------------// +ipcMain.on(commands.GET_MODELS_LIST, async (event, payload) => { + if (!mainWindow) return; + if (payload) { + customModelsFolderPath = payload; + + logit("📁 Custom Models Folder Path: ", customModelsFolderPath); + + mainWindow.webContents.send( + commands.CUSTOM_MODEL_FILES_LIST, + getModels(payload) + ); + } +}); + +//------------------------Custom Models Select-----------------------------// +ipcMain.handle(commands.SELECT_CUSTOM_MODEL_FOLDER, async (event, message) => { + if (!mainWindow) return; + const { canceled, filePaths: folderPaths } = await dialog.showOpenDialog({ + properties: ["openDirectory"], + title: "Select Custom Models Folder", + defaultPath: customModelsFolderPath, }); - customModelsSelect({ - mainWindow, - customModelsFolderPath, - logit, - slash, - getModels, + if (canceled) { + logit("🚫 Select Custom Models Folder Operation Cancelled"); + return null; + } else { + customModelsFolderPath = folderPaths[0]; + + if ( + !folderPaths[0].endsWith(slash + "models") && + !folderPaths[0].endsWith(slash + "models" + slash) + ) { + logit("❌ Invalid Custom Models Folder Detected: Not a 'models' folder"); + const options: MessageBoxOptions = { + type: "error", + title: "Invalid Folder", + message: + "Please make sure that the folder name is 'models' and nothing else.", + buttons: ["OK"], + }; + dialog.showMessageBoxSync(options); + return null; + } + + mainWindow.webContents.send( + commands.CUSTOM_MODEL_FILES_LIST, + getModels(customModelsFolderPath) + ); + + logit("📁 Custom Folder Path: ", customModelsFolderPath); + return customModelsFolderPath; + } +}); + +//------------------------Image Upscayl-----------------------------// +ipcMain.on(commands.UPSCAYL, async (event, payload) => { + if (!mainWindow) return; + const model = payload.model as string; + const gpuId = payload.gpuId as string; + const saveImageAs = payload.saveImageAs as string; + + let inputDir = (payload.imagePath.match(/(.*)[\/\\]/)[1] || "") as string; + let outputDir = folderPath || (payload.outputPath as string); + + if (saveOutputFolder === true && outputFolderPath) { + outputDir = outputFolderPath; + } + + const isDefaultModel = defaultModels.includes(model); + + const fullfileName = payload.imagePath.replace(/^.*[\\\/]/, "") as string; + const fileName = parse(fullfileName).name; + const fileExt = parse(fullfileName).ext; + + let scale = "4"; + if (model.includes("x2")) { + scale = "2"; + } else if (model.includes("x3")) { + scale = "3"; + } else { + scale = "4"; + } + + const outFile = + outputDir + + slash + + fileName + + "_upscayl_" + + payload.scale + + "x_" + + model + + "." + + saveImageAs; + + // UPSCALE + if (fs.existsSync(outFile)) { + // If already upscayled, just output that file + logit("✅ Already upscayled at: ", outFile); + mainWindow.webContents.send(commands.UPSCAYL_DONE, outFile); + } else { + const upscayl = spawnUpscayl( + "realesrgan", + getSingleImageArguments( + inputDir, + fullfileName, + outFile, + isDefaultModel ? modelsPath : customModelsFolderPath ?? modelsPath, + model, + scale, + gpuId, + saveImageAs + ), + logit + ); + + childProcesses.push(upscayl); + + stopped = false; + let isAlpha = false; + let failed = false; + + const onData = (data: string) => { + if (!mainWindow) return; + logit("image upscayl: ", data.toString()); + mainWindow.setProgressBar(parseFloat(data.slice(0, data.length)) / 100); + data = data.toString(); + mainWindow.webContents.send(commands.UPSCAYL_PROGRESS, data.toString()); + if (data.includes("invalid gpu") || data.includes("failed")) { + logit("❌ INVALID GPU OR FAILED"); + failed = true; + } + if (data.includes("has alpha channel")) { + logit("📢 INCLUDES ALPHA CHANNEL, CHANGING OUTFILE NAME!"); + isAlpha = true; + } + }; + const onError = (data) => { + if (!mainWindow) return; + mainWindow.webContents.send(commands.UPSCAYL_PROGRESS, data.toString()); + failed = true; + return; + }; + const onClose = async () => { + if (!failed && !stopped) { + logit("💯 Done upscaling"); + logit("♻ Scaling and converting now..."); + const originalImage = await Jimp.read(inputDir + slash + fullfileName); + try { + const newImage = await Jimp.read( + isAlpha ? outFile + ".png" : outFile + ); + try { + if (!mainWindow) return; + newImage + .scaleToFit( + originalImage.getWidth() * parseInt(payload.scale), + originalImage.getHeight() * parseInt(payload.scale) + ) + .quality(100 - quality) + .write(isAlpha ? outFile + ".png" : outFile); + mainWindow.setProgressBar(-1); + mainWindow.webContents.send( + commands.UPSCAYL_DONE, + isAlpha ? outFile + ".png" : outFile + ); + } catch (error) { + logit("❌ Error converting to PNG: ", error); + onError(error); + } + } catch (error) { + logit("❌ Error reading original image metadata", error); + onError(error); + } + } + }; + + upscayl.process.stderr.on("data", onData); + upscayl.process.on("error", onError); + upscayl.process.on("close", onClose); + } +}); + +//------------------------Folder Upscayl-----------------------------// +ipcMain.on(commands.FOLDER_UPSCAYL, async (event, payload) => { + if (!mainWindow) return; + // GET THE MODEL + const model = payload.model; + const gpuId = payload.gpuId; + const saveImageAs = payload.saveImageAs; + const scale = payload.scale as string; + + // GET THE IMAGE DIRECTORY + let inputDir = payload.batchFolderPath; + // GET THE OUTPUT DIRECTORY + let outputDir = payload.outputPath; + + if (saveOutputFolder === true && outputFolderPath) { + outputDir = outputFolderPath; + } + + if (!fs.existsSync(outputDir)) { + fs.mkdirSync(outputDir, { recursive: true }); + } + + const isDefaultModel = defaultModels.includes(model); + + // UPSCALE + const upscayl = spawnUpscayl( + "realesrgan", + getBatchArguments( + inputDir, + outputDir, + isDefaultModel ? modelsPath : customModelsFolderPath ?? modelsPath, + model, + gpuId, + saveImageAs, + scale + ), + logit + ); + + childProcesses.push(upscayl); + + stopped = false; + let failed = false; + + const onData = (data: any) => { + if (!mainWindow) return; + data = data.toString(); + mainWindow.webContents.send( + commands.FOLDER_UPSCAYL_PROGRESS, + data.toString() + ); + if (data.includes("invalid gpu") || data.includes("failed")) { + logit("❌ INVALID GPU OR INVALID FILES IN FOLDER - FAILED"); + failed = true; + upscayl.kill(); + } + }; + const onError = (data: any) => { + if (!mainWindow) return; + mainWindow.webContents.send( + commands.FOLDER_UPSCAYL_PROGRESS, + data.toString() + ); + failed = true; + upscayl.kill(); + return; + }; + const onClose = () => { + if (!mainWindow) return; + if (!failed && !stopped) { + logit("💯 Done upscaling"); + mainWindow.webContents.send(commands.FOLDER_UPSCAYL_DONE, outputDir); + } else { + upscayl.kill(); + } + }; + + upscayl.process.stderr.on("data", onData); + upscayl.process.on("error", onError); + upscayl.process.on("close", onClose); +}); + +//------------------------Double Upscayl-----------------------------// +ipcMain.on(commands.DOUBLE_UPSCAYL, async (event, payload) => { + if (!mainWindow) return; + + const model = payload.model as string; + let inputDir = (payload.imagePath.match(/(.*)[\/\\]/)[1] || "") as string; + let outputDir = payload.outputPath as string; + + if (saveOutputFolder === true && outputFolderPath) { + outputDir = outputFolderPath; + } + const gpuId = payload.gpuId as string; + const saveImageAs = payload.saveImageAs as string; + + const isDefaultModel = defaultModels.includes(model); + + // COPY IMAGE TO TMP FOLDER + + const fullfileName = payload.imagePath.split(slash).slice(-1)[0] as string; + const fileName = parse(fullfileName).name; + const outFile = + outputDir + slash + fileName + "_upscayl_16x_" + model + "." + saveImageAs; + + let scale = "4"; + if (model.includes("x2")) { + scale = "2"; + } else if (model.includes("x3")) { + scale = "3"; + } else { + scale = "4"; + } + + // UPSCALE + let upscayl = spawnUpscayl( + "realesrgan", + getDoubleUpscaleArguments( + inputDir, + fullfileName, + outFile, + isDefaultModel ? modelsPath : customModelsFolderPath ?? modelsPath, + model, + gpuId, + saveImageAs, + scale + ), + logit + ); + + childProcesses.push(upscayl); + + stopped = false; + let failed = false; + let isAlpha = false; + let failed2 = false; + + const onData = (data) => { + if (!mainWindow) return; + // CONVERT DATA TO STRING + data = data.toString(); + // SEND UPSCAYL PROGRESS TO RENDERER + mainWindow.webContents.send(commands.DOUBLE_UPSCAYL_PROGRESS, data); + // IF PROGRESS HAS ERROR, UPSCAYL FAILED + if (data.includes("invalid gpu") || data.includes("failed")) { + failed = true; + } + if (data.includes("has alpha channel")) { + isAlpha = true; + } + }; + + const onError = (data) => { + if (!mainWindow) return; + data.toString(); + // SEND UPSCAYL PROGRESS TO RENDERER + mainWindow.webContents.send(commands.DOUBLE_UPSCAYL_PROGRESS, data); + // SET FAILED TO TRUE + failed = true; + return; + }; + + const onData2 = (data) => { + if (!mainWindow) return; + // CONVERT DATA TO STRING + data = data.toString(); + // SEND UPSCAYL PROGRESS TO RENDERER + mainWindow.webContents.send(commands.DOUBLE_UPSCAYL_PROGRESS, data); + // IF PROGRESS HAS ERROR, UPSCAYL FAILED + if (data.includes("invalid gpu") || data.includes("failed")) { + failed2 = true; + } + }; + + const onError2 = (data) => { + if (!mainWindow) return; + data.toString(); + // SEND UPSCAYL PROGRESS TO RENDERER + mainWindow.webContents.send(commands.DOUBLE_UPSCAYL_PROGRESS, data); + // SET FAILED TO TRUE + failed2 = true; + return; + }; + + const onClose2 = async (code) => { + if (!mainWindow) return; + if (!failed2 && !stopped) { + logit("💯 Done upscaling"); + logit("♻ Scaling and converting now..."); + const originalImage = await Jimp.read(inputDir + slash + fullfileName); + try { + const newImage = await Jimp.read(isAlpha ? outFile + ".png" : outFile); + try { + newImage + .scaleToFit( + originalImage.getWidth() * parseInt(payload.scale), + originalImage.getHeight() * parseInt(payload.scale) + ) + .quality(100 - quality) + .write(isAlpha ? outFile + ".png" : outFile); + mainWindow.setProgressBar(-1); + mainWindow.webContents.send( + commands.DOUBLE_UPSCAYL_DONE, + isAlpha ? outFile + ".png" : outFile + ); + } catch (error) { + logit("❌ Error converting to PNG: ", error); + onError(error); + } + } catch (error) { + logit("❌ Error reading original image metadata", error); + onError(error); + } + } + }; + + upscayl.process.stderr.on("data", onData); + upscayl.process.on("error", onError); + upscayl.process.on("close", (code) => { + // IF NOT FAILED + if (!failed && !stopped) { + // UPSCALE + let upscayl2 = spawnUpscayl( + "realesrgan", + getDoubleUpscaleSecondPassArguments( + isAlpha, + outFile, + isDefaultModel ? modelsPath : customModelsFolderPath ?? modelsPath, + model, + gpuId, + saveImageAs, + scale + ), + logit + ); + + childProcesses.push(upscayl2); + + upscayl2.process.stderr.on("data", onData2); + upscayl2.process.on("error", onError2); + upscayl2.process.on("close", onClose2); + } }); - imageUpscayl({ - mainWindow, - slash, - logit, - childProcesses, - stopped, - modelsPath, - customModelsFolderPath, - saveOutputFolder, - outputFolderPath, - quality, - defaultModels, - folderPath, - }); - folderUpscayl({ - mainWindow, - logit, - childProcesses, - stopped, - modelsPath, - customModelsFolderPath, - saveOutputFolder, - outputFolderPath, - defaultModels, - }); - doubleUpscayl({ - mainWindow, - slash, - logit, - childProcesses, - stopped, - modelsPath, - customModelsFolderPath, - saveOutputFolder, - outputFolderPath, - quality, - defaultModels, - }); -} +}); //------------------------Auto-Update Code-----------------------------// autoUpdater.autoInstallOnAppQuit = false; diff --git a/electron/utils/listener/customModelsSelect.ts b/electron/utils/listener/customModelsSelect.ts deleted file mode 100644 index 028a5c5..0000000 --- a/electron/utils/listener/customModelsSelect.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { MessageBoxOptions, dialog, ipcMain } from "electron"; -import commands from "../../commands"; - -export type CustomModelsSelectProps = { - mainWindow: Electron.BrowserWindow; - customModelsFolderPath: string | undefined; - logit: (message: string, ...optionalParams: any[]) => void; - slash: string; - getModels: (folderPath: string) => string[] | null; -}; - -export default function ({ - mainWindow, - customModelsFolderPath, - logit, - slash, - getModels, -}: CustomModelsSelectProps) { - ipcMain.handle( - commands.SELECT_CUSTOM_MODEL_FOLDER, - async (event, message) => { - const { canceled, filePaths: folderPaths } = await dialog.showOpenDialog({ - properties: ["openDirectory"], - title: "Select Custom Models Folder", - defaultPath: customModelsFolderPath, - }); - if (canceled) { - logit("🚫 Select Custom Models Folder Operation Cancelled"); - return null; - } else { - customModelsFolderPath = folderPaths[0]; - - if ( - !folderPaths[0].endsWith(slash + "models") && - !folderPaths[0].endsWith(slash + "models" + slash) - ) { - logit( - "❌ Invalid Custom Models Folder Detected: Not a 'models' folder" - ); - const options: MessageBoxOptions = { - type: "error", - title: "Invalid Folder", - message: - "Please make sure that the folder name is 'models' and nothing else.", - buttons: ["OK"], - }; - dialog.showMessageBoxSync(options); - return null; - } - - mainWindow.webContents.send( - commands.CUSTOM_MODEL_FILES_LIST, - getModels(customModelsFolderPath) - ); - - logit("📁 Custom Folder Path: ", customModelsFolderPath); - return customModelsFolderPath; - } - } - ); -} diff --git a/electron/utils/listener/doubleUpscayl.ts b/electron/utils/listener/doubleUpscayl.ts deleted file mode 100644 index 3e6e4eb..0000000 --- a/electron/utils/listener/doubleUpscayl.ts +++ /dev/null @@ -1,198 +0,0 @@ -import { ipcMain } from "electron"; -import commands from "../../commands"; -import { parse } from "path"; -import { spawnUpscayl } from "../../upscayl"; -import { - getDoubleUpscaleArguments, - getDoubleUpscaleSecondPassArguments, -} from "../getArguments"; -import Jimp from "jimp"; - -export default function ({ - mainWindow, - slash, - logit, - childProcesses, - stopped, - modelsPath, - customModelsFolderPath, - saveOutputFolder, - outputFolderPath, - quality, - defaultModels, -}: { - mainWindow: Electron.BrowserWindow; - slash: string; - logit: (message: string, ...optionalParams: any[]) => void; - childProcesses: any[]; - stopped: boolean; - modelsPath: string; - customModelsFolderPath: string | undefined; - saveOutputFolder: boolean; - outputFolderPath: string | undefined; - quality: number; - defaultModels: string[]; -}) { - ipcMain.on(commands.DOUBLE_UPSCAYL, async (event, payload) => { - const model = payload.model as string; - let inputDir = (payload.imagePath.match(/(.*)[\/\\]/)[1] || "") as string; - let outputDir = payload.outputPath as string; - - if (saveOutputFolder === true && outputFolderPath) { - outputDir = outputFolderPath; - } - const gpuId = payload.gpuId as string; - const saveImageAs = payload.saveImageAs as string; - - const isDefaultModel = defaultModels.includes(model); - - // COPY IMAGE TO TMP FOLDER - - const fullfileName = payload.imagePath.split(slash).slice(-1)[0] as string; - const fileName = parse(fullfileName).name; - const outFile = - outputDir + - slash + - fileName + - "_upscayl_16x_" + - model + - "." + - saveImageAs; - - let scale = "4"; - if (model.includes("x2")) { - scale = "2"; - } else if (model.includes("x3")) { - scale = "3"; - } else { - scale = "4"; - } - - // UPSCALE - let upscayl = spawnUpscayl( - "realesrgan", - getDoubleUpscaleArguments( - inputDir, - fullfileName, - outFile, - isDefaultModel ? modelsPath : customModelsFolderPath ?? modelsPath, - model, - gpuId, - saveImageAs, - scale - ), - logit - ); - - childProcesses.push(upscayl); - - stopped = false; - let failed = false; - let isAlpha = false; - let failed2 = false; - - const onData = (data) => { - // CONVERT DATA TO STRING - data = data.toString(); - // SEND UPSCAYL PROGRESS TO RENDERER - mainWindow.webContents.send(commands.DOUBLE_UPSCAYL_PROGRESS, data); - // IF PROGRESS HAS ERROR, UPSCAYL FAILED - if (data.includes("invalid gpu") || data.includes("failed")) { - failed = true; - } - if (data.includes("has alpha channel")) { - isAlpha = true; - } - }; - - const onError = (data) => { - data.toString(); - // SEND UPSCAYL PROGRESS TO RENDERER - mainWindow.webContents.send(commands.DOUBLE_UPSCAYL_PROGRESS, data); - // SET FAILED TO TRUE - failed = true; - return; - }; - - const onData2 = (data) => { - // CONVERT DATA TO STRING - data = data.toString(); - // SEND UPSCAYL PROGRESS TO RENDERER - mainWindow.webContents.send(commands.DOUBLE_UPSCAYL_PROGRESS, data); - // IF PROGRESS HAS ERROR, UPSCAYL FAILED - if (data.includes("invalid gpu") || data.includes("failed")) { - failed2 = true; - } - }; - - const onError2 = (data) => { - data.toString(); - // SEND UPSCAYL PROGRESS TO RENDERER - mainWindow.webContents.send(commands.DOUBLE_UPSCAYL_PROGRESS, data); - // SET FAILED TO TRUE - failed2 = true; - return; - }; - - const onClose2 = async (code) => { - if (!failed2 && !stopped) { - logit("💯 Done upscaling"); - logit("♻ Scaling and converting now..."); - const originalImage = await Jimp.read(inputDir + slash + fullfileName); - try { - const newImage = await Jimp.read( - isAlpha ? outFile + ".png" : outFile - ); - try { - newImage - .scaleToFit( - originalImage.getWidth() * parseInt(payload.scale), - originalImage.getHeight() * parseInt(payload.scale) - ) - .quality(100 - quality) - .write(isAlpha ? outFile + ".png" : outFile); - mainWindow.setProgressBar(-1); - mainWindow.webContents.send( - commands.DOUBLE_UPSCAYL_DONE, - isAlpha ? outFile + ".png" : outFile - ); - } catch (error) { - logit("❌ Error converting to PNG: ", error); - onError(error); - } - } catch (error) { - logit("❌ Error reading original image metadata", error); - onError(error); - } - } - }; - - upscayl.process.stderr.on("data", onData); - upscayl.process.on("error", onError); - upscayl.process.on("close", (code) => { - // IF NOT FAILED - if (!failed && !stopped) { - // UPSCALE - let upscayl2 = spawnUpscayl( - "realesrgan", - getDoubleUpscaleSecondPassArguments( - isAlpha, - outFile, - isDefaultModel ? modelsPath : customModelsFolderPath ?? modelsPath, - model, - gpuId, - saveImageAs, - scale - ), - logit - ); - - childProcesses.push(upscayl2); - - upscayl2.process.stderr.on("data", onData2); - upscayl2.process.on("error", onError2); - upscayl2.process.on("close", onClose2); - } - }); - }); -} diff --git a/electron/utils/listener/folderUpscayl.ts b/electron/utils/listener/folderUpscayl.ts deleted file mode 100644 index 7d59bfb..0000000 --- a/electron/utils/listener/folderUpscayl.ts +++ /dev/null @@ -1,106 +0,0 @@ -import { ipcMain } from "electron"; -import commands from "../../commands"; -import { spawnUpscayl } from "../../upscayl"; -import { getBatchArguments } from "../getArguments"; -import fs from "fs"; - -export type FolderUpscaylProps = { - mainWindow: Electron.BrowserWindow; - logit: (message: string, ...optionalParams: any[]) => void; - childProcesses: any[]; - stopped: boolean; - modelsPath: string; - customModelsFolderPath: string | undefined; - saveOutputFolder: boolean; - outputFolderPath: string | undefined; - defaultModels: string[]; -}; - -export default function ({ - mainWindow, - logit, - childProcesses, - stopped, - modelsPath, - customModelsFolderPath, - saveOutputFolder, - outputFolderPath, - defaultModels, -}: FolderUpscaylProps) { - ipcMain.on(commands.FOLDER_UPSCAYL, async (event, payload) => { - // GET THE MODEL - const model = payload.model; - const gpuId = payload.gpuId; - const saveImageAs = payload.saveImageAs; - const scale = payload.scale as string; - - // GET THE IMAGE DIRECTORY - let inputDir = payload.batchFolderPath; - // GET THE OUTPUT DIRECTORY - let outputDir = payload.outputPath; - - if (saveOutputFolder === true && outputFolderPath) { - outputDir = outputFolderPath; - } - - if (!fs.existsSync(outputDir)) { - fs.mkdirSync(outputDir, { recursive: true }); - } - - const isDefaultModel = defaultModels.includes(model); - - // UPSCALE - const upscayl = spawnUpscayl( - "realesrgan", - getBatchArguments( - inputDir, - outputDir, - isDefaultModel ? modelsPath : customModelsFolderPath ?? modelsPath, - model, - gpuId, - saveImageAs, - scale - ), - logit - ); - - childProcesses.push(upscayl); - - stopped = false; - let failed = false; - - const onData = (data: any) => { - data = data.toString(); - mainWindow.webContents.send( - commands.FOLDER_UPSCAYL_PROGRESS, - data.toString() - ); - if (data.includes("invalid gpu") || data.includes("failed")) { - logit("❌ INVALID GPU OR INVALID FILES IN FOLDER - FAILED"); - failed = true; - upscayl.kill(); - } - }; - const onError = (data: any) => { - mainWindow.webContents.send( - commands.FOLDER_UPSCAYL_PROGRESS, - data.toString() - ); - failed = true; - upscayl.kill(); - return; - }; - const onClose = () => { - if (!failed && !stopped) { - logit("💯 Done upscaling"); - mainWindow.webContents.send(commands.FOLDER_UPSCAYL_DONE, outputDir); - } else { - upscayl.kill(); - } - }; - - upscayl.process.stderr.on("data", onData); - upscayl.process.on("error", onError); - upscayl.process.on("close", onClose); - }); -} diff --git a/electron/utils/listener/getModelsList.ts b/electron/utils/listener/getModelsList.ts deleted file mode 100644 index d9d62ed..0000000 --- a/electron/utils/listener/getModelsList.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { ipcMain } from "electron"; -import commands from "../../commands"; - -export type GetModelsListProps = { - mainWindow: Electron.BrowserWindow; - customModelsFolderPath: string | undefined; - logit: (message: string, ...optionalParams: any[]) => void; - getModels: (folderPath: string) => string[] | null; -}; - -export default function ({ - mainWindow, - customModelsFolderPath, - logit, - getModels, -}: GetModelsListProps) { - ipcMain.on(commands.GET_MODELS_LIST, async (event, payload) => { - if (payload) { - customModelsFolderPath = payload; - - logit("📁 Custom Models Folder Path: ", customModelsFolderPath); - - mainWindow.webContents.send( - commands.CUSTOM_MODEL_FILES_LIST, - getModels(payload) - ); - } - }); -} diff --git a/electron/utils/listener/imageUpscayl.ts b/electron/utils/listener/imageUpscayl.ts deleted file mode 100644 index 2c5e37d..0000000 --- a/electron/utils/listener/imageUpscayl.ts +++ /dev/null @@ -1,162 +0,0 @@ -import { ipcMain } from "electron"; -import commands from "../../commands"; -import { parse } from "path"; -import { spawnUpscayl } from "../../upscayl"; -import Jimp from "jimp"; -import { getSingleImageArguments } from "../getArguments"; -import fs from "fs"; - -export type ImageUpscaylProps = { - mainWindow: Electron.BrowserWindow; - slash: string; - logit: (...args: any) => void; - childProcesses: any[]; - stopped: boolean; - modelsPath: string; - customModelsFolderPath: string | undefined; - saveOutputFolder: boolean; - outputFolderPath: string | undefined; - quality: number; - defaultModels: string[]; - folderPath: string | undefined; -}; - -export default function ({ - mainWindow, - slash, - logit, - childProcesses, - stopped, - modelsPath, - customModelsFolderPath, - saveOutputFolder, - outputFolderPath, - quality, - defaultModels, - folderPath, -}: ImageUpscaylProps) { - ipcMain.on(commands.UPSCAYL, async (event, payload) => { - const model = payload.model as string; - const gpuId = payload.gpuId as string; - const saveImageAs = payload.saveImageAs as string; - - let inputDir = (payload.imagePath.match(/(.*)[\/\\]/)[1] || "") as string; - let outputDir = folderPath || (payload.outputPath as string); - - if (saveOutputFolder === true && outputFolderPath) { - outputDir = outputFolderPath; - } - - const isDefaultModel = defaultModels.includes(model); - - const fullfileName = payload.imagePath.replace(/^.*[\\\/]/, "") as string; - const fileName = parse(fullfileName).name; - const fileExt = parse(fullfileName).ext; - - let scale = "4"; - if (model.includes("x2")) { - scale = "2"; - } else if (model.includes("x3")) { - scale = "3"; - } else { - scale = "4"; - } - - const outFile = - outputDir + - slash + - fileName + - "_upscayl_" + - payload.scale + - "x_" + - model + - "." + - saveImageAs; - - // UPSCALE - if (fs.existsSync(outFile)) { - // If already upscayled, just output that file - logit("✅ Already upscayled at: ", outFile); - mainWindow.webContents.send(commands.UPSCAYL_DONE, outFile); - } else { - const upscayl = spawnUpscayl( - "realesrgan", - getSingleImageArguments( - inputDir, - fullfileName, - outFile, - isDefaultModel ? modelsPath : customModelsFolderPath ?? modelsPath, - model, - scale, - gpuId, - saveImageAs - ), - logit - ); - - childProcesses.push(upscayl); - - stopped = false; - let isAlpha = false; - let failed = false; - - const onData = (data: string) => { - logit("image upscayl: ", data.toString()); - mainWindow.setProgressBar(parseFloat(data.slice(0, data.length)) / 100); - data = data.toString(); - mainWindow.webContents.send(commands.UPSCAYL_PROGRESS, data.toString()); - if (data.includes("invalid gpu") || data.includes("failed")) { - logit("❌ INVALID GPU OR FAILED"); - failed = true; - } - if (data.includes("has alpha channel")) { - logit("📢 INCLUDES ALPHA CHANNEL, CHANGING OUTFILE NAME!"); - isAlpha = true; - } - }; - const onError = (data) => { - mainWindow.webContents.send(commands.UPSCAYL_PROGRESS, data.toString()); - failed = true; - return; - }; - const onClose = async () => { - if (!failed && !stopped) { - logit("💯 Done upscaling"); - logit("♻ Scaling and converting now..."); - const originalImage = await Jimp.read( - inputDir + slash + fullfileName - ); - try { - const newImage = await Jimp.read( - isAlpha ? outFile + ".png" : outFile - ); - try { - newImage - .scaleToFit( - originalImage.getWidth() * parseInt(payload.scale), - originalImage.getHeight() * parseInt(payload.scale) - ) - .quality(100 - quality) - .write(isAlpha ? outFile + ".png" : outFile); - mainWindow.setProgressBar(-1); - mainWindow.webContents.send( - commands.UPSCAYL_DONE, - isAlpha ? outFile + ".png" : outFile - ); - } catch (error) { - logit("❌ Error converting to PNG: ", error); - onError(error); - } - } catch (error) { - logit("❌ Error reading original image metadata", error); - onError(error); - } - } - }; - - upscayl.process.stderr.on("data", onData); - upscayl.process.on("error", onError); - upscayl.process.on("close", onClose); - } - }); -} diff --git a/electron/utils/listener/selectFile.ts b/electron/utils/listener/selectFile.ts deleted file mode 100644 index 46f50ed..0000000 --- a/electron/utils/listener/selectFile.ts +++ /dev/null @@ -1,59 +0,0 @@ -import { MessageBoxOptions, dialog, ipcMain } from "electron"; -import commands from "../../commands"; - -export type SelectFileProps = { - mainWindow: Electron.BrowserWindow; - imagePath: string; - logit: (...args: any) => void; -}; - -export default function ({ mainWindow, imagePath, logit }) { - ipcMain.handle(commands.SELECT_FILE, async () => { - const { canceled, filePaths } = await dialog.showOpenDialog({ - properties: ["openFile", "multiSelections"], - title: "Select Image", - defaultPath: imagePath, - }); - - if (canceled) { - logit("🚫 File Operation Cancelled"); - return null; - } else { - imagePath = filePaths[0]; - - let isValid = false; - // READ SELECTED FILES - filePaths.forEach((file) => { - // log.log("Files in Folder: ", file); - if ( - file.endsWith(".png") || - file.endsWith(".jpg") || - file.endsWith(".jpeg") || - file.endsWith(".webp") || - file.endsWith(".JPG") || - file.endsWith(".PNG") || - file.endsWith(".JPEG") || - file.endsWith(".WEBP") - ) { - isValid = true; - } - }); - - if (!isValid) { - logit("❌ Invalid File Detected"); - const options: MessageBoxOptions = { - type: "error", - title: "Invalid File", - message: - "The selected file is not a valid image. Make sure you select a '.png', '.jpg', or '.webp' file.", - }; - dialog.showMessageBoxSync(mainWindow, options); - return null; - } - - logit("📄 Selected File Path: ", filePaths[0]); - // CREATE input AND upscaled FOLDER - return filePaths[0]; - } - }); -} diff --git a/electron/utils/listener/selectFolder.ts b/electron/utils/listener/selectFolder.ts deleted file mode 100644 index ef7f576..0000000 --- a/electron/utils/listener/selectFolder.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { dialog, ipcMain } from "electron"; -import commands from "../../commands"; - -export type SelectFolderProps = { - folderPath: string; - logit: (...args: any[]) => void; -}; - -export default function ({ folderPath, logit }) { - ipcMain.handle(commands.SELECT_FOLDER, async (event, message) => { - const { canceled, filePaths: folderPaths } = await dialog.showOpenDialog({ - properties: ["openDirectory"], - defaultPath: folderPath, - }); - - if (canceled) { - logit("🚫 Select Folder Operation Cancelled"); - return null; - } else { - folderPath = folderPaths[0]; - logit("📁 Selected Folder Path: ", folderPath); - return folderPaths[0]; - } - }); -} diff --git a/main/utils/listener/customModelsSelect.js b/main/utils/listener/customModelsSelect.js new file mode 100644 index 0000000..ae9290a --- /dev/null +++ b/main/utils/listener/customModelsSelect.js @@ -0,0 +1,48 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const electron_1 = require("electron"); +const commands_1 = __importDefault(require("../../commands")); +function default_1({ mainWindow, customModelsFolderPath, logit, slash, getModels, }) { + electron_1.ipcMain.handle(commands_1.default.SELECT_CUSTOM_MODEL_FOLDER, (event, message) => __awaiter(this, void 0, void 0, function* () { + const { canceled, filePaths: folderPaths } = yield electron_1.dialog.showOpenDialog({ + properties: ["openDirectory"], + title: "Select Custom Models Folder", + defaultPath: customModelsFolderPath, + }); + if (canceled) { + logit("🚫 Select Custom Models Folder Operation Cancelled"); + return null; + } + else { + customModelsFolderPath = folderPaths[0]; + if (!folderPaths[0].endsWith(slash + "models") && + !folderPaths[0].endsWith(slash + "models" + slash)) { + logit("❌ Invalid Custom Models Folder Detected: Not a 'models' folder"); + const options = { + type: "error", + title: "Invalid Folder", + message: "Please make sure that the folder name is 'models' and nothing else.", + buttons: ["OK"], + }; + electron_1.dialog.showMessageBoxSync(options); + return null; + } + mainWindow.webContents.send(commands_1.default.CUSTOM_MODEL_FILES_LIST, getModels(customModelsFolderPath)); + logit("📁 Custom Folder Path: ", customModelsFolderPath); + return customModelsFolderPath; + } + })); +} +exports.default = default_1; diff --git a/main/utils/listener/doubleUpscayl.js b/main/utils/listener/doubleUpscayl.js index b5ab77e..3af7ba9 100644 --- a/main/utils/listener/doubleUpscayl.js +++ b/main/utils/listener/doubleUpscayl.js @@ -18,8 +18,8 @@ const path_1 = require("path"); const upscayl_1 = require("../../upscayl"); const getArguments_1 = require("../getArguments"); const jimp_1 = __importDefault(require("jimp")); -function default_1(mainWindow, slash, logit, childProcesses, stopped, modelsPath, customModelsFolderPath, saveOutputFolder, outputFolderPath, quality, defaultModels) { - return electron_1.ipcMain.on(commands_1.default.DOUBLE_UPSCAYL, (event, payload) => __awaiter(this, void 0, void 0, function* () { +function default_1({ mainWindow, slash, logit, childProcesses, stopped, modelsPath, customModelsFolderPath, saveOutputFolder, outputFolderPath, quality, defaultModels, }) { + electron_1.ipcMain.on(commands_1.default.DOUBLE_UPSCAYL, (event, payload) => __awaiter(this, void 0, void 0, function* () { const model = payload.model; let inputDir = (payload.imagePath.match(/(.*)[\/\\]/)[1] || ""); let outputDir = payload.outputPath; diff --git a/main/utils/listener/folderUpscayl.js b/main/utils/listener/folderUpscayl.js index be8702d..e421037 100644 --- a/main/utils/listener/folderUpscayl.js +++ b/main/utils/listener/folderUpscayl.js @@ -17,8 +17,7 @@ const commands_1 = __importDefault(require("../../commands")); const upscayl_1 = require("../../upscayl"); const getArguments_1 = require("../getArguments"); const fs_1 = __importDefault(require("fs")); -function default_1(mainWindow, logit, childProcesses, stopped, modelsPath, customModelsFolderPath, saveOutputFolder, outputFolderPath, defaultModels) { - //------------------------Upscayl Folder-----------------------------// +function default_1({ mainWindow, logit, childProcesses, stopped, modelsPath, customModelsFolderPath, saveOutputFolder, outputFolderPath, defaultModels, }) { electron_1.ipcMain.on(commands_1.default.FOLDER_UPSCAYL, (event, payload) => __awaiter(this, void 0, void 0, function* () { // GET THE MODEL const model = payload.model; diff --git a/main/utils/listener/getModelsList.js b/main/utils/listener/getModelsList.js new file mode 100644 index 0000000..c09a604 --- /dev/null +++ b/main/utils/listener/getModelsList.js @@ -0,0 +1,26 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const electron_1 = require("electron"); +const commands_1 = __importDefault(require("../../commands")); +function default_1({ mainWindow, customModelsFolderPath, logit, getModels, }) { + electron_1.ipcMain.on(commands_1.default.GET_MODELS_LIST, (event, payload) => __awaiter(this, void 0, void 0, function* () { + if (payload) { + customModelsFolderPath = payload; + logit("📁 Custom Models Folder Path: ", customModelsFolderPath); + mainWindow.webContents.send(commands_1.default.CUSTOM_MODEL_FILES_LIST, getModels(payload)); + } + })); +} +exports.default = default_1; diff --git a/main/utils/listener/imageUpscayl.js b/main/utils/listener/imageUpscayl.js new file mode 100644 index 0000000..8df33e9 --- /dev/null +++ b/main/utils/listener/imageUpscayl.js @@ -0,0 +1,118 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const electron_1 = require("electron"); +const commands_1 = __importDefault(require("../../commands")); +const path_1 = require("path"); +const upscayl_1 = require("../../upscayl"); +const jimp_1 = __importDefault(require("jimp")); +const getArguments_1 = require("../getArguments"); +const fs_1 = __importDefault(require("fs")); +function default_1({ mainWindow, slash, logit, childProcesses, stopped, modelsPath, customModelsFolderPath, saveOutputFolder, outputFolderPath, quality, defaultModels, folderPath, }) { + electron_1.ipcMain.on(commands_1.default.UPSCAYL, (event, payload) => __awaiter(this, void 0, void 0, function* () { + const model = payload.model; + const gpuId = payload.gpuId; + const saveImageAs = payload.saveImageAs; + let inputDir = (payload.imagePath.match(/(.*)[\/\\]/)[1] || ""); + let outputDir = folderPath || payload.outputPath; + if (saveOutputFolder === true && outputFolderPath) { + outputDir = outputFolderPath; + } + const isDefaultModel = defaultModels.includes(model); + const fullfileName = payload.imagePath.replace(/^.*[\\\/]/, ""); + const fileName = (0, path_1.parse)(fullfileName).name; + const fileExt = (0, path_1.parse)(fullfileName).ext; + let scale = "4"; + if (model.includes("x2")) { + scale = "2"; + } + else if (model.includes("x3")) { + scale = "3"; + } + else { + scale = "4"; + } + const outFile = outputDir + + slash + + fileName + + "_upscayl_" + + payload.scale + + "x_" + + model + + "." + + saveImageAs; + // UPSCALE + if (fs_1.default.existsSync(outFile)) { + // If already upscayled, just output that file + logit("✅ Already upscayled at: ", outFile); + mainWindow.webContents.send(commands_1.default.UPSCAYL_DONE, outFile); + } + else { + const upscayl = (0, upscayl_1.spawnUpscayl)("realesrgan", (0, getArguments_1.getSingleImageArguments)(inputDir, fullfileName, outFile, isDefaultModel ? modelsPath : customModelsFolderPath !== null && customModelsFolderPath !== void 0 ? customModelsFolderPath : modelsPath, model, scale, gpuId, saveImageAs), logit); + childProcesses.push(upscayl); + stopped = false; + let isAlpha = false; + let failed = false; + const onData = (data) => { + logit("image upscayl: ", data.toString()); + mainWindow.setProgressBar(parseFloat(data.slice(0, data.length)) / 100); + data = data.toString(); + mainWindow.webContents.send(commands_1.default.UPSCAYL_PROGRESS, data.toString()); + if (data.includes("invalid gpu") || data.includes("failed")) { + logit("❌ INVALID GPU OR FAILED"); + failed = true; + } + if (data.includes("has alpha channel")) { + logit("📢 INCLUDES ALPHA CHANNEL, CHANGING OUTFILE NAME!"); + isAlpha = true; + } + }; + const onError = (data) => { + mainWindow.webContents.send(commands_1.default.UPSCAYL_PROGRESS, data.toString()); + failed = true; + return; + }; + const onClose = () => __awaiter(this, void 0, void 0, function* () { + if (!failed && !stopped) { + logit("💯 Done upscaling"); + logit("♻ Scaling and converting now..."); + const originalImage = yield jimp_1.default.read(inputDir + slash + fullfileName); + try { + const newImage = yield jimp_1.default.read(isAlpha ? outFile + ".png" : outFile); + try { + newImage + .scaleToFit(originalImage.getWidth() * parseInt(payload.scale), originalImage.getHeight() * parseInt(payload.scale)) + .quality(100 - quality) + .write(isAlpha ? outFile + ".png" : outFile); + mainWindow.setProgressBar(-1); + mainWindow.webContents.send(commands_1.default.UPSCAYL_DONE, isAlpha ? outFile + ".png" : outFile); + } + catch (error) { + logit("❌ Error converting to PNG: ", error); + onError(error); + } + } + catch (error) { + logit("❌ Error reading original image metadata", error); + onError(error); + } + } + }); + upscayl.process.stderr.on("data", onData); + upscayl.process.on("error", onError); + upscayl.process.on("close", onClose); + } + })); +} +exports.default = default_1; diff --git a/main/utils/listener/selectFile.js b/main/utils/listener/selectFile.js new file mode 100644 index 0000000..1fcc9d5 --- /dev/null +++ b/main/utils/listener/selectFile.js @@ -0,0 +1,61 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const electron_1 = require("electron"); +const commands_1 = __importDefault(require("../../commands")); +function default_1({ mainWindow, imagePath, logit }) { + return electron_1.ipcMain.handle(commands_1.default.SELECT_FILE, () => __awaiter(this, void 0, void 0, function* () { + const { canceled, filePaths } = yield electron_1.dialog.showOpenDialog({ + properties: ["openFile", "multiSelections"], + title: "Select Image", + defaultPath: imagePath, + }); + if (canceled) { + logit("🚫 File Operation Cancelled"); + return null; + } + else { + imagePath = filePaths[0]; + let isValid = false; + // READ SELECTED FILES + filePaths.forEach((file) => { + // log.log("Files in Folder: ", file); + if (file.endsWith(".png") || + file.endsWith(".jpg") || + file.endsWith(".jpeg") || + file.endsWith(".webp") || + file.endsWith(".JPG") || + file.endsWith(".PNG") || + file.endsWith(".JPEG") || + file.endsWith(".WEBP")) { + isValid = true; + } + }); + if (!isValid) { + logit("❌ Invalid File Detected"); + const options = { + type: "error", + title: "Invalid File", + message: "The selected file is not a valid image. Make sure you select a '.png', '.jpg', or '.webp' file.", + }; + electron_1.dialog.showMessageBoxSync(mainWindow, options); + return null; + } + logit("📄 Selected File Path: ", filePaths[0]); + // CREATE input AND upscaled FOLDER + return filePaths[0]; + } + })); +} +exports.default = default_1; diff --git a/main/utils/listener/selectFolder.js b/main/utils/listener/selectFolder.js new file mode 100644 index 0000000..407a130 --- /dev/null +++ b/main/utils/listener/selectFolder.js @@ -0,0 +1,34 @@ +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const electron_1 = require("electron"); +const commands_1 = __importDefault(require("../../commands")); +function default_1({ folderPath, logit }) { + electron_1.ipcMain.handle(commands_1.default.SELECT_FOLDER, (event, message) => __awaiter(this, void 0, void 0, function* () { + const { canceled, filePaths: folderPaths } = yield electron_1.dialog.showOpenDialog({ + properties: ["openDirectory"], + defaultPath: folderPath, + }); + if (canceled) { + logit("🚫 Select Folder Operation Cancelled"); + return null; + } + else { + folderPath = folderPaths[0]; + logit("📁 Selected Folder Path: ", folderPath); + return folderPaths[0]; + } + })); +} +exports.default = default_1; diff --git a/renderer/components/Footer.tsx b/renderer/components/Footer.tsx index 3e131b1..8d892db 100644 --- a/renderer/components/Footer.tsx +++ b/renderer/components/Footer.tsx @@ -15,17 +15,10 @@ function Footer() {

By{" "} - TGS963 - {" "} - and{" "} - - Nayam Amarshe + TGS963 and Nayam Amarshe

diff --git a/renderer/components/upscayl-tab/view/ImageOptions.tsx b/renderer/components/upscayl-tab/view/ImageOptions.tsx index 22b51bd..1a4c85c 100644 --- a/renderer/components/upscayl-tab/view/ImageOptions.tsx +++ b/renderer/components/upscayl-tab/view/ImageOptions.tsx @@ -20,7 +20,7 @@ const ImageOptions = ({ }, []); return ( -
+
{/*
*/}