From 3d722836bf3de174f540eddf8533f65b5c06b499 Mon Sep 17 00:00:00 2001 From: Jordan Rey Date: Sun, 7 May 2023 12:22:17 +0200 Subject: [PATCH] replace updater call and add electron-log --- package.json | 1 + packages/main/src/index.ts | 25 ++++++++----------------- packages/main/src/ipc.ts | 9 +++++---- packages/main/src/mainWindow.ts | 3 ++- yarn.lock | 5 +++++ 5 files changed, 21 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index c6c5216..9b86218 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ }, "dependencies": { "classnames": "2.3.2", + "electron-log": "4.4.8", "electron-updater": "5.3.0", "got": "11.8.6", "p-queue": "6.6.2", diff --git a/packages/main/src/index.ts b/packages/main/src/index.ts index d23568e..3840936 100644 --- a/packages/main/src/index.ts +++ b/packages/main/src/index.ts @@ -2,6 +2,9 @@ import { app } from "electron"; import "./security-restrictions"; import { restoreOrCreateWindow } from "/@/mainWindow"; import { platform } from "node:process"; +import { autoUpdater } from "electron-updater"; +import log from "electron-log"; +import type { ElectronLog } from "electron-log"; app.setAppUserModelId("com.arena-returns.launcher"); @@ -42,20 +45,8 @@ app .then(restoreOrCreateWindow) .catch(e => console.error("Failed create window:", e)); -/** - * Check for app updates, install it in background and notify user that new version was installed. - * No reason run this in non-production build. - * @see https://www.electron.build/auto-update.html#quick-setup-guide - * - * Note: It may throw "ENOENT: no such file app-update.yml" - * if you compile production app without publishing it to distribution server. - * Like `yarn compile` does. It's ok 😅 - */ -app - .whenReady() - .then(() => import("electron-updater")) - .then(module => { - const autoUpdater = module.autoUpdater || (module.default.autoUpdater as (typeof module)["autoUpdater"]); - return autoUpdater.checkForUpdatesAndNotify(); - }) - .catch(e => console.error("Failed check and install updates:", e)); +autoUpdater.logger = log; +(autoUpdater.logger as ElectronLog).transports.file.level = "info"; +app.on("ready", function () { + autoUpdater.checkForUpdatesAndNotify(); +}); diff --git a/packages/main/src/ipc.ts b/packages/main/src/ipc.ts index 7101b8d..6318223 100644 --- a/packages/main/src/ipc.ts +++ b/packages/main/src/ipc.ts @@ -7,6 +7,7 @@ import * as CdnService from "./cdnService"; import * as Updater from "./updater"; import { exec } from "child_process"; import * as Utils from "./utils"; +import log from "electron-log"; export enum DebugMode { NO_DEBUG, @@ -104,19 +105,19 @@ export function registerEvents(mainWindow: BrowserWindow) { ipcMain.on("launchGame", _event => { if (devMode) { - console.log("DevMode enabled, checking if we need to inject a localhost config in the client..."); + log.info("DevMode enabled, checking if we need to inject a localhost config in the client..."); const gameConfigPath = path.join(Constants.GAME_PATH, "game", "config.properties"); const gameConfig = fs.readFileSync(gameConfigPath); if (gameConfig.includes("127.0.0.1:5555") || gameConfig.includes("localhost:5555")) { - console.log("Localhost config already present, good!"); + log.info("Localhost config already present, good!"); } else { - console.log("Adding the Localhost config"); + log.info("Adding the Localhost config"); fs.appendFileSync(gameConfigPath, "\r\nproxyGroup_2=Localhost\r\nproxyAddresses_2=127.0.0.1:5555"); } } const javaArgs = Utils.buildJavaArgs(process.platform); - console.log(`Launching game with args: ${javaArgs}`); + log.info(`Launching game with args: ${javaArgs}`); switch (process.platform) { case "win32": diff --git a/packages/main/src/mainWindow.ts b/packages/main/src/mainWindow.ts index f4fccb4..92f9dec 100644 --- a/packages/main/src/mainWindow.ts +++ b/packages/main/src/mainWindow.ts @@ -2,6 +2,7 @@ import { app, BrowserWindow } from "electron"; import { join, resolve } from "node:path"; import * as CdnService from "./cdnService"; import * as IPC from "./ipc"; +import log from "electron-log"; export let browserWindow: BrowserWindow; @@ -31,7 +32,7 @@ async function createWindow() { }); if (process.platform === "linux") { - console.log("Linux system detected. Disabling resizing as it causes issues with Gnome."); + log.info("Linux system detected. Disabling resizing as it causes issues with Gnome."); browserWindow.setResizable(false); } diff --git a/yarn.lock b/yarn.lock index 7fce0b1..734e724 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1357,6 +1357,11 @@ electron-builder@23.6.0: simple-update-notifier "^1.0.7" yargs "^17.5.1" +electron-log@4.4.8: + version "4.4.8" + resolved "https://registry.yarnpkg.com/electron-log/-/electron-log-4.4.8.tgz#fcb9f714dbcaefb6ac7984c4683912c74730248a" + integrity sha512-QQ4GvrXO+HkgqqEOYbi+DHL7hj5JM+nHi/j+qrN9zeeXVKy8ZABgbu4CnG+BBqDZ2+tbeq9tUC4DZfIWFU5AZA== + electron-osx-sign@^0.6.0: version "0.6.0" resolved "https://registry.yarnpkg.com/electron-osx-sign/-/electron-osx-sign-0.6.0.tgz#9b69c191d471d9458ef5b1e4fdd52baa059f1bb8"