Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Battery/AC power, plus more #34

Merged
merged 4 commits into from
Sep 2, 2024
Merged

Conversation

danjohnson95
Copy link
Contributor

@danjohnson95 danjohnson95 commented Aug 30, 2024

Hey! Thanks for all your hard work on NativePHP.

This PR adds the ability to determine the power state of the current device (on battery or connected to AC), as well as some other data we can get from Electron's powerMonitor.

This could come in really useful for apps that run long running jobs, or computationally expensive actions.

Here's a video of it in action: my app is hooking into the PowerStateChanged event to show a notification.

IMG_5369.MOV

As well as an event for power state changes, it also implements:

  • An event for when the thermal state changes (ie, when the fans are blaring)
  • An event for when the CPU is being clocked (ie power saving mode)
  • A getter for the current thermal state
  • A getter to determine the idle state
  • A getter to determine how long the device has been idle for
  • A getter for whether we're on battery power or not

I've got another PR for the NativePHP/Laravel repo to complete this functionality, and I'll add a PR for the docs if you're happy with this change.

There are a few more things in the powerMonitor that I can implement too if you're interested.

Copy link
Member

@simonhamp simonhamp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

@simonhamp
Copy link
Member

@danjohnson95 please do prepare a docs PR too

@danjohnson95
Copy link
Contributor Author

Docs PR here: NativePHP/nativephp.com#40

@simonhamp simonhamp merged commit 1d456dc into NativePHP:main Sep 2, 2024
1 check failed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants