awesome-cordova-plugins/src/plugins/backgroundmode.ts

127 lines
3.7 KiB
TypeScript
Raw Normal View History

2016-07-08 06:35:11 +08:00
import { Cordova, Plugin } from './plugin';
/**
* @name Background Mode
* @description
2016-06-08 22:43:11 +08:00
* Cordova plugin to prevent the app from going to sleep while in background.
* Requires Cordova plugin: cordova-plugin-background-mode. For more info about plugin, vist: https://github.com/katzer/cordova-plugin-background-mode#android-customization
*@usage
* ```typescript
* import { BackgroundMode } from 'ionic-native';
2016-07-02 03:46:15 +08:00
*
* BackgroundMode.enable();
* ```
2016-07-02 03:46:15 +08:00
*
* @advanced
*
* Configuration options
*
* | Property | Type | Description |
* |----------|-----------|------------------------------------------------------------------------------|
* | title | `string` | Title of the background task. Optional |
* | ticker | `string` | The text that scrolls itself on the statusbar. Optional |
* | text | `string` | Description of the background task. Optional |
* | silent | `boolean` | If the plugin will display a notification or not. Default is false. Optional |
* | resume | `boolean` | Bring the app into the foreground if the notification is tapped. Optional |
*
*/
@Plugin({
plugin: 'cordova-plugin-background-mode',
2016-06-09 09:30:41 +08:00
pluginRef: 'cordova.plugins.backgroundMode',
repo: 'https://github.com/katzer/cordova-plugin-background-mode',
platforms: ['Android', 'iOS', 'Windows Phone 8']
})
export class BackgroundMode {
2016-06-08 22:43:11 +08:00
/**
* Enable the background mode.
2016-06-09 22:28:46 +08:00
* Once called, prevents the app from being paused while in background.
2016-06-08 22:43:11 +08:00
*/
@Cordova({
sync: true
})
2016-07-08 06:35:11 +08:00
static enable(): void { }
2016-07-08 06:35:11 +08:00
/**
* Disable the background mode.
* Once the background mode has been disabled, the app will be paused when in background.
*/
@Cordova()
2016-07-08 06:35:11 +08:00
static disable(): void { }
2016-06-08 22:43:11 +08:00
/**
* Checks if background mode is enabled or not.
2016-07-02 03:46:15 +08:00
* @returns {boolean} returns a true of false if the background mode is enabled.
2016-06-08 22:43:11 +08:00
*/
@Cordova()
2016-07-08 06:35:11 +08:00
static isEnabled(): Promise<boolean> { return; }
2016-07-02 03:46:15 +08:00
2016-06-08 22:43:11 +08:00
/**
* Can be used to get the information if the background mode is active.
2016-07-02 03:46:15 +08:00
* @returns {boolean} returns tru or flase if the background mode is active.
2016-06-08 22:43:11 +08:00
*/
@Cordova()
2016-07-08 06:35:11 +08:00
static isActive(): Promise<boolean> { return; }
2016-06-08 22:43:11 +08:00
/**
* Override the default title, ticker and text.
* Available only for Android platform.
2016-07-02 03:46:15 +08:00
* @param {Configure} options List of option to configure. See table below
2016-06-08 22:43:11 +08:00
*/
@Cordova({
platforms: ['Android']
})
2016-07-08 06:35:11 +08:00
static setDefaults(options?: Configure): void { }
2016-06-08 22:43:11 +08:00
/**
* Modify the displayed information.
* Available only for Android platform.
2016-07-02 03:46:15 +08:00
* @param {Configure} options Any options you want to update. See table below.
2016-06-08 22:43:11 +08:00
*/
@Cordova({
platforms: ['Android']
})
2016-07-08 06:35:11 +08:00
static update(options?: Configure): void { }
2016-07-02 03:46:15 +08:00
/**
* Sets a callback for a specific event
2016-06-08 22:43:11 +08:00
* Can be used to get notified or run function when the background mode has been activated, deactivated or failed.
2016-08-24 00:47:11 +08:00
* @param {string} eventName The name of the event. Available events: activate, deactivate, failure
*/
@Cordova({
sync: true
})
2016-07-08 06:35:11 +08:00
static on(eventName: string, callback: any): void { }
}
2016-06-08 22:43:11 +08:00
/**
* Configurations items that can be updated.
*/
2016-06-09 22:28:46 +08:00
export interface Configure {
/**
*Title of the background task
*/
title?: String;
/**
*The text that scrolls itself on statusbar
*/
ticker?: String;
/**
*Description of background task
*/
text?: String;
/**
*Boolean, if true plugin will not display a notification. Default is false.
*/
2016-06-09 22:28:46 +08:00
silent?: boolean;
/**
*Boolean. By default the app will come to foreground when taping on the notification. If false, plugin wont come to foreground when tapped.
*/
2016-06-09 22:28:46 +08:00
resume?: boolean;
}