From 09370ee24a5178ad2c1c3d29781e3553eece0fb2 Mon Sep 17 00:00:00 2001 From: amitojsingh366 Date: Sat, 17 Apr 2021 21:08:04 +0300 Subject: [PATCH] added logger --- package.json | 3 +- src/index.ts | 168 ++++++++++++++++++++++++++++----------------------- yarn.lock | 8 +++ 3 files changed, 101 insertions(+), 78 deletions(-) diff --git a/package.json b/package.json index d86e6ae..1451ae7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "easy-rpc", - "version": "2.0.20", + "version": "2.0.21", "description": "A easy discord rpc", "main": "dist/index.js", "scripts": { @@ -66,6 +66,7 @@ "dependencies": { "auto-launch": "^5.0.5", "discord-rpc": "^3.2.0", + "electron-log": "^4.3.4", "electron-prompt": "^1.6.2", "electron-updater": "^4.3.8" }, diff --git a/src/index.ts b/src/index.ts index 802e206..f1282cd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,106 +1,120 @@ import { app, BrowserWindow, ipcMain, Menu, shell, Tray } from "electron"; import * as path from "path"; import { autoUpdater } from "electron-updater"; -import { RPC_STARTED, startHandler, rpc, RPC_TRYING_TO_START } from "./presence"; +import { + RPC_STARTED, + startHandler, + rpc, + RPC_TRYING_TO_START, +} from "./presence"; import { HandleTray } from "./tray"; -import AutoLaunch from 'auto-launch'; +import AutoLaunch from "auto-launch"; import { MENU_TEMPLATE } from "./constants"; +import electronLogger from "electron-log"; export let mainWindow: BrowserWindow; let tray: Tray; let menu: Menu; const instanceLock = app.requestSingleInstanceLock(); +electronLogger.transports.file.level = "debug"; +autoUpdater.logger = electronLogger; +// just in case we have to revert to a build +autoUpdater.allowDowngrade = true; + export const commons = { - shouldDock: true, - autoLaunch: false, -} + shouldDock: true, + autoLaunch: false, +}; const easyRPCAutoLauncher = new AutoLaunch({ - name: 'Easy RPC', + name: "Easy RPC", }); export async function createWindow() { - mainWindow = new BrowserWindow({ - height: 825, - width: 600, - autoHideMenuBar: true, - webPreferences: { - nodeIntegration: true, - contextIsolation: false - }, - }); + mainWindow = new BrowserWindow({ + height: 825, + width: 600, + autoHideMenuBar: true, + webPreferences: { + nodeIntegration: true, + contextIsolation: false, + }, + }); - await mainWindow.loadFile(path.join(__dirname, "../public/home.html")); - menu = Menu.buildFromTemplate(MENU_TEMPLATE); - Menu.setApplicationMenu(menu); - const handleLinks = (event: any, url: string) => { - event.preventDefault(); - shell.openExternal(url); - }; - mainWindow.webContents.on("new-window", handleLinks); - mainWindow.webContents.on("will-navigate", handleLinks); - autoUpdater.checkForUpdatesAndNotify(); + await mainWindow.loadFile(path.join(__dirname, "../public/home.html")); + menu = Menu.buildFromTemplate(MENU_TEMPLATE); + Menu.setApplicationMenu(menu); + const handleLinks = (event: any, url: string) => { + event.preventDefault(); + shell.openExternal(url); + }; + mainWindow.webContents.on("new-window", handleLinks); + mainWindow.webContents.on("will-navigate", handleLinks); + autoUpdater.checkForUpdatesAndNotify(); } app.on("ready", async () => { - await createWindow(); - app.on("activate", function () { - if (BrowserWindow.getAllWindows().length === 0) createWindow(); - }); - await startHandler() - tray = new Tray(path.join(__dirname, `../icons/tray.png`)); - await HandleTray(tray); - ipcMain.on("@app/shouldDock", (event, shouldDock) => { - commons.shouldDock = shouldDock; - }) - ipcMain.on("@app/autoLaunch", (event, autoLaunch) => { - if (autoLaunch) { - easyRPCAutoLauncher.enable(); - } else { - easyRPCAutoLauncher.disable(); - } - commons.autoLaunch = autoLaunch; - }) - ipcMain.on("@app/quit", (event, args) => { - if (RPC_STARTED && rpc) { - rpc.removeAllListeners(); - rpc.clearActivity(); - rpc.destroy(); - } - app.quit(); - }); - ipcMain.on('@app/version', (event, args) => { - event.sender.send('@app/version', app.getVersion()); - }); - if (!mainWindow.isDestroyed()) { - mainWindow.webContents.send("@app/shouldDock", ""); - mainWindow.webContents.send("@app/autoLaunch", ""); - mainWindow.webContents.send("@app/started", ""); + await createWindow(); + app.on("activate", function () { + if (BrowserWindow.getAllWindows().length === 0) createWindow(); + }); + await startHandler(); + tray = new Tray(path.join(__dirname, `../icons/tray.png`)); + await HandleTray(tray); + ipcMain.on("@app/shouldDock", (event, shouldDock) => { + commons.shouldDock = shouldDock; + }); + ipcMain.on("@app/autoLaunch", (event, autoLaunch) => { + if (autoLaunch) { + easyRPCAutoLauncher.enable(); + } else { + easyRPCAutoLauncher.disable(); } + commons.autoLaunch = autoLaunch; + }); + ipcMain.on("@app/quit", (event, args) => { + if (RPC_STARTED && rpc) { + rpc.removeAllListeners(); + rpc.clearActivity(); + rpc.destroy(); + } + app.quit(); + }); + ipcMain.on("@app/version", (event, args) => { + event.sender.send("@app/version", app.getVersion()); + }); + if (!mainWindow.isDestroyed()) { + mainWindow.webContents.send("@app/shouldDock", ""); + mainWindow.webContents.send("@app/autoLaunch", ""); + mainWindow.webContents.send("@app/started", ""); + } }); if (!instanceLock) { - app.quit(); + app.quit(); } else { - app.on("second-instance", (event, argv, workingDirectory) => { - if (mainWindow) { - if (mainWindow.isDestroyed()) { - createWindow(); - } else if (mainWindow.isMinimized()) { - mainWindow.restore(); - } - mainWindow.focus(); - } else { - createWindow(); - } - }); + app.on("second-instance", (event, argv, workingDirectory) => { + if (mainWindow) { + if (mainWindow.isDestroyed()) { + createWindow(); + } else if (mainWindow.isMinimized()) { + mainWindow.restore(); + } + mainWindow.focus(); + } else { + createWindow(); + } + }); } app.on("window-all-closed", () => { - if ((RPC_STARTED && commons.shouldDock) || (RPC_TRYING_TO_START && commons.shouldDock)) { - return; - } else { - app.quit(); - } -}); \ No newline at end of file + if ( + (RPC_STARTED && commons.shouldDock) || + (RPC_TRYING_TO_START && commons.shouldDock) + ) { + return; + } else { + app.quit(); + } +}); diff --git a/yarn.lock b/yarn.lock index e059750..c49483d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1108,6 +1108,7 @@ __metadata: electron: ^12.0.2 electron-builder: ^22.10.5 electron-builder-notarize: ^1.2.0 + electron-log: ^4.3.4 electron-prompt: ^1.6.2 electron-updater: ^4.3.8 typescript: ^4.2.3 @@ -1183,6 +1184,13 @@ __metadata: languageName: node linkType: hard +"electron-log@npm:^4.3.4": + version: 4.3.4 + resolution: "electron-log@npm:4.3.4" + checksum: 93d53f52aa3f93542deeea831a2a3398b7b53920b87f7ec61f78938b60d8abd7d202abbb7577920544c9b5de1db31330d3460eaa29275a2fca1ffbc91c37b2c5 + languageName: node + linkType: hard + "electron-notarize@npm:^0.2.0": version: 0.2.1 resolution: "electron-notarize@npm:0.2.1"