Search code examples
meteormeteor-cordova

How to keep mobile screen on


I'm working on a Meteor Application which runs for long times and I'm looking for a way to keep the screen on when there's no user activity (while the app is running of course).

Thanks


Solution

  • If I read the documentation correctly, and I may not, because I've never used this before, then you can add the insomnia plugin to your cordova/phonegap build like this:

    $ meteor add cordova:nl.x-services.plugins.insomnia@https://github.com/EddyVerbruggen/Insomnia-PhoneGap-Plugin/tarball/47ba15a4ad791eb4d5a0643cdb7ef69f73109e15
    

    And then use:

    window.plugins.insomnia.keepAwake()
    

    and

    window.plugins.insomnia.allowSleepAgain()
    

    Update for Meteor 1.2:

    Install plugins from a Git URL: Meteor no longer supports installing Cordova plugins from tarball URLs, but does support Git URLs with a SHA reference (like https://github.com/apache/cordova-plugin-file#c452f1a67f41cb1165c92555f0e721fbb07329cc). Existing GitHub tarball URLs are converted automatically.

    This means that you now need to use:

    $ meteor add cordova:nl.x-services.plugins.insomnia@https://github.com/EddyVerbruggen/Insomnia-PhoneGap-Plugin#47ba15a4ad791eb4d5a0643cdb7ef69f73109e15
    

    Update 2

    As user3819370 points out, the plugin is now in the registry being used by meteor, so you can simply install it like this:

    meteor add cordova:cordova-plugin-insomnia@4.0.1