MCPcopy
hub / github.com/codeaashu/claude-code / startMdmPoll

Function startMdmPoll

src/utils/settings/changeDetector.ts:381–418  ·  view source on GitHub ↗

* Start polling for MDM settings changes (registry/plist). * Takes a snapshot of current MDM settings and compares on each tick.

()

Source from the content-addressed store, hash-verified

379 * Takes a snapshot of current MDM settings and compares on each tick.
380 */
381function 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.

Callers 1

initializeFunction · 0.85

Calls 8

getMdmSettingsFunction · 0.85
getHkcuSettingsFunction · 0.85
jsonStringifyFunction · 0.85
refreshMdmSettingsFunction · 0.85
setMdmSettingsCacheFunction · 0.85
logForDebuggingFunction · 0.85
fanOutFunction · 0.85
errorMessageFunction · 0.50

Tested by

no test coverage detected