Skip to content

Commit 2b22c52

Browse files
committed
fix: add flexible constant for IO master port
1 parent 4c9dc72 commit 2b22c52

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

Diff for: packages/native-machine-id/binding.cc

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
#ifdef __APPLE__
55
#include <CoreFoundation/CoreFoundation.h>
66
#include <IOKit/IOKitLib.h>
7+
#include <AvailabilityMacros.h>
8+
// kIOMainPortDefault is the replacement on macOS 12+ but is not available in older SDKs
9+
#if (defined(MAC_OS_X_VERSION_MIN_REQUIRED) && MAC_OS_X_VERSION_MIN_REQUIRED >= 120000)
10+
#define IO_PORT_DEFAULT kIOMainPortDefault
11+
#else
12+
#define IO_PORT_DEFAULT kIOMasterPortDefault
13+
#endif
714
#elif defined(__linux__)
815
#include <fstream>
916
#include <algorithm>
@@ -21,7 +28,7 @@ namespace
2128
std::string getMachineId() noexcept
2229
{
2330
std::string uuid;
24-
io_registry_entry_t ioRegistryRoot = IORegistryEntryFromPath(kIOMainPortDefault, "IOService:/");
31+
io_registry_entry_t ioRegistryRoot = IORegistryEntryFromPath(IO_PORT_DEFAULT, "IOService:/");
2532

2633
if (ioRegistryRoot == MACH_PORT_NULL)
2734
{

Diff for: packages/native-machine-id/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "native-machine-id",
3-
"version": "0.0.2",
3+
"version": "0.0.4",
44
"description": "Native retrieval of a unique desktop machine ID without admin privileges or child processes. Faster and more reliable alternative to node-machine-id.",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

0 commit comments

Comments
 (0)