Skip to content

Prevent your Capacitor app from getting some sleep!

Notifications You must be signed in to change notification settings

galfert/keep-awake

 
 

Repository files navigation

capacitor-keep-awake

npm version

Prevent your screen from getting some sleep!

Installation

npm i @boosten/capacitor-keep-awake

Configuration

Example

Check out the example repo: capacitor-keep-awake-example

import { Plugins } from '@capacitor/core';

@Component({
  template: `
    <button (click)="keepAwake()">keep awake!</button>
    <button (click)="allowSleep()">let me sleep!</button>
  `
})
export class SignupComponent {
  async keepAwake() {
    await Plugins.KeepAwake.keepAwake();
  }

  async allowSleep() {
    await Plugins.KeepAwake.allowSleep();
  }
}

Web

This functionality is not applicable to the browser.

iOS

No extra steps required 🙂.

Android

You have to register your plugin in your app main activity. See official Capacitor docs

public class MainActivity extends BridgeActivity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Initializes the Bridge
    this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {
      {
        // Additional plugins you've installed go here
        // Ex: add(TotallyAwesomePlugin.class);
        add(KeepAwake.class);
      }
    });
  }
}

Credits

Capacitor version of the plugin: cordova insommia.

About

Prevent your Capacitor app from getting some sleep!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 32.0%
  • Swift 28.5%
  • Ruby 12.9%
  • TypeScript 12.7%
  • Objective-C 10.2%
  • JavaScript 3.7%