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

Latest commit

 

History

History
92 lines (70 loc) · 3.07 KB

README.md

File metadata and controls

92 lines (70 loc) · 3.07 KB


keep-awake

@capacitor-community/keep-awake

Capacitor community plugin to prevent your screen from getting some sleep!


Maintainers

Maintainer GitHub Social
Kevin Boosten boosten @Boostuh1

Installation

npm i @capacitor-community/keep-awake

Configuration

iOS

No extra steps required 🙂.

Android

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

import com.getcapacitor.community.keepawake.KeepAwake;

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);
          }
        }
      );
  }
}

Usage

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

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

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

Credits

Capacitor version of the plugin: cordova insommia.