Re: [whatwg] Proposal: Wake Lock API

On August 19, 2014 at 2:08:04 PM, Jonas Sicking (jonas@sicking.cc) wrote:
> > > How would you handle feature detection with this design?
>  
> This is a good question. I don't have a better solution than adding  
> separate DisplayWakeLock() and SystemWakeLock() classes.  
>  

Might make sense to do it this way regardless. It might be that we need to add different behavior for each type of lock in the future.  

Ok, so taking into consideration the feedback received so far - how about something like: 

```
[Constructor]
interface DisplayLock : WakeLock {
   static readonly attribute boolean isHeld;
}

[Constructor]
interface SystemLock : WakeLock {
   static readonly attribute boolean isHeld;
}

interface WakeLock : EventTarget {
   Promise<void> request();
   Promise<void> release();
   attribute EventHandler onlost;
}
```

Usage:
```
//feature detect + lock check
if (DisplayLock && !DisplayLock.isHeld){
   var lock = new DisplayLock();
   lock.request().then(yay,boo);

   //listen in case the lock is lost:
   lock.addEventListener("lost", function(){
      //try again maybe when the battery has more juice
   });
}
```

Received on Tuesday, 19 August 2014 20:30:12 UTC