Prevent your screen from getting some sleep!
npm i @boosten/capacitor-keep-awake
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();
}
}
This functionality is not applicable to the browser.
No extra steps required 🙂.
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);
}
});
}
}
Capacitor version of the plugin: cordova insommia.