Skip to content

Commit cd82a53

Browse files
authored
feat(power-management): add power management support (#489)
1 parent 00d87db commit cd82a53

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ import { OneSignal } from './plugins/onesignal';
7272
import { PhotoViewer } from './plugins/photo-viewer';
7373
import { ScreenOrientation } from './plugins/screen-orientation';
7474
import { PinDialog } from './plugins/pin-dialog';
75+
import { PowerManagement } from './plugins/power-management';
7576
import { Printer } from './plugins/printer';
7677
import { Push } from './plugins/push';
7778
import { SafariViewController } from './plugins/safari-view-controller';
@@ -178,6 +179,7 @@ OneSignal,
178179
PhotoViewer,
179180
ScreenOrientation,
180181
PinDialog,
182+
PowerManagement,
181183
Screenshot,
182184
SecureStorage,
183185
Shake,
@@ -266,6 +268,7 @@ window['IonicNative'] = {
266268
PhotoViewer: PhotoViewer,
267269
ScreenOrientation: ScreenOrientation,
268270
PinDialog: PinDialog,
271+
PowerManagement: PowerManagement,
269272
SafariViewController: SafariViewController,
270273
Screenshot: Screenshot,
271274
SecureStorage: SecureStorage,

src/plugins/power-management.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import {Plugin, Cordova} from './plugin';
2+
/**
3+
* @name PowerManagement
4+
* @description
5+
* The PowerManagement plugin offers access to the devices power-management functionality.
6+
* It should be used for applications which keep running for a long time without any user interaction.
7+
*
8+
* @usage
9+
* ```
10+
* import {PowerManagement} from 'ionic-native';
11+
*
12+
* PowerManagement.acquire()
13+
* .then(onSuccess)
14+
* .catch(onError);
15+
*
16+
* ```
17+
*/
18+
@Plugin({
19+
plugin: 'cordova-plugin-powermanagement-orig',
20+
pluginRef: 'https://github.com/Viras-/cordova-plugin-powermanagement',
21+
repo: 'powerManagement'
22+
})
23+
export class PowerManagement {
24+
/**
25+
* Acquire a wakelock by calling this.
26+
*/
27+
@Cordova()
28+
static acquire(): Promise<any> {return; }
29+
30+
/**
31+
* This acquires a partial wakelock, allowing the screen to be dimmed.
32+
*/
33+
@Cordova()
34+
static dim(): Promise<any> {return; }
35+
36+
/**
37+
* Release the wakelock. It's important to do this when you're finished with the wakelock, to avoid unnecessary battery drain.
38+
*/
39+
@Cordova()
40+
static release(): Promise<any> {return; }
41+
42+
/**
43+
* By default, the plugin will automatically release a wakelock when your app is paused (e.g. when the screen is turned off, or the user switches to another app).
44+
* It will reacquire the wakelock upon app resume. If you would prefer to disable this behaviour, you can use this function.
45+
* @param set {boolean}
46+
*/
47+
@Cordova()
48+
static setReleaseOnPause(set: boolean): Promise<any> {return; }
49+
}

0 commit comments

Comments
 (0)