Ever needed to know if your user's phone screen is turning on or off? Look no further!
All you need to do is take the web block contained in this plugin and drop it anywhere you want screen event detection and event handler to live. This might be in your layout web block, or somewhere on a specific screen where you want to listen for those events. In my demo app, I have the block in the main screen.
Then, you just have two events to worry about: ScreenTurnedOff and ScreenTurnedOn. Those should be self-explanatory, and you can define event handlers for both.
Those events are fired the moment the screen state changes, so the logic contained in ScreenTurnedOff will begin to execute as soon as the screen turns off. How long long-running logic will continue to execute while the phone screen is off, and at what speed, I can't guarantee. Ditto for if your app goes to the background before the screen turns off. But in my simple tests in Android 9/10 and iOS 13, my Javacsript handler did capture a timestamp of the moment the screen was turned off in both use cases. However, your mileage may vary by exact device and operating system.
See the source at https://github.com/wrobins/cordova-plugin-screenevents
Removed error that would get spammed if the plugin was not loaded correctly.