diff --git a/electron/index.ts b/electron/index.ts index 17de2db..b2cd6b3 100644 --- a/electron/index.ts +++ b/electron/index.ts @@ -213,7 +213,7 @@ ipcMain.handle(commands.SELECT_FILE, async () => { return null; } - logit("ℹ Selected File Path: ", filePaths[0]); + logit("📢 Selected File Path: ", filePaths[0]); // CREATE input AND upscaled FOLDER return filePaths[0]; } @@ -231,7 +231,7 @@ ipcMain.handle(commands.SELECT_FOLDER, async (event, message) => { return null; } else { folderPath = folderPaths[0]; - logit("ℹ Selected Folder Path: ", folderPath); + logit("📢 Selected Folder Path: ", folderPath); return folderPaths[0]; } }); @@ -271,7 +271,7 @@ const getModels = (folderPath: string) => { return null; } - logit("ℹ Detected Custom Models: ", models); + logit("📢 Detected Custom Models: ", models); return models; }; @@ -279,7 +279,7 @@ ipcMain.on(commands.GET_MODELS_LIST, async (event, payload) => { if (payload) { customModelsFolderPath = payload; - logit("ℹ Custom Models Folder Path: ", customModelsFolderPath); + logit("📢 Custom Models Folder Path: ", customModelsFolderPath); mainWindow.webContents.send( commands.CUSTOM_MODEL_FILES_LIST, @@ -329,7 +329,7 @@ ipcMain.handle(commands.SELECT_CUSTOM_MODEL_FOLDER, async (event, message) => { //------------------------Open Folder-----------------------------// ipcMain.on(commands.OPEN_FOLDER, async (event, payload) => { - logit("ℹ Opening Folder: ", payload); + logit("📢 Opening Folder: ", payload); shell.openPath(payload); }); @@ -338,7 +338,7 @@ ipcMain.on(commands.STOP, async (event, payload) => { stopped = true; childProcesses.forEach((child) => { - logit("ℹ Stopping Upscaling Process", child.process.pid); + logit("📢 Stopping Upscaling Process", child.process.pid); child.kill(); }); }); @@ -504,7 +504,7 @@ ipcMain.on(commands.UPSCAYL, async (event, payload) => { // UPSCALE if (fs.existsSync(outFile)) { // If already upscayled, just output that file - logit("ℹ Already upscayled at: ", outFile); + logit("📢 Already upscayled at: ", outFile); mainWindow.webContents.send(commands.UPSCAYL_DONE, outFile); } else { const upscayl = spawnUpscayl( @@ -538,7 +538,7 @@ ipcMain.on(commands.UPSCAYL, async (event, payload) => { failed = true; } if (data.includes("has alpha channel")) { - logit("ℹ INCLUDES ALPHA CHANNEL, CHANGING OUTFILE NAME!"); + logit("📢 INCLUDES ALPHA CHANNEL, CHANGING OUTFILE NAME!"); isAlpha = true; } }; @@ -649,7 +649,7 @@ autoUpdater.on("update-available", ({ releaseNotes, releaseName }) => { detail: "A new version is being downloaded. Please check GitHub for more details.", }; - logit("ℹ Update Available", releaseName, releaseNotes); + logit("📢 Update Available", releaseName, releaseNotes); dialog.showMessageBox(dialogOpts).then((returnValue) => {}); }); @@ -662,7 +662,7 @@ autoUpdater.on("update-downloaded", (event) => { detail: "A new version has been downloaded. Restart the application to apply the updates.", }; - logit("ℹ Update Downloaded"); + logit("📢 Update Downloaded"); dialog.showMessageBox(dialogOpts).then((returnValue) => { if (returnValue.response === 0) autoUpdater.quitAndInstall(); }); diff --git a/electron/upscayl.ts b/electron/upscayl.ts index 4dc007c..1ac98e7 100644 --- a/electron/upscayl.ts +++ b/electron/upscayl.ts @@ -6,7 +6,7 @@ export const spawnUpscayl = ( command: string[], logit: (...args: any) => void ) => { - logit("ℹ Upscayl Command: ", command); + logit("📢 Upscayl Command: ", command); const spawnedProcess = spawn(execPath(binaryName), command, { cwd: undefined, diff --git a/renderer/components/LeftPaneImageSteps.tsx b/renderer/components/LeftPaneImageSteps.tsx index 021f1c5..3d574c0 100644 --- a/renderer/components/LeftPaneImageSteps.tsx +++ b/renderer/components/LeftPaneImageSteps.tsx @@ -1,4 +1,4 @@ -import { useAtom } from "jotai"; +import { useAtom, useAtomValue } from "jotai"; import React, { useEffect, useState } from "react"; import Select from "react-select"; import ReactTooltip from "react-tooltip"; @@ -19,9 +19,6 @@ interface IProps { outputPath: string; doubleUpscayl: boolean; setDoubleUpscayl: React.Dispatch>; - setModel: React.Dispatch>; - setSaveImageAs: React.Dispatch>; - setGpuId: React.Dispatch>; dimensions: { width: number | null; height: number | null; @@ -41,9 +38,6 @@ function LeftPaneImageSteps({ outputPath, doubleUpscayl, setDoubleUpscayl, - setModel, - setGpuId, - setSaveImageAs, dimensions, }: IProps) { const [currentModel, setCurrentModel] = useState<{ @@ -54,52 +48,7 @@ function LeftPaneImageSteps({ value: null, }); - const [modelOptions] = useAtom(modelsListAtom); - - const { logit } = useLog(); - - useEffect(() => { - themeChange(false); - - if (!localStorage.getItem("saveImageAs")) { - logit("ℹ Setting saveImageAs to png"); - localStorage.setItem("saveImageAs", "png"); - } else { - const currentlySavedImageFormat = localStorage.getItem("saveImageAs"); - logit( - "ℹ Getting saveImageAs from localStorage", - currentlySavedImageFormat - ); - setSaveImageAs(currentlySavedImageFormat); - } - - if (!localStorage.getItem("model")) { - setCurrentModel(modelOptions[0]); - setModel(modelOptions[0].value); - localStorage.setItem("model", JSON.stringify(modelOptions[0])); - logit("ℹ Setting model to", modelOptions[0].value); - } else { - const currentlySavedModel = JSON.parse( - localStorage.getItem("model") - ) as (typeof modelOptions)[0]; - setCurrentModel(currentlySavedModel); - setModel(currentlySavedModel.value); - logit("ℹ Getting model from localStorage", currentlySavedModel.value); - } - - if (!localStorage.getItem("gpuId")) { - localStorage.setItem("gpuId", ""); - logit("ℹ Setting gpuId to empty string"); - } else { - const currentlySavedGpuId = localStorage.getItem("gpuId"); - setGpuId(currentlySavedGpuId); - logit("ℹ Getting gpuId from localStorage", currentlySavedGpuId); - } - }, []); - - useEffect(() => { - logit("ℹ Setting model to", currentModel.value); - }, [currentModel]); + const modelOptions = useAtomValue(modelsListAtom); return (
diff --git a/renderer/components/SettingsTab.tsx b/renderer/components/SettingsTab.tsx index 5d470e1..2f7c0e4 100644 --- a/renderer/components/SettingsTab.tsx +++ b/renderer/components/SettingsTab.tsx @@ -1,9 +1,10 @@ import React, { useEffect, useState } from "react"; import { themeChange } from "theme-change"; import commands from "../../electron/commands"; -import { useAtom } from "jotai"; +import { useAtom, useAtomValue } from "jotai"; import { customModelsPathAtom, scaleAtom } from "../atoms/userSettingsAtom"; import { modelsListAtom } from "../atoms/modelsListAtom"; +import useLog from "./hooks/useLog"; interface IProps { batchMode: boolean; @@ -32,23 +33,27 @@ function SettingsTab({ label: null, value: null, }); - + const [rememberOutputFolder, setRememberOutputFolder] = useState(false); const [isCopied, setIsCopied] = useState(false); const [customModelsPath, setCustomModelsPath] = useAtom(customModelsPathAtom); - const [modelOptions, setModelOptions] = useAtom(modelsListAtom); - + const modelOptions = useAtomValue(modelsListAtom); const [scale, setScale] = useAtom(scaleAtom); - const [rememberOutputFolder, setRememberOutputFolder] = useState(false); + const { logit } = useLog(); useEffect(() => { themeChange(false); if (!localStorage.getItem("saveImageAs")) { + logit("📢 Setting saveImageAs to png"); localStorage.setItem("saveImageAs", "png"); } else { const currentlySavedImageFormat = localStorage.getItem("saveImageAs"); + logit( + "📢 Getting saveImageAs from localStorage", + currentlySavedImageFormat + ); setSaveImageAs(currentlySavedImageFormat); } @@ -56,32 +61,36 @@ function SettingsTab({ setCurrentModel(modelOptions[0]); setModel(modelOptions[0].value); localStorage.setItem("model", JSON.stringify(modelOptions[0])); + logit("📢 Setting model to", modelOptions[0].value); } else { const currentlySavedModel = JSON.parse( localStorage.getItem("model") ) as (typeof modelOptions)[0]; setCurrentModel(currentlySavedModel); setModel(currentlySavedModel.value); + logit("📢 Getting model from localStorage", currentlySavedModel.value); } if (!localStorage.getItem("gpuId")) { localStorage.setItem("gpuId", ""); + logit("📢 Setting gpuId to empty string"); } else { const currentlySavedGpuId = localStorage.getItem("gpuId"); setGpuId(currentlySavedGpuId); + logit("📢 Getting gpuId from localStorage", currentlySavedGpuId); } if (!localStorage.getItem("rememberOutputFolder")) { + logit("📢 Setting rememberOutputFolder to false"); localStorage.setItem("rememberOutputFolder", "false"); } else { const currentlySavedRememberOutputFolder = localStorage.getItem( "rememberOutputFolder" ); - console.log( - "🚀 => file: SettingsTab.tsx:80 => currentlySavedRememberOutputFolder:", + logit( + "📢 Getting rememberOutputFolder from localStorage", currentlySavedRememberOutputFolder ); - setRememberOutputFolder( currentlySavedRememberOutputFolder === "true" ? true : false ); @@ -89,7 +98,7 @@ function SettingsTab({ }, []); useEffect(() => { - console.log("Current Model: ", currentModel); + logit("📢 Setting model to", currentModel.value); }, [currentModel]); // HANDLERS diff --git a/renderer/pages/index.tsx b/renderer/pages/index.tsx index 390e45b..00cc9fc 100644 --- a/renderer/pages/index.tsx +++ b/renderer/pages/index.tsx @@ -79,7 +79,7 @@ const Home = () => { // LOG window.electron.on(commands.LOG, (_, data: string) => { - logit(`ℹ BACKEND REPORTED: `, data); + logit(`📢 BACKEND REPORTED: `, data); }); // UPSCAYL PROGRESS @@ -88,7 +88,7 @@ const Home = () => { setProgress(data); } handleErrors(data); - logit(`ℹ UPSCAYL_PROGRESS: `, data); + logit(`📢 UPSCAYL_PROGRESS: `, data); }); // FOLDER UPSCAYL PROGRESS @@ -97,7 +97,7 @@ const Home = () => { setProgress(data); } handleErrors(data); - logit(`ℹ FOLDER_UPSCAYL_PROGRESS: `, data); + logit(`📢 FOLDER_UPSCAYL_PROGRESS: `, data); }); // DOUBLE UPSCAYL PROGRESS @@ -109,7 +109,7 @@ const Home = () => { setProgress(data); } handleErrors(data); - logit(`ℹ DOUBLE_UPSCAYL_PROGRESS: `, data); + logit(`📢 DOUBLE_UPSCAYL_PROGRESS: `, data); }); // VIDEO UPSCAYL PROGRESS @@ -118,7 +118,7 @@ const Home = () => { setProgress(data); } handleErrors(data); - logit(`ℹ UPSCAYL_VIDEO_PROGRESS: `, data); + logit(`📢 UPSCAYL_VIDEO_PROGRESS: `, data); }); // UPSCAYL DONE @@ -126,14 +126,14 @@ const Home = () => { setProgress(""); setUpscaledImagePath(data); logit("upscaledImagePath: ", upscaledImagePath); - logit(`ℹ UPSCAYL_DONE: `, data); + logit(`📢 UPSCAYL_DONE: `, data); }); // FOLDER UPSCAYL DONE window.electron.on(commands.FOLDER_UPSCAYL_DONE, (_, data: string) => { setProgress(""); setUpscaledBatchFolderPath(data); - logit(`ℹ FOLDER_UPSCAYL_DONE: `, data); + logit(`📢 FOLDER_UPSCAYL_DONE: `, data); }); // DOUBLE UPSCAYL DONE @@ -141,21 +141,21 @@ const Home = () => { setProgress(""); setDoubleUpscaylCounter(0); setUpscaledImagePath(data); - logit(`ℹ DOUBLE_UPSCAYL_DONE: `, data); + logit(`📢 DOUBLE_UPSCAYL_DONE: `, data); }); // VIDEO UPSCAYL DONE window.electron.on(commands.UPSCAYL_VIDEO_DONE, (_, data: string) => { setProgress(""); setUpscaledVideoPath(data); - logit(`ℹ UPSCAYL_VIDEO_DONE: `, data); + logit(`📢 UPSCAYL_VIDEO_DONE: `, data); }); // CUSTOM FOLDER LISTENER window.electron.on( commands.CUSTOM_MODEL_FILES_LIST, (_, data: string[]) => { - logit(`ℹ CUSTOM_MODEL_FILES_LIST: `, data); + logit(`📢 CUSTOM_MODEL_FILES_LIST: `, data); const newModelOptions = data.map((model) => { return { value: model, @@ -182,7 +182,7 @@ const Home = () => { if (customModelsPath !== null) { window.electron.send(commands.GET_MODELS_LIST, customModelsPath); - logit("ℹ GET_MODELS_LIST: ", customModelsPath); + logit("📢 GET_MODELS_LIST: ", customModelsPath); } }, []); @@ -204,10 +204,10 @@ const Home = () => { useEffect(() => { if (imagePath.length > 0 && !isVideo) { - logit("ℹ imagePath: ", imagePath); + logit("📢 imagePath: ", imagePath); const extension = imagePath.toLocaleLowerCase().split(".").pop(); - logit("ℹ Extension: ", extension); + logit("📢 Extension: ", extension); if (!allowedFileTypes.includes(extension.toLowerCase())) { alert("Please select an image"); @@ -228,7 +228,7 @@ const Home = () => { }, [imagePath, videoPath]); const resetImagePaths = () => { - logit("ℹ Resetting image paths"); + logit("📢 Resetting image paths"); setDimensions({ width: null, @@ -273,10 +273,10 @@ const Home = () => { var path = await window.electron.invoke(commands.SELECT_FILE); if (path !== null) { - logit("ℹ Selected Image Path: ", path); + logit("📢 Selected Image Path: ", path); SetImagePath(path); var dirname = path.match(/(.*)[\/\\]/)[1] || ""; - logit("ℹ Selected Image Directory: ", dirname); + logit("📢 Selected Image Directory: ", dirname); setOutputPath(dirname); } }; @@ -287,11 +287,11 @@ const Home = () => { var path = await window.electron.invoke(commands.SELECT_FOLDER); if (path !== null) { - logit("ℹ Selected Folder Path: ", path); + logit("📢 Selected Folder Path: ", path); setBatchFolderPath(path); setOutputPath(path + "_upscayled"); } else { - logit("ℹ Folder selection cancelled"); + logit("📢 Folder selection cancelled"); setBatchFolderPath(""); setOutputPath(""); } @@ -307,7 +307,7 @@ const Home = () => { const handleModelChange = (e: any) => { setModel(e.value); - logit("ℹ Model changed: ", e.value); + logit("📢 Model changed: ", e.value); localStorage.setItem( "model", JSON.stringify({ label: e.label, value: e.value }) @@ -329,7 +329,7 @@ const Home = () => { }; const openFolderHandler = (e) => { - logit("ℹ OPEN_FOLDER: ", upscaledBatchFolderPath); + logit("📢 OPEN_FOLDER: ", upscaledBatchFolderPath); window.electron.send(commands.OPEN_FOLDER, upscaledBatchFolderPath); }; @@ -341,7 +341,7 @@ const Home = () => { e.dataTransfer.items.length === 0 || e.dataTransfer.files.length === 0 ) { - logit("ℹ No valid files dropped"); + logit("📢 No valid files dropped"); alert("Please drag and drop an image"); return; } @@ -349,25 +349,25 @@ const Home = () => { const type = e.dataTransfer.items[0].type; const filePath = e.dataTransfer.files[0].path; const extension = e.dataTransfer.files[0].name.split(".").at(-1); - logit("ℹ Dropped file: ", JSON.stringify({ type, filePath, extension })); + logit("📢 Dropped file: ", JSON.stringify({ type, filePath, extension })); if ( (!type.includes("image") && !type.includes("video")) || (!allowedFileTypes.includes(extension.toLowerCase()) && !allowedVideoFileTypes.includes(extension.toLowerCase())) ) { - logit("ℹ Invalid file dropped"); + logit("📢 Invalid file dropped"); alert("Please drag and drop an image"); } else { if (isVideo) { setVideoPath(filePath); } else { - logit("ℹ Setting image path: ", filePath); + logit("📢 Setting image path: ", filePath); SetImagePath(filePath); } var dirname = filePath.match(/(.*)[\/\\]/)[1] || ""; - logit("ℹ Setting output path: ", dirname); + logit("📢 Setting output path: ", dirname); setOutputPath(dirname); } }; @@ -380,7 +380,7 @@ const Home = () => { const filePath = e.clipboardData.files[0].path; const extension = e.clipboardData.files[0].name.split(".").at(-1); - logit("ℹ Pasted file: ", JSON.stringify({ type, filePath, extension })); + logit("📢 Pasted file: ", JSON.stringify({ type, filePath, extension })); if ( !type.includes("image") && @@ -390,7 +390,7 @@ const Home = () => { } else { SetImagePath(filePath); var dirname = filePath.match(/(.*)[\/\\]/)[1] || ""; - logit("ℹ Setting output path: ", dirname); + logit("📢 Setting output path: ", dirname); setOutputPath(dirname); } }; @@ -398,13 +398,13 @@ const Home = () => { const outputHandler = async () => { var path = await window.electron.invoke(commands.SELECT_FOLDER); if (path !== null) { - logit("ℹ Setting Output Path: ", path); + logit("📢 Setting Output Path: ", path); setOutputPath(path); const rememberOutputFolder = localStorage.getItem("rememberOutputFolder"); if (rememberOutputFolder) { - logit("ℹ Remembering Output Folder: ", path); + logit("📢 Remembering Output Folder: ", path); localStorage.setItem("lastOutputFolderPath", path); } } else { @@ -416,7 +416,7 @@ const Home = () => { if (isVideo) { setUpscaledVideoPath(""); } else { - logit("ℹ Resetting Upscaled Image Path"); + logit("📢 Resetting Upscaled Image Path"); setUpscaledImagePath(""); } @@ -432,7 +432,7 @@ const Home = () => { saveImageAs, scale, }); - logit("ℹ DOUBLE_UPSCAYL"); + logit("📢 DOUBLE_UPSCAYL"); } else if (batchMode) { setDoubleUpscayl(false); window.electron.send(commands.FOLDER_UPSCAYL, { @@ -444,7 +444,7 @@ const Home = () => { saveImageAs, scale, }); - logit("ℹ FOLDER_UPSCAYL"); + logit("📢 FOLDER_UPSCAYL"); } else { window.electron.send(commands.UPSCAYL, { scaleFactor, @@ -455,7 +455,7 @@ const Home = () => { saveImageAs, scale, }); - logit("ℹ UPSCAYL"); + logit("📢 UPSCAYL"); } } // else if (isVideo && videoPath !== "") { @@ -470,19 +470,19 @@ const Home = () => { // } else { alert(`Please select ${isVideo ? "a video" : "an image"} to upscale`); - logit("ℹ No valid image selected"); + logit("📢 No valid image selected"); } }; const stopHandler = () => { window.electron.send(commands.STOP); - logit("ℹ Stopping Upscayl"); + logit("📢 Stopping Upscayl"); resetImagePaths(); }; const formatPath = (path) => { //USE REGEX TO GET THE FILENAME AND ENCODE IT INTO PROPER FORM IN ORDER TO AVOID ERRORS DUE TO SPECIAL CHARACTERS - logit("ℹ Formatting path: ", path); + logit("📢 Formatting path: ", path); return path.replace( /([^/\\]+)$/i, encodeURIComponent(path.match(/[^/\\]+$/i)[0]) @@ -553,9 +553,6 @@ const Home = () => { outputPath={outputPath} doubleUpscayl={doubleUpscayl} setDoubleUpscayl={setDoubleUpscayl} - setModel={setModel} - setGpuId={setGpuId} - setSaveImageAs={setSaveImageAs} dimensions={dimensions} /> )}