@@ -316,6 +316,7 @@ async function addDeviceLicense() {
316316 const dir = path . dirname ( targetPath ) ;
317317 // POSIX: mkdir + printf (use absolute paths)
318318 const safe = content . replace ( / ' / g, `'\\''` ) ;
319+ // todo we need to chmod to make this world readable
319320 command = `/bin/mkdir -p "${ dir } " && /bin/printf '%s' '${ safe } ' > "${ targetPath } "` ;
320321 }
321322
@@ -349,6 +350,51 @@ async function isLicensedDevice() {
349350 }
350351}
351352
353+ async function _getLinuxDeviceID ( ) {
354+ const data = await fsPromise . readFile ( "/etc/machine-id" , "utf8" ) ;
355+ const id = data . trim ( ) ;
356+ return id || null ;
357+ // throw on error to main.
358+ // no fallback, /var/lib/dbus/machine-id may need sudo in some machines
359+ }
360+
361+ /**
362+ * Get the macOS device ID (IOPlatformUUID).
363+ * @returns {Promise<string|null> }
364+ */
365+ function _getMacDeviceID ( ) {
366+ return new Promise ( ( resolve , reject ) => {
367+ exec (
368+ 'ioreg -rd1 -c IOPlatformExpertDevice | grep IOPlatformUUID' ,
369+ { encoding : 'utf8' } ,
370+ ( err , stdout ) => {
371+ if ( err ) {
372+ console . error ( 'Failed to get Mac device ID:' , err . message ) ;
373+ return reject ( err ) ;
374+ }
375+
376+ const match = stdout . match ( / " I O P l a t f o r m U U I D " = " ( [ ^ " ] + ) " / ) ;
377+ if ( match && match [ 1 ] ) {
378+ resolve ( match [ 1 ] ) ;
379+ } else {
380+ resolve ( null ) ;
381+ }
382+ }
383+ ) ;
384+ } ) ;
385+ }
386+
387+ async function getDeviceID ( ) {
388+ if ( process . platform === "linux" ) {
389+ return _getLinuxDeviceID ( ) ;
390+ } else if ( process . platform === "darwin" ) {
391+ return _getMacDeviceID ( ) ;
392+ } else if ( process . platform === "win32" ) {
393+ return "not implemented" ; //await _getWindowsDeviceID();
394+ }
395+ throw new Error ( `Unsupported platform: ${ process . platform } ` ) ;
396+ }
397+
352398exports . getURLContent = getURLContent ;
353399exports . setLocaleStrings = setLocaleStrings ;
354400exports . getPhoenixBinaryVersion = getPhoenixBinaryVersion ;
@@ -361,5 +407,6 @@ exports.openInDefaultApp = openInDefaultApp;
361407exports . addDeviceLicense = addDeviceLicense ;
362408exports . removeDeviceLicense = removeDeviceLicense ;
363409exports . isLicensedDevice = isLicensedDevice ;
410+ exports . getDeviceID = getDeviceID ;
364411exports . _loadNodeExtensionModule = _loadNodeExtensionModule ;
365412exports . _npmInstallInFolder = _npmInstallInFolder ;
0 commit comments