NativePHP is currently in alpha development
Let's get to beta!- System Idle State
- System Idle Time
- Current Thermal State
- Battery Information
- Events
- `PowerStateChanged`
- `SpeedLimitChanged`
- `ThermalStateChanged`
The power monitor allows you to gather information about the power state of the device.
#System Idle State
You can check if the system is idle with the getSystemIdleState
method.
It expects a int $threshold
argument, which is the number of seconds the system must be idle before it is considered idle. And it'll return an enum value of SystemIdleStatesEnum
.
1use Native\Laravel\Enums\SystemIdleStatesEnum;2use Native\Laravel\Facades\PowerMonitor;3 4$state = PowerMonitor::getSystemIdleState(60);5 6if ($state === SystemIdleStatesEnum::IDLE) {7 // The system is idle!8}
The possible values for the SystemIdleStatesEnum
enum are:
-
SystemIdleStatesEnum::ACTIVE
-
SystemIdleStatesEnum::IDLE
-
SystemIdleStatesEnum::LOCKED
-
SystemIdleStatesEnum::UNKNOWN
#System Idle Time
You can get the number of seconds the system has been idle with the getSystemIdleTime
method.
1use Native\Laravel\Facades\PowerMonitor;2 3$seconds = PowerMonitor::getSystemIdleTime();
#Current Thermal State
You can get the current thermal state of the system with the getCurrentThermalState
method. It'll return an enum value of ThermalStatesEnum
.
1use Native\Laravel\Enums\ThermalStatesEnum;2use Native\Laravel\Facades\PowerMonitor;3 4$thermalState = PowerMonitor::getCurrentThermalState();5 6if ($state === ThermalStatesEnum::CRITICAL) {7 // Wow, the CPU is running hot!8}
The possible values for the ThermalStatesEnum
enum are:
-
ThermalStatesEnum::UNKNOWN
-
ThermalStatesEnum::NOMINAL
-
ThermalStatesEnum::FAIR
-
ThermalStatesEnum::SERIOUS
-
ThermalStatesEnum::CRITICAL
#Battery Information
You can determine if the device is running on battery power or AC power with the isOnBatteryPower
method.
1use Native\Laravel\Facades\PowerMonitor;2 3if (PowerMonitor::isOnBatteryPower()) {4 // The device is running on battery power.5} else {6 // The device is running on AC power.7}
#Events
You can listen to the following events to get handle when the system's power state changes:
#PowerStateChanged
This Native\Laravel\Events\PowerStateChanged
event is fired whenever the power state of the system changes. For example, when the system goes from battery power to AC power, or vice versa.
The event contains a public $state
property which is an enum value of Native\Laravel\Enums\PowerStatesEnum
.
#SpeedLimitChanged
This Native\Laravel\Events\SpeedLimitChanged
event is fired whenever the CPU speed limit changes, usually due to thermal throttling or low battery.
The event contains a public $limit
property which is the percentage of the maximum CPU speed that is currently allowed.
#ThermalStateChanged
The Native\Laravel\Events\ThermalStateChanged
event is fired whenever the thermal state of the system changes.
The event contains a public $state
property which is an enum value of Native\Laravel\Enums\ThermalStatesEnum
.
- System Idle State
- System Idle Time
- Current Thermal State
- Battery Information
- Events
- `PowerStateChanged`
- `SpeedLimitChanged`
- `ThermalStateChanged`