* Start polling for MDM settings changes (registry/plist). * Takes a snapshot of current MDM settings and compares on each tick.
()
| 379 | * Takes a snapshot of current MDM settings and compares on each tick. |
| 380 | */ |
| 381 | function startMdmPoll(): void { |
| 382 | // Capture initial snapshot (includes both admin MDM and user-writable HKCU) |
| 383 | const initial = getMdmSettings() |
| 384 | const initialHkcu = getHkcuSettings() |
| 385 | lastMdmSnapshot = jsonStringify({ |
| 386 | mdm: initial.settings, |
| 387 | hkcu: initialHkcu.settings, |
| 388 | }) |
| 389 | |
| 390 | mdmPollTimer = setInterval(() => { |
| 391 | if (disposed) return |
| 392 | |
| 393 | void (async () => { |
| 394 | try { |
| 395 | const { mdm: current, hkcu: currentHkcu } = await refreshMdmSettings() |
| 396 | if (disposed) return |
| 397 | |
| 398 | const currentSnapshot = jsonStringify({ |
| 399 | mdm: current.settings, |
| 400 | hkcu: currentHkcu.settings, |
| 401 | }) |
| 402 | |
| 403 | if (currentSnapshot !== lastMdmSnapshot) { |
| 404 | lastMdmSnapshot = currentSnapshot |
| 405 | // Update the cache so sync readers pick up new values |
| 406 | setMdmSettingsCache(current, currentHkcu) |
| 407 | logForDebugging('Detected MDM settings change via poll') |
| 408 | fanOut('policySettings') |
| 409 | } |
| 410 | } catch (error) { |
| 411 | logForDebugging(`MDM poll error: ${errorMessage(error)}`) |
| 412 | } |
| 413 | })() |
| 414 | }, testOverrides?.mdmPollInterval ?? MDM_POLL_INTERVAL_MS) |
| 415 | |
| 416 | // Don't let the timer keep the process alive |
| 417 | mdmPollTimer.unref() |
| 418 | } |
| 419 | |
| 420 | /** |
| 421 | * Reset the settings cache, then notify all listeners. |
no test coverage detected