π Upscayl - #1 Free and Open Source AI Image Upscaler for Linux, MacOS and Windows.
TypeScript aielectronesrgangigapixelgigapixel-imagesimageimage-upscalingtopazupscaleupscalerimageupscayl
Add showNotification function and update output folder path
Nayam Amarshe57810f4d7736
diff --git a/electron/commands/batch-upscayl.ts b/electron/commands/batch-upscayl.tsindex f1aa5e4..d6c2f0d 100644--- a/electron/commands/batch-upscayl.ts+++ b/electron/commands/batch-upscayl.ts@@ -23,6 +23,7 @@ import { BatchUpscaylPayload } from "../../common/types/types";import { ImageFormat } from "../utils/types";import getModelScale from "../../common/check-model-scale";import removeFileExtension from "../utils/remove-file-extension";+import showNotification from "../utils/show-notification";const batchUpscayl = async (event, payload: BatchUpscaylPayload) => {const mainWindow = getMainWindow();@@ -35,9 +36,9 @@ const batchUpscayl = async (event, payload: BatchUpscaylPayload) => {// GET THE IMAGE DIRECTORYlet inputDir = payload.batchFolderPath;// GET THE OUTPUT DIRECTORY- let outputDir = payload.outputPath;+ let outputFolderPath = payload.outputPath;if (saveOutputFolder === true && outputFolderPath) {- outputDir = outputFolderPath;+ outputFolderPath = outputFolderPath;}setNoImageProcessing(payload.noImageProcessing);@@ -49,11 +50,12 @@ const batchUpscayl = async (event, payload: BatchUpscaylPayload) => {const desiredScale = payload.scale as string;- outputDir +=- slash +- `upscayl_${model}_x${noImageProcessing ? initialScale : desiredScale}`;- if (!fs.existsSync(outputDir)) {- fs.mkdirSync(outputDir, { recursive: true });+ const outputFolderName = `upscayl_${model}_x${+ noImageProcessing ? initialScale : desiredScale+ }`;+ outputFolderPath += slash + outputFolderName;+ if (!fs.existsSync(outputFolderPath)) {+ fs.mkdirSync(outputFolderPath, { recursive: true });}// Delete .DS_Store files@@ -69,7 +71,7 @@ const batchUpscayl = async (event, payload: BatchUpscaylPayload) => {"realesrgan",getBatchArguments(inputDir,- outputDir,+ outputFolderPath,isDefaultModel ? modelsPath : customModelsFolderPath ?? modelsPath,model,gpuId,@@ -123,18 +125,22 @@ const batchUpscayl = async (event, payload: BatchUpscaylPayload) => {if (noImageProcessing) {logit("π« Skipping scaling and converting");mainWindow.setProgressBar(-1);- mainWindow.webContents.send(COMMAND.FOLDER_UPSCAYL_DONE, outputDir);+ mainWindow.webContents.send(+ COMMAND.FOLDER_UPSCAYL_DONE,+ outputFolderPath+ );return;}const files = fs.readdirSync(inputDir);try {files.forEach(async (file) => {+ if (file.startsWith(".") || file === outputFolderName) return;console.log("Filename: ", removeFileExtension(file));await convertAndScale(inputDir + slash + file,- `${outputDir}${slash}${removeFileExtension(file)}.png`,- `${outputDir}/${removeFileExtension(file)}.${saveImageAs}`,+ `${outputFolderPath}${slash}${removeFileExtension(file)}.png`,+ `${outputFolderPath}/${removeFileExtension(file)}.${saveImageAs}`,desiredScale,saveImageAs,onError@@ -143,11 +149,15 @@ const batchUpscayl = async (event, payload: BatchUpscaylPayload) => {if (saveImageAs !== "png") {logit("Removing output PNG");fs.unlinkSync(- `${outputDir}${slash}${removeFileExtension(file)}.png`+ `${outputFolderPath}${slash}${removeFileExtension(file)}.png`);}});- mainWindow.webContents.send(COMMAND.FOLDER_UPSCAYL_DONE, outputDir);+ mainWindow.webContents.send(+ COMMAND.FOLDER_UPSCAYL_DONE,+ outputFolderPath+ );+ showNotification("Upscayled", "Image upscayled successfully!");} catch (error) {logit("β Error processing (scaling and converting) the image.", error);upscayl.kill();@@ -157,6 +167,7 @@ const batchUpscayl = async (event, payload: BatchUpscaylPayload) => {"Error processing (scaling and converting) the image. Please report this error on Upscayl GitHub Issues page.\n" +error);+ showNotification("Upscayl Failure", "Failed to upscale image!");}} else {upscayl.kill();diff --git a/electron/commands/double-upscayl.ts b/electron/commands/double-upscayl.tsindex a021639..ba740da 100644--- a/electron/commands/double-upscayl.ts+++ b/electron/commands/double-upscayl.ts@@ -25,6 +25,7 @@ import convertAndScale from "../utils/convert-and-scale";import { DoubleUpscaylPayload } from "../../common/types/types";import { ImageFormat } from "../utils/types";import getModelScale from "../../common/check-model-scale";+import showNotification from "../utils/show-notification";const doubleUpscayl = async (event, payload: DoubleUpscaylPayload) => {const mainWindow = getMainWindow();@@ -120,6 +121,7 @@ const doubleUpscayl = async (event, payload: DoubleUpscaylPayload) => {COMMAND.UPSCAYL_ERROR,"Error upscaling image. Error: " + data);+ showNotification("Upscayl Failure", "Failed to upscale image!");upscayl.kill();return;};@@ -170,6 +172,7 @@ const doubleUpscayl = async (event, payload: DoubleUpscaylPayload) => {encodeURIComponent(outFile.match(/[^/\\]+$/i)![0])));+ showNotification("Upscayled", "Image upscayled successfully!");} catch (error) {logit("β Error reading original image metadata", error);mainWindow &&@@ -178,6 +181,7 @@ const doubleUpscayl = async (event, payload: DoubleUpscaylPayload) => {"Error processing (scaling and converting) the image. Please report this error on Upscayl GitHub Issues page.\n" +error);+ showNotification("Upscayl Failure", "Failed to upscale image!");upscayl.kill();}}@@ -229,6 +233,7 @@ const doubleUpscayl = async (event, payload: DoubleUpscaylPayload) => {COMMAND.UPSCAYL_ERROR,"Error upscaling image. Error: " + data);+ showNotification("Upscayl Failure", "Failed to upscale image!");upscayl2.kill();return;});diff --git a/electron/commands/image-upscayl.ts b/electron/commands/image-upscayl.tsindex c8cc7d2..542aa7f 100644--- a/electron/commands/image-upscayl.ts+++ b/electron/commands/image-upscayl.ts@@ -26,6 +26,7 @@ import { ImageUpscaylPayload } from "../../common/types/types";import { ImageFormat } from "../utils/types";import getModelScale from "../../common/check-model-scale";import removeFileExtension from "../utils/remove-file-extension";+import showNotification from "../utils/show-notification";const imageUpscayl = async (event, payload: ImageUpscaylPayload) => {const mainWindow = getMainWindow();@@ -191,6 +192,7 @@ const imageUpscayl = async (event, payload: ImageUpscaylPayload) => {encodeURIComponent(outFile.match(/[^/\\]+$/i)![0])));+ showNotification("Upscayl", "Image upscayled successfully!");} catch (error) {logit("β Error processing (scaling and converting) the image. Please report this error on GitHub.",@@ -202,6 +204,7 @@ const imageUpscayl = async (event, payload: ImageUpscaylPayload) => {"Error processing (scaling and converting) the image. Please report this error on Upscayl GitHub Issues page.\n" +error);+ showNotification("Upscayl Failure", "Failed to upscale image!");}}};diff --git a/electron/utils/convert-and-scale.ts b/electron/utils/convert-and-scale.tsindex e0c3a75..df5bca1 100644--- a/electron/utils/convert-and-scale.ts+++ b/electron/utils/convert-and-scale.ts@@ -1,7 +1,6 @@import fs from "fs";import sharp, { FormatEnum, Metadata } from "sharp";import logit from "./logit";-import { getMainWindow } from "../main-window";import { compression } from "./config-variables";import { ImageFormat } from "./types";@@ -17,22 +16,24 @@ const convertAndScale = async (logit("Skipping png compression for 4x scale");return;}- const mainWindow = getMainWindow();let originalImage: Metadata | undefined;try {originalImage = await sharp(originalImagePath).metadata();} catch (error) {- logit("β Error with original Image: ", error);+ logit("β Error with original Image: ", error, " - ", originalImagePath);}fs.access(originalImagePath, fs.constants.F_OK, (err) => {+ logit("πΌοΈ Checking if original image exists: ", originalImagePath);if (err) {- throw new Error("Could not grab the original image!");+ throw new Error(+ "Could not grab the original image from the path provided! - " + err+ );}});- if (!mainWindow || !originalImage) {+ if (!originalImage) {throw new Error("Could not grab the original image!");}diff --git a/electron/utils/remove-file-extension.ts b/electron/utils/remove-file-extension.tsindex 660450d..9a03c12 100644--- a/electron/utils/remove-file-extension.ts+++ b/electron/utils/remove-file-extension.ts@@ -1,3 +1,5 @@+import { Dirent } from "fs";+/*** Returns the filename without the extension.* @param filename The filename to remove the extension from.diff --git a/electron/utils/show-notification.ts b/electron/utils/show-notification.tsnew file mode 100644index 0000000..cb35ef9--- /dev/null+++ b/electron/utils/show-notification.ts@@ -0,0 +1,9 @@+import { Notification } from "electron/main";++export default function showNotification(title: string, body: string) {+ new Notification({+ title,+ body,+ closeButtonText: "Close",+ }).show();+}