From 373870621e025b851962f9ec510187f404b8f45b Mon Sep 17 00:00:00 2001 From: Nayam Amarshe <25067102+NayamAmarshe@users.noreply.github.com> Date: Fri, 31 Mar 2023 16:03:48 +0530 Subject: [PATCH] Added log for console --- electron/index.ts | 18 +++++++++++------- main/index.js | 16 +++++++++------- package-lock.json | 15 +++++++++++++++ package.json | 1 + renderer/pages/_app.tsx | 1 + renderer/pages/index.tsx | 13 +++++++++++++ 6 files changed, 50 insertions(+), 14 deletions(-) diff --git a/electron/index.ts b/electron/index.ts index 690bd2a..7e2ea05 100644 --- a/electron/index.ts +++ b/electron/index.ts @@ -11,6 +11,7 @@ import { autoUpdater } from "electron-updater"; import getPlatform from "./getPlatform"; import ffmpeg from "upscayl-ffmpeg"; import { join, parse } from "path"; +import log from "electron-log"; import { format } from "url"; import fs from "fs"; @@ -31,15 +32,17 @@ import prepareNext from "electron-next"; import isDev from "electron-is-dev"; import commands from "./commands"; +log.initialize({ preload: true }); + // Prepare the renderer once the app is ready let mainWindow; app.on("ready", async () => { await prepareNext("./renderer"); - console.log("🚀 ICON PATH: ", join(__dirname, "build", "icon.png")); - console.log("🚀 UPSCAYL EXEC PATH: ", execPath("")); - console.log("🚀 MODELS PATH: ", modelsPath); - console.log("🚀 FFMPEG PATH: ", ffmpeg.path); + log.info("🚀 ICON PATH: ", join(__dirname, "build", "icon.png")); + log.info("🚀 UPSCAYL EXEC PATH: ", execPath("")); + log.info("🚀 MODELS PATH: ", modelsPath); + log.info("🚀 FFMPEG PATH: ", ffmpeg.path); mainWindow = new BrowserWindow({ icon: join(__dirname, "build", "icon.png"), @@ -84,7 +87,8 @@ app.on("ready", async () => { // Quit the app once all windows are closed app.on("window-all-closed", app.quit); -console.log(app.getAppPath()); +log.log(app.getAppPath()); + //------------------------Select File-----------------------------// // ! DONT FORGET TO RESTART THE APP WHEN YOU CHANGE CODE HERE ipcMain.handle(commands.SELECT_FILE, async () => { @@ -93,10 +97,10 @@ ipcMain.handle(commands.SELECT_FILE, async () => { }); if (canceled) { - console.log("operation cancelled"); + console.log("File Operation Cancelled"); return "cancelled"; } else { - console.log(filePaths[0]); + console.log("Selected File Path: ", filePaths[0]); // CREATE input AND upscaled FOLDER return filePaths[0]; } diff --git a/main/index.js b/main/index.js index 721c306..d55cc4e 100644 --- a/main/index.js +++ b/main/index.js @@ -18,6 +18,7 @@ const electron_updater_1 = require("electron-updater"); const getPlatform_1 = __importDefault(require("./getPlatform")); const upscayl_ffmpeg_1 = __importDefault(require("upscayl-ffmpeg")); const path_1 = require("path"); +const electron_log_1 = __importDefault(require("electron-log")); const url_1 = require("url"); const fs_1 = __importDefault(require("fs")); const binaries_1 = require("./binaries"); @@ -27,14 +28,15 @@ const upscayl_1 = require("./upscayl"); const electron_next_1 = __importDefault(require("electron-next")); const electron_is_dev_1 = __importDefault(require("electron-is-dev")); const commands_1 = __importDefault(require("./commands")); +electron_log_1.default.initialize({ preload: true }); // Prepare the renderer once the app is ready let mainWindow; electron_1.app.on("ready", () => __awaiter(void 0, void 0, void 0, function* () { yield (0, electron_next_1.default)("./renderer"); - console.log("🚀 ICON PATH: ", (0, path_1.join)(__dirname, "build", "icon.png")); - console.log("🚀 UPSCAYL EXEC PATH: ", (0, binaries_1.execPath)("")); - console.log("🚀 MODELS PATH: ", binaries_1.modelsPath); - console.log("🚀 FFMPEG PATH: ", upscayl_ffmpeg_1.default.path); + electron_log_1.default.info("🚀 ICON PATH: ", (0, path_1.join)(__dirname, "build", "icon.png")); + electron_log_1.default.info("🚀 UPSCAYL EXEC PATH: ", (0, binaries_1.execPath)("")); + electron_log_1.default.info("🚀 MODELS PATH: ", binaries_1.modelsPath); + electron_log_1.default.info("🚀 FFMPEG PATH: ", upscayl_ffmpeg_1.default.path); mainWindow = new electron_1.BrowserWindow({ icon: (0, path_1.join)(__dirname, "build", "icon.png"), width: 1300, @@ -72,7 +74,7 @@ electron_1.app.on("ready", () => __awaiter(void 0, void 0, void 0, function* () })); // Quit the app once all windows are closed electron_1.app.on("window-all-closed", electron_1.app.quit); -console.log(electron_1.app.getAppPath()); +electron_log_1.default.log(electron_1.app.getAppPath()); //------------------------Select File-----------------------------// // ! DONT FORGET TO RESTART THE APP WHEN YOU CHANGE CODE HERE electron_1.ipcMain.handle(commands_1.default.SELECT_FILE, () => __awaiter(void 0, void 0, void 0, function* () { @@ -80,11 +82,11 @@ electron_1.ipcMain.handle(commands_1.default.SELECT_FILE, () => __awaiter(void 0 properties: ["openFile", "multiSelections"], }); if (canceled) { - console.log("operation cancelled"); + console.log("File Operation Cancelled"); return "cancelled"; } else { - console.log(filePaths[0]); + console.log("Selected File Path: ", filePaths[0]); // CREATE input AND upscaled FOLDER return filePaths[0]; } diff --git a/package-lock.json b/package-lock.json index 260e1e7..7e383d3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ "daisyui": "^2.51.4", "electron-is-dev": "^2.0.0", "electron-is-packaged": "^1.0.2", + "electron-log": "^5.0.0-beta.16", "electron-next": "^3.1.5", "electron-root-path": "^1.1.0", "electron-updater": "^5.3.0", @@ -3327,6 +3328,15 @@ "eslint": "^3.0.0 || ^4.0.0 || ^5.0.0" } }, + "node_modules/electron-log": { + "version": "5.0.0-beta.16", + "resolved": "https://registry.npmjs.org/electron-log/-/electron-log-5.0.0-beta.16.tgz", + "integrity": "sha512-oBGFKjAsOXyzhvJIW0s+HIA7cV+kZ0B0FvO3hKyS8yPDGFsjQyr3M8N7ZyYxI6yEeihVID3CCfsTmpi6L9k0gw==", + "engines": { + "electron": ">= 13", + "node": ">= 14" + } + }, "node_modules/electron-next": { "version": "3.1.5", "resolved": "https://registry.npmjs.org/electron-next/-/electron-next-3.1.5.tgz", @@ -10108,6 +10118,11 @@ "integrity": "sha512-JZpV9QgVsehop7tm3KDll2/iJ9K3e7mL+jm6E3gA96zurIhxv3FZ0kxJK0eGL9c3SYORU1rN+/q2Ia8/v62Pjw==", "requires": {} }, + "electron-log": { + "version": "5.0.0-beta.16", + "resolved": "https://registry.npmjs.org/electron-log/-/electron-log-5.0.0-beta.16.tgz", + "integrity": "sha512-oBGFKjAsOXyzhvJIW0s+HIA7cV+kZ0B0FvO3hKyS8yPDGFsjQyr3M8N7ZyYxI6yEeihVID3CCfsTmpi6L9k0gw==" + }, "electron-next": { "version": "3.1.5", "resolved": "https://registry.npmjs.org/electron-next/-/electron-next-3.1.5.tgz", diff --git a/package.json b/package.json index 045b8c7..9301cd2 100644 --- a/package.json +++ b/package.json @@ -159,6 +159,7 @@ "daisyui": "^2.51.4", "electron-is-dev": "^2.0.0", "electron-is-packaged": "^1.0.2", + "electron-log": "^5.0.0-beta.16", "electron-next": "^3.1.5", "electron-root-path": "^1.1.0", "electron-updater": "^5.3.0", diff --git a/renderer/pages/_app.tsx b/renderer/pages/_app.tsx index ffeba88..2e19c60 100644 --- a/renderer/pages/_app.tsx +++ b/renderer/pages/_app.tsx @@ -3,6 +3,7 @@ import Head from "next/head"; import { AppProps } from "next/app"; import { useEffect } from "react"; import { themeChange } from "theme-change"; +import log from "electron-log/renderer"; const MyApp = ({ Component, pageProps }: AppProps) => { return ( diff --git a/renderer/pages/index.tsx b/renderer/pages/index.tsx index b1d3d1c..89ade9b 100644 --- a/renderer/pages/index.tsx +++ b/renderer/pages/index.tsx @@ -11,6 +11,8 @@ import LeftPaneImageSteps from "../components/LeftPaneImageSteps"; import Tabs from "../components/Tabs"; import SettingsTab from "../components/SettingsTab"; +let logData = []; + const Home = () => { // STATES const [imagePath, SetImagePath] = useState(""); @@ -38,6 +40,17 @@ const Home = () => { height: null, }); const [selectedTab, setSelectedTab] = useState(0); + const [logData, setLogData] = useState([]); + + (function () { + let info = console.info; + + console.log = function () { + var args = Array.prototype.slice.call(arguments); + info.apply(this, args); + setLogData([...logData, { level: "info", arguments: args }]); + }; + })(); // EFFECTS useEffect(() => {