You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
github-actions[bot] edited this page Oct 31, 2025
·
1 revision
Monitor system power events like sleep, wake, and battery status.
Overview
The Electron.PowerMonitor API provides access to system power events and state changes. This includes monitoring when the system is going to sleep, waking up, or changing power sources.
Events
⚡ OnAC
Emitted when the system changes to AC power.
⚡ OnBattery
Emitted when system changes to battery power.
⚡ OnLockScreen
Emitted when the system is about to lock the screen.
⚡ OnResume
Emitted when system is resuming.
⚡ OnShutdown
Emitted when the system is about to reboot or shut down.
⚡ OnSuspend
Emitted when the system is suspending.
⚡ OnUnLockScreen
Emitted when the system is about to unlock the screen.
Usage Examples
Basic Power Event Monitoring
// Monitor system sleep/wakeElectron.PowerMonitor.OnSuspend+=()=>{Console.WriteLine("System going to sleep");// Save application stateSaveApplicationState();};Electron.PowerMonitor.OnResume+=()=>{Console.WriteLine("System waking up");// Restore application stateRestoreApplicationState();};
// Monitor power source changesElectron.PowerMonitor.OnAC+=()=>{Console.WriteLine("Switched to AC power");// Adjust power-intensive operationsEnablePowerIntensiveFeatures();};Electron.PowerMonitor.OnBattery+=()=>{Console.WriteLine("Switched to battery power");// Reduce power consumptionEnablePowerSavingMode();};
System Shutdown Handling
// Handle system shutdownElectron.PowerMonitor.OnShutdown+=()=>{Console.WriteLine("System shutting down");// Save critical data and exit gracefullySaveAndExit();};
Application State Management
privateboolisSuspended=false;publicvoidInitializePowerMonitoring(){// Track suspension stateElectron.PowerMonitor.OnSuspend+=()=>{isSuspended=true;OnSystemSleep();};Electron.PowerMonitor.OnResume+=()=>{isSuspended=false;OnSystemWake();};// Handle screen lock for securityElectron.PowerMonitor.OnLockScreen+=()=>{OnScreenLocked();};}privatevoidOnSystemSleep(){// Pause network operationsPauseNetworkOperations();// Save unsaved workAutoSaveDocuments();// Reduce resource usageMinimizeResourceUsage();}privatevoidOnSystemWake(){// Resume network operationsResumeNetworkOperations();// Check for updatesCheckForUpdates();// Restore full functionalityRestoreFullFunctionality();}privatevoidOnScreenLocked(){// Hide sensitive informationHideSensitiveData();// Pause real-time featuresPauseRealTimeFeatures();}
Battery Status Monitoring
// Monitor battery status changesElectron.PowerMonitor.OnAC+=()=>{Console.WriteLine("Plugged in - full performance mode");EnableFullPerformanceMode();};Electron.PowerMonitor.OnBattery+=()=>{Console.WriteLine("On battery - power saving mode");EnablePowerSavingMode();};