0.0.1 • Published 4 years ago

@boosten/capacitor-keep-awake v0.0.1

Weekly downloads
293
License
MIT
Repository
github
Last release
4 years ago

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.