GithubHelp home page GithubHelp logo

capacitor-community / keep-awake Goto Github PK

View Code? Open in Web Editor NEW
116.0 10.0 13.0 559 KB

⚡️ Capacitor plugin to prevent devices from dimming or locking the screen.

License: MIT License

Ruby 9.91% Java 33.93% Objective-C 8.98% Swift 19.96% TypeScript 22.37% JavaScript 4.84%
capacitor android ios capacitor-community web capacitor-plugin

keep-awake's Introduction


Keep Awake

@capacitor-community/keep-awake

⚡️ Capacitor plugin to prevent devices from dimming or locking the screen.


Maintainers

Maintainer GitHub Social
Kevin Boosten kevinboosten @kevinboosten
Robin Genz robingenz @robin_genz

Installation

npm install @capacitor-community/keep-awake
npx cap sync

Configuration

No configuration required for this plugin.

Demo

A working example can be found here: robingenz/capacitor-plugin-demo

Usage

import { KeepAwake } from '@capacitor-community/keep-awake';

const keepAwake = async () => {
  await KeepAwake.keepAwake();
};

const allowSleep = async () => {
  await KeepAwake.allowSleep();
};

const isSupported = async () => {
  const result = await KeepAwake.isSupported();
  return result.isSupported;
};

const isKeptAwake = async () => {
  const result = await KeepAwake.isKeptAwake();
  return result.isKeptAwake;
};

API

keepAwake()

keepAwake() => Promise<void>

Prevent the device from dimming the screen.


allowSleep()

allowSleep() => Promise<void>

Allow the device to dim the screen.


isSupported()

isSupported() => Promise<IsSupportedResult>

Whether keep awake is supported or not.

Returns: Promise<IsSupportedResult>


isKeptAwake()

isKeptAwake() => Promise<IsKeptAwakeResult>

Check if the device is kept awake.

Returns: Promise<IsKeptAwakeResult>


Interfaces

IsSupportedResult

Prop Type
isSupported boolean

IsKeptAwakeResult

Prop Type
isKeptAwake boolean

Changelog

See CHANGELOG.md.

License

See LICENSE.

keep-awake's People

Contributors

dependabot[bot] avatar jonz94 avatar merlinschumacher avatar nunosav avatar robingenz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

keep-awake's Issues

Compile error: Attempted import error: 'registerPlugin' is not exported from '@capacitor/core'.

Describe the bug
Attempting to build Ionic React app after importing this plugin.

Failed to compile.
./node_modules/@capacitor-community/keep-awake/dist/esm/index.js
Attempted import error: 'registerPlugin' is not exported from '@capacitor/core'.

@capacitor/core 2.4.0
@Ionic/core 5.5.4
@ionic/react 5.5.4
@capacitor-community/keep-awake 2.2.0

To Reproduce
Steps to reproduce the behavior:

  1. import { KeepAwake } from '@capacitor-community/keep-awake'
  2. add const keepAwake = async () => { await KeepAwake.keepAwake()}
  3. attempt to build

Desktop (please complete the following information):

  • OS: macOS big sur
  • Version 11.1

Additional context
Add any other context about the problem here.

Capacitor V4 support

Hello, Capacitor V4 has been released. Do you have any plans for compatibility support?

bug: Android studio does not build with Capacitor 3

Now that Capacitor 3 is released I'm attempting to upgrade my app and the only thing my app stalls on is this plugin.

Android studio build fails with:

\MainActivity.java:11: error: cannot find symbol
import com.getcapacitor.community.keepawake.KeepAwake;
^
symbol: class KeepAwake
location: package com.getcapacitor.community.keepawake

I'm not smart enough to actually find the bug or suggest a fix.

I'd appreciate if someone can help out how to solve this.

I have installed keep awake ^2.0.0 (found that in another issue)

Capacitor doctor:

Latest Dependencies:

@capacitor/cli: 3.0.0
@capacitor/core: 3.0.0
@capacitor/android: 3.0.0
@capacitor/ios: 3.0.0

Installed Dependencies:

@capacitor/cli: 3.0.0
@capacitor/core: 3.0.0
@capacitor/ios: 2.4.7
@capacitor/android: 3.0.0

can't install with capacitor 4.0.x core

Doesn't look like this works with capacitor core 4.0.x yet?

npm ERR! While resolving: [email protected]
npm ERR! Found: @capacitor/[email protected]
npm ERR! node_modules/@capacitor/core
npm ERR!   @capacitor/core@"4.0.1" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer @capacitor/core@"^3.0.0" from @capacitor-community/[email protected]
npm ERR! node_modules/@capacitor-community/keep-awake
npm ERR!   @capacitor-community/keep-awake@"*" from the root project

feat: Indicator whether KeepAwake functionality is supported

Is your feature request related to a problem? Please describe:

At the moment there seems to be no easy way to determine whether or not the Browser supports KeepAwake without calling it once, and fishing for an exception. It would be handy if the plugin would supply this information.

Describe the solution you'd like:

Ideally, KeepAwake would have a boolean-prop that I can read once during the initialisation of my app that tells me whether or not the plugin will work.

Describe alternatives you've considered:

My current workaround is to try calling keepAwake() once when my app starts, and see if it throws an error:

import { KeepAwake } from "@capacitor-community/keep-awake"

const KEEP_AWAKE_TEST = KeepAwake.keepAwake()
  .then(() => {
    KeepAwake.allowSleep()
    return true
  })
  .catch((e) => {
    return false
  })

// then, later: 
const keepAwakeAvailable = await KEEP_AWAKE_TEST
if (keepAwakeAvailable ) { /* ... */ }

Additional context:

n.a.

bug: upgrade to core 6.0

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: undefined@undefined
npm ERR! Found: @capacitor/[email protected]
npm ERR! node_modules/@capacitor/core
npm ERR!   peer @capacitor/core@"^5.0.0" from @capacitor-community/[email protected]
npm ERR!   node_modules/@capacitor-community/keep-awake
npm ERR!     @capacitor-community/keep-awake@"*" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! @capacitor/app@"*" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: @capacitor/[email protected]
npm ERR! node_modules/@capacitor/core
npm ERR!   peer @capacitor/core@"^6.0.0" from @capacitor/[email protected]
npm ERR!   node_modules/@capacitor/app
npm ERR!     @capacitor/app@"*" from the root project

1de406a

bug: Does not work

I use this plugin with Ionic application on Android
I have only one page. In the class i use

ngOnInit() {

    const keepAwake = async () => {

      await KeepAwake.keepAwake();
    };

  }

I have tried to call it in different places but alway after 30s the device goes asleep.

Using keep-awake in react application seems not to be supported.

Hi.

I'm building a React application that runs on tip of capacitor-ionic. I've added the keep-awake plugin to my react project. I'm using keep-awake version 1.0 due to the version of capacitor i'm using (i'm using version 2.4.7, latest stable).

When i try to keep awake the screen i receive this message in the console: Line 2 - Msg: KeepAwake does not support web.

Newer versions of keepawake do support webview applications? Is it a limitation of version 1.0 or there is no way to get this functionalities available to web applications?

Thanks in advance.

feat: plugin version renaming to 6.0.0

Thank you for reviewing all these plugins.

The version number doesn't align with the capacitor version. Is it possible to align the version number with the capacitor version.
5.0.0 > 6.0.0

feat: add `isKeptAwake` method

Is your feature request related to a problem? Please describe.
Currently there is no way to check if the device is kept awake.

Describe the solution you'd like
Add isKeptAwake method.

Describe alternatives you've considered
No alternative solutions.

Additional context

Android returns "does not support web" in React (ionic react) app?

I am using v1 of this plugin with capacitor 2.4. In my react app, Android studio returns "Msg: KeepAwake does not support web"

I have tried firing the keepAwake() function:

-in the main index.js before the app is mounted:

`import { KeepAwake } from '@capacitor-community/keep-awake';
const keepAwake = async () => {
    await KeepAwake.keepAwake();
}
// Tried both inside and outside a useEffect
UseEffect(()=>{ keepAwake() },[])
ReactDOM.render(<App />, document.getElementById('root'));`

-in the main App.tsx component before the routing

On Android 11, the keepAwake does not work. Android studio returns "Msg: KeepAwake does not support web"

Any advice?

bug: Firefox exception

Plugin version:
3.0.0

Platform(s):

  • Firefox - any OS.

Expected behavior:

No exception.

Steps to reproduce:

Setup:

  • Quasar 2.10.2 + Capacitor 4.3.0
  • same dep in src-capacitor/package.json
  • dep in package.json : "@capacitor-community/keep-awake": "^3.0.0", (not sure I should do this, I suspect that's my mistake but couldn't find any other way to add my quasar boot script - see bellow)

Current behavior:

Exception raised

[Quasar] boot error: Error: Screen Wake Lock API not available in this browser.
    CapacitorException util.js:21
    unavailable web-plugin.js:68
    throwUnsupportedError web.ts:35
    keepAwake web.ts:11
    p runtime.js:95
    promise callback*wrapper runtime.js:92
    <anonymous> keepAwake.ts:6
    start client-entry.js:92
    async* client-entry.js:163
    promise callback* client-entry.js:161
    promise callback* client-entry.js:137

Related code:

  • in quasar.config.js:
boot: [
      'keepAwake'
    ],
  • in src/boot/keepAwake.ts:
import {KeepAwake} from '@capacitor-community/keep-awake';
import { boot } from 'quasar/wrappers'

export default boot(async () => {
  if (await KeepAwake.isSupported()) {
    await KeepAwake.keepAwake()
    console.log('Keep awake enabled')
  } else {
    console.error('Keep awake not supported')
  }
})

Other information:

I'm not confident in this setup, I just came on this project and don't know much about quasar or capacitor 😬
Sorry if it's not a bug on KeepAwake's side !

Capacitor doctor:

💊   Capacitor Doctor  💊

Latest Dependencies:

  @capacitor/cli: 4.6.1
  @capacitor/core: 4.6.1
  @capacitor/android: 4.6.1
  @capacitor/ios: 4.6.1

Installed Dependencies:

  @capacitor/cli: 4.3.0
  @capacitor/core: 4.3.0
  @capacitor/android: 4.3.0
  @capacitor/ios: 4.3.0

[success] iOS looking great! 👌
[success] Android looking great! 👌

Cannot find module '@capacitor-community/keep-awake' or its corresponding type declarations.bug:

Plugin version:
4.0.0

Platform(s):
all, using Capacitor v5 & typescript

Current behavior:
Following documentation, for the line:

import { KeepAwake } from '@capacitor-community/keep-awake';

typescript returns an error:

Cannot find module '@capacitor-community/keep-awake' or its corresponding type declarations.
Screenshot 2023-11-16 at 10 16 09 AM

Capacitor doctor:

💊   Capacitor Doctor  💊 

Latest Dependencies:

  @capacitor/cli: 5.5.1
  @capacitor/core: 5.5.1
  @capacitor/android: 5.5.1
  @capacitor/ios: 5.5.1

Installed Dependencies:

  @capacitor/android: 5.5.1
  @capacitor/ios: 5.5.1
  @capacitor/core: 5.5.1
  @capacitor/cli: 5.5.1

[success] iOS looking great! 👌
[success] Android looking great! 👌

Can you check if keepawake is active or not?

I am firing off keepawake with a component lifecycle hook, (i.e. viewDidEnter) and i dont want to keep firing it every time the component mounts if it is already active. is there any way to check for this? i.e: isKeptAwake, or willAllowSleep, etc?

bug: Phone still goes to sleep after using keepAwake() funciton

Plugin version:
@capacitor-community/[email protected]

Platform(s):
Android App
Android Web
IOS ( Untested)

Current behavior:
The phone still goes to sleep and locks al though I have used the function
await KeepAwake.keepAwake();

Expected behavior:

Steps to reproduce:

Related code:

insert short code snippets here

Other information:

Capacitor doctor:

insert the output from `npx cap doctor` here

hint: Call keepAwake() again after a video was played

Plugin version:
3.0.0

Platform(s):

  • iOS

Current behavior:
Display goes to sleep

Expected behavior:
Display keep awake

Other information:
I have a strange behaviour which I would not blame on this package but which might be good to know for one or the other.

When I call await KeepAwake.keepAwake(); the display stays active as expected. But if I then play a video that has audio via a HTMLVideo tag, iOS seems to set UIApplication.shared.isIdleTimerDisabled = false at the end of the video.

Hence the hint to call await KeepAwake.keepAwake(); again after a video has been played.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.