Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 746
PowerMonitor
Monitor system power events like sleep, wake, and battery status.
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.
Emitted when the system changes to AC power.
Emitted when system changes to battery power.
Emitted when the system is about to lock the screen.
Emitted when system is resuming.
Emitted when the system is about to reboot or shut down.
Emitted when the system is suspending.
Emitted when the system is about to unlock the screen.
// 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();};// Handle screen lock eventsElectron.PowerMonitor.OnLockScreen+=()=>{Console.WriteLine("Screen locking");// Pause real-time operationsPauseRealTimeOperations();};Electron.PowerMonitor.OnUnLockScreen+=()=>{Console.WriteLine("Screen unlocking");// Resume real-time operationsResumeRealTimeOperations();};// 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();};// Handle system shutdownElectron.PowerMonitor.OnShutdown+=()=>{Console.WriteLine("System shutting down");// Save critical data and exit gracefullySaveAndExit();};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();}// 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();};- Electron.App - Application lifecycle events
- Electron.Notification - Notify users about power events
- Electron PowerMonitor Documentation - Official Electron power monitor API
Want to contribute to this documentation? Please fork and create a PR! The Wiki is autogenerated from the /docs content in the repository.