Skip to content

Commit 4abe424

Browse files
committed
fix: logger for node in dev and device licensing working in mac
1 parent 64e2141 commit 4abe424

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

src-node/utils.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const {lintFile} = require("./ESLint/service");
99
let openModule, open; // dynamic import when needed
1010

1111
const options = { name: 'Phoenix Code' };
12-
const content = '{"licensedDevice": true}\n';
12+
const licenseFileContent = JSON.stringify({licensedDevice: true});
1313

1414
async function _importOpen() {
1515
if(open){
@@ -303,21 +303,29 @@ function readFileUtf8(p) {
303303
});
304304
}
305305

306+
/**
307+
* Writes the license file in a world-readable location.
308+
* Works on Windows, macOS, and Linux.
309+
*/
306310
async function addDeviceLicense() {
307311
const targetPath = getLicensePath();
308312
let command;
309313

310314
if (os.platform() === 'win32') {
311-
// PowerShell with explicit dirs and safe quoting
315+
// Windows: write file and explicitly grant Everyone read rights
312316
const dir = 'C:\\Program Files\\Phoenix Code Control';
313-
const psContent = content.replace(/'/g, "''");
314-
command = `powershell -Command "New-Item -ItemType Directory -Force '${dir}' | Out-Null; Set-Content -Path '${targetPath}' -Value '${psContent}' -Encoding UTF8"`;
317+
command =
318+
`powershell -Command "` +
319+
`New-Item -ItemType Directory -Force '${dir}' | Out-Null; ` +
320+
`Set-Content -Path '${targetPath}' -Value '${licenseFileContent}' -Encoding UTF8; ` +
321+
`icacls '${targetPath}' /inheritance:e /grant *S-1-1-0:RX | Out-Null"`;
315322
} else {
323+
// macOS / Linux: mkdir + write + chmod 0644 (world-readable, owner-writable)
316324
const dir = path.dirname(targetPath);
317-
// POSIX: mkdir + printf (use absolute paths)
318-
const safe = content.replace(/'/g, `'\\''`);
319-
// todo we need to chmod to make this world readable
320-
command = `/bin/mkdir -p "${dir}" && /bin/printf '%s' '${safe}' > "${targetPath}"`;
325+
command =
326+
`/bin/mkdir -p "${dir}"` +
327+
` && printf '%s' '${licenseFileContent}' > "${targetPath}"` +
328+
` && /bin/chmod 0644 "${targetPath}"`;
321329
}
322330

323331
await sudoExec(command);
@@ -363,6 +371,10 @@ async function _getLinuxDeviceID() {
363371
* @returns {Promise<string|null>}
364372
*/
365373
function _getMacDeviceID() {
374+
// to read this in mac bash, do:
375+
// #!/bin/bash
376+
// device_id=$(ioreg -rd1 -c IOPlatformExpertDevice | awk -F\" '/IOPlatformUUID/ {print $4}' | tr -d '[:space:]')
377+
// echo "$device_id"
366378
return new Promise((resolve, reject) => {
367379
exec(
368380
'ioreg -rd1 -c IOPlatformExpertDevice | grep IOPlatformUUID',

src/loggerSetup.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@
6868
Bugsnag.notify(message?
6969
new CustomBugSnagError(message, error)
7070
:error);
71+
} else {
72+
console.error(message, error, error.nodeStack);
7173
}
7274
},
7375
/**
@@ -79,6 +81,8 @@
7981
reportErrorMessage: function (message) {
8082
if(isBugsnagEnabled) {
8183
Bugsnag.notify(new CustomBugSnagError(message));
84+
} else {
85+
console.error(message);
8286
}
8387
},
8488

src/nls/root/strings.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,6 +1712,7 @@ define({
17121712
"LICENSE_ACTIVATE_SUCCESS": "License activated system-wide. Please restart {APP_NAME} for the changes to take effect.",
17131713
"LICENSE_ACTIVATE_SUCCESS_PARTIAL": "License activated for your account only (not system-wide). Please restart {APP_NAME} for the changes to take effect.",
17141714
"LICENSE_ACTIVATE_FAIL": "Failed to activate license",
1715+
"LICENSE_ACTIVATE_FAIL_APPLY": "'Failed to apply license to device'",
17151716
"LICENSE_ENTER_KEY": "Please enter a license key",
17161717
"LICENSE_REAPPLY_TO_DEVICE": "Already activated? Reapply system-wide"
17171718
});

src/services/manage-licenses.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,10 @@ define(function (require, exports, module) {
274274
// Refresh license status
275275
await _loadLicenseStatus($dialog);
276276
} else {
277-
_showActivationMessage($dialog, false, 'Failed to apply license to device');
277+
_showActivationMessage($dialog, false, Strings.LICENSE_ACTIVATE_FAIL_APPLY);
278278
}
279279
} catch (error) {
280-
_showActivationMessage($dialog, false, error.message || 'Failed to apply license to device');
280+
_showActivationMessage($dialog, false, Strings.LICENSE_ACTIVATE_FAIL_APPLY);
281281
} finally {
282282
// Reset link state
283283
$link.html(originalText);

0 commit comments

Comments
 (0)