1
0
mirror of https://github.com/upscayl/upscayl.git synced 2025-01-18 17:14:08 +01:00

Refined SettingsTab logging and changed emoji

This commit is contained in:
Feenix 2023-05-01 13:14:12 +05:30
parent f1505bdf00
commit 2f09776fb1
5 changed files with 67 additions and 112 deletions

View File

@ -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();
});

View File

@ -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,

View File

@ -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<React.SetStateAction<boolean>>;
setModel: React.Dispatch<React.SetStateAction<string>>;
setSaveImageAs: React.Dispatch<React.SetStateAction<string>>;
setGpuId: React.Dispatch<React.SetStateAction<string>>;
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 (
<div className="animate-step-in animate flex h-screen flex-col gap-7 overflow-y-auto p-5 overflow-x-hidden">

View File

@ -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

View File

@ -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}
/>
)}