3 Commits

Author SHA1 Message Date
5f2e05b4b9 return unused return comment 2024-07-21 22:02:27 +02:00
d171545f18 fix hwid error 2024-07-21 21:48:44 +02:00
6551f0b369 fix hwid generation 2024-07-21 14:58:59 +02:00
2 changed files with 17 additions and 10 deletions

View File

@@ -16,17 +16,24 @@ const platforms = {
};
const crypto = require("crypto");
const defaultHWID = "recorderinthesandybridge";
/**
* Returns machine hardware id.
* Returns `undefined` if cannot determine.
* @return {string?}
* @return {Promise<string>}
*/
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) => {
try {
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"));
} catch {
resolve(crypto.createHash("md5").update(defaultHWID).digest("hex"));
}
})
}
exports.getHwId = getHwId;

View File

@@ -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 };