Skip to content

Commit

Permalink
replace updater call and add electron-log
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanamr committed May 7, 2023
1 parent 789d7b1 commit 3d72283
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 22 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
25 changes: 8 additions & 17 deletions packages/main/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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();
});
9 changes: 5 additions & 4 deletions packages/main/src/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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":
Expand Down
3 changes: 2 additions & 1 deletion packages/main/src/mainWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}

Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1357,6 +1357,11 @@ [email protected]:
simple-update-notifier "^1.0.7"
yargs "^17.5.1"

[email protected]:
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"
Expand Down

0 comments on commit 3d72283

Please sign in to comment.