()
| 68 | } |
| 69 | |
| 70 | function startRestartInterval(): void { |
| 71 | // Only run on macOS |
| 72 | if (process.platform !== 'darwin') { |
| 73 | return |
| 74 | } |
| 75 | |
| 76 | // Already running |
| 77 | if (restartInterval !== null) { |
| 78 | return |
| 79 | } |
| 80 | |
| 81 | restartInterval = setInterval(() => { |
| 82 | // Only restart if we still need sleep prevention |
| 83 | if (refCount > 0) { |
| 84 | logForDebugging('Restarting caffeinate to maintain sleep prevention') |
| 85 | killCaffeinate() |
| 86 | spawnCaffeinate() |
| 87 | } |
| 88 | }, RESTART_INTERVAL_MS) |
| 89 | |
| 90 | // Don't let the interval keep the Node process alive |
| 91 | restartInterval.unref() |
| 92 | } |
| 93 | |
| 94 | function stopRestartInterval(): void { |
| 95 | if (restartInterval !== null) { |
no test coverage detected