From 6551f0b369171a1ec96ada6818ea8f7ed328d7bd Mon Sep 17 00:00:00 2001 From: HorizonCode Date: Sun, 21 Jul 2024 14:58:59 +0200 Subject: [PATCH] fix hwid generation --- electron/hwidUtil.js | 18 +++++++++++------- main.js | 4 ++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/electron/hwidUtil.js b/electron/hwidUtil.js index 285ff88..e1e6055 100644 --- a/electron/hwidUtil.js +++ b/electron/hwidUtil.js @@ -16,17 +16,21 @@ const platforms = { }; const crypto = require("crypto"); +const defaultHWID = "recorderinthesandybridge"; + /** * Returns machine hardware id. * Returns `undefined` if cannot determine. - * @return {string?} + * @return {Promise} */ function getHwId() { - const getter = platforms[process.platform]; - if (!getter) return; - const result = getter[1].exec(child_process.execSync(getter[0], options)); - if (!result) return; - return crypto.createHash("md5").update(result[1]).digest("hex") || - undefined; + return new Promise((resolve) => { + const getter = platforms[process.platform]; + if (getter) { + const result = getter[1].exec(child_process.execSync(getter[0], options)); + if (result) resolve(crypto.createHash("md5").update(result[1]).digest("hex")); + } + resolve(crypto.createHash("md5").update(defaultHWID).digest("hex")); + }) } exports.getHwId = getHwId; diff --git a/main.js b/main.js index b50f05b..ea3dd75 100644 --- a/main.js +++ b/main.js @@ -248,7 +248,7 @@ function registerIPCPipes() { ipcMain.handle("ezpplauncher:login", async (e, args) => { let hwid = ""; try { - hwid = getHwId(); + hwid = await getHwId(); } catch (err) { logger.error(`Failed to get HWID.`, err); return { @@ -315,7 +315,7 @@ function registerIPCPipes() { }); ipcMain.handle("ezpplauncher:autologin", async (e) => { - const hwid = getHwId(); + const hwid = await getHwId(); const username = config.get("username"); const guest = config.get("guest"); if (guest) return { code: 200, message: "Login as guest", guest: true };