mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2025-02-22 01:19:36 +08:00
refactor(batterystatus): update event based methods to use new @Cordova wrapper implementation
This commit is contained in:
parent
c947437610
commit
120d20bfe4
@ -1,4 +1,4 @@
|
|||||||
import {Plugin} from './plugin';
|
import {Plugin, Cordova} from './plugin';
|
||||||
import {Observable} from "rxjs/Observable";
|
import {Observable} from "rxjs/Observable";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -35,25 +35,31 @@ export class BatteryStatus {
|
|||||||
* Watch the change in battery level
|
* Watch the change in battery level
|
||||||
* @returns {Observable} Returns an observable that pushes a status object
|
* @returns {Observable} Returns an observable that pushes a status object
|
||||||
*/
|
*/
|
||||||
static onChange () : Observable<StatusObject> {
|
@Cordova({
|
||||||
return getEventObservable("batterylevel");
|
eventObservable: true,
|
||||||
}
|
event: 'batterylevel'
|
||||||
|
})
|
||||||
|
static onChange () : Observable<StatusObject> {return}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Watch when the battery level goes low
|
* Watch when the battery level goes low
|
||||||
* @returns {Observable<StatusObject>} Returns an observable that pushes a status object
|
* @returns {Observable<StatusObject>} Returns an observable that pushes a status object
|
||||||
*/
|
*/
|
||||||
static onLow () : Observable<StatusObject> {
|
@Cordova({
|
||||||
return getEventObservable("batterylow");
|
eventObservable: true,
|
||||||
}
|
event: 'batterylow'
|
||||||
|
})
|
||||||
|
static onLow () : Observable<StatusObject> {return}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Watch when the battery level goes to critial
|
* Watch when the battery level goes to critial
|
||||||
* @returns {Observable<StatusObject>} Returns an observable that pushes a status object
|
* @returns {Observable<StatusObject>} Returns an observable that pushes a status object
|
||||||
*/
|
*/
|
||||||
static onCritical () : Observable<StatusObject> {
|
@Cordova({
|
||||||
return getEventObservable("batterycritical");
|
eventObservable: true,
|
||||||
}
|
event: 'batterycritical'
|
||||||
|
})
|
||||||
|
static onCritical () : Observable<StatusObject> {return}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,17 +73,4 @@ export interface StatusObject {
|
|||||||
* A boolean that indicates whether the device is plugged in
|
* A boolean that indicates whether the device is plugged in
|
||||||
*/
|
*/
|
||||||
isPlugged : boolean
|
isPlugged : boolean
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Wrap the event with an observable
|
|
||||||
* @param event
|
|
||||||
* @returns {Observable}
|
|
||||||
*/
|
|
||||||
function getEventObservable (event : string) : Observable<StatusObject> {
|
|
||||||
return new Observable(observer => {
|
|
||||||
let callback = (status : any) => observer.next(status);
|
|
||||||
window.addEventListener(event, callback, false);
|
|
||||||
return () => window.removeEventListener(event, callback, false);
|
|
||||||
});
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user