Skip to content

Commit 8435efe

Browse files
Merge pull request #52 from OpenAstroTech/feature/js/macos-platform-detection
MacOS platform detection
2 parents 09623d9 + bc35439 commit 8435efe

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

OATFWGUI/anon_usage_data.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ def get_computer_uuid() -> str:
143143
machine_id_fn = {
144144
PlatformEnum.WINDOWS: get_uuid_windows,
145145
PlatformEnum.LINUX: get_uuid_linux,
146+
PlatformEnum.MACOS: get_uuid_macos,
146147
PlatformEnum.UNKNOWN: lambda: 'unknown platform',
147148
}.get(get_platform(), lambda: 'unknown, unhandled platform')
148149
machine_id_str = machine_id_fn()
@@ -178,6 +179,20 @@ def get_uuid_linux() -> str:
178179
return machine_id_contents
179180

180181

182+
def get_uuid_macos() -> str:
183+
sub_proc = subprocess.run(
184+
['ioreg',
185+
'-rd1',
186+
'-c',
187+
'IOPlatformExpertDevice',
188+
],
189+
capture_output=True)
190+
if sub_proc.returncode != 0:
191+
return 'unknown-macos'
192+
ioreg_output = sub_proc.stdout.decode('UTF-8')
193+
return windows_uuid
194+
195+
181196
def to_nearest_half(num: float) -> float:
182197
return round(num * 2, 0) / 2
183198

OATFWGUI/platform_check.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
class PlatformEnum(enum.Enum):
1010
LINUX = enum.auto()
1111
WINDOWS = enum.auto()
12+
MACOS = enum.auto()
1213
UNKNOWN = enum.auto()
1314

1415

@@ -25,6 +26,8 @@ def get_platform() -> PlatformEnum:
2526
platform_lookup = PlatformEnum.WINDOWS
2627
elif 'linux' in platform_str:
2728
platform_lookup = PlatformEnum.LINUX
29+
elif 'darwin' in platform_str:
30+
platform_lookup = PlatformEnum.MACOS
2831
else:
2932
platform_lookup = PlatformEnum.UNKNOWN
3033
platform_lookup_cache = platform_lookup # Cache return

0 commit comments

Comments
 (0)