()
| 53 | * On Linux: returns empty (no MDM equivalent). |
| 54 | */ |
| 55 | export function fireRawRead(): Promise<RawReadResult> { |
| 56 | return (async (): Promise<RawReadResult> => { |
| 57 | if (process.platform === 'darwin') { |
| 58 | const plistPaths = getMacOSPlistPaths() |
| 59 | |
| 60 | const allResults = await Promise.all( |
| 61 | plistPaths.map(async ({ path, label }) => { |
| 62 | // Fast-path: skip the plutil subprocess if the plist file does not |
| 63 | // exist. Spawning plutil takes ~5ms even for an immediate ENOENT, |
| 64 | // and non-MDM machines never have these files. |
| 65 | // Uses synchronous existsSync to preserve the spawn-during-imports |
| 66 | // invariant: execFilePromise must be the first await so plutil |
| 67 | // spawns before the event loop polls (see main.tsx:3-4). |
| 68 | if (!existsSync(path)) { |
| 69 | return { stdout: '', label, ok: false } |
| 70 | } |
| 71 | const { stdout, code } = await execFilePromise(PLUTIL_PATH, [ |
| 72 | ...PLUTIL_ARGS_PREFIX, |
| 73 | path, |
| 74 | ]) |
| 75 | return { stdout, label, ok: code === 0 && !!stdout } |
| 76 | }), |
| 77 | ) |
| 78 | |
| 79 | // First source wins (array is in priority order) |
| 80 | const winner = allResults.find(r => r.ok) |
| 81 | return { |
| 82 | plistStdouts: winner |
| 83 | ? [{ stdout: winner.stdout, label: winner.label }] |
| 84 | : [], |
| 85 | hklmStdout: null, |
| 86 | hkcuStdout: null, |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | if (process.platform === 'win32') { |
| 91 | const [hklm, hkcu] = await Promise.all([ |
| 92 | execFilePromise('reg', [ |
| 93 | 'query', |
| 94 | WINDOWS_REGISTRY_KEY_PATH_HKLM, |
| 95 | '/v', |
| 96 | WINDOWS_REGISTRY_VALUE_NAME, |
| 97 | ]), |
| 98 | execFilePromise('reg', [ |
| 99 | 'query', |
| 100 | WINDOWS_REGISTRY_KEY_PATH_HKCU, |
| 101 | '/v', |
| 102 | WINDOWS_REGISTRY_VALUE_NAME, |
| 103 | ]), |
| 104 | ]) |
| 105 | return { |
| 106 | plistStdouts: null, |
| 107 | hklmStdout: hklm.code === 0 ? hklm.stdout : null, |
| 108 | hkcuStdout: hkcu.code === 0 ? hkcu.stdout : null, |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | return { plistStdouts: null, hklmStdout: null, hkcuStdout: null } |
no test coverage detected