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

124 lines
4.4 KiB
TypeScript
Raw Normal View History

2016-02-17 17:36:38 +08:00
import {Plugin, Cordova} from './plugin';
/**
* The essential purpose of badge numbers is to enable an application to inform its users that it has something for them for example, unread messages when the application isnt running in the foreground.
*
2016-03-05 05:42:21 +08:00
* Requires Cordova plugin: cordova-plugin-badge. For more info, please see the [Badge plugin docs](https://github.com/katzer/cordova-plugin-badge).
2016-02-17 17:36:38 +08:00
*
* ```
2016-03-05 05:42:21 +08:00
* cordova plugin add cordova-plugin-badge
* ```
2016-02-17 17:36:38 +08:00
*
* @usage
* ```js
2016-03-05 05:42:21 +08:00
* Badge.set(10);
* Badge.increase();
* Badge.clear();
2016-02-17 17:36:38 +08:00
* ```
*/
@Plugin({
plugin: 'cordova-plugin-badge',
pluginRef: 'cordova.plugins.notification.badge'
})
export class Badge {
/**
2016-03-05 05:42:21 +08:00
* Clear the badge of the app icon.
2016-02-17 17:36:38 +08:00
*/
@Cordova()
2016-03-05 05:42:21 +08:00
static clear() {
// This Promise is replaced by one from the @Cordova decorator that wraps
// the plugin's callbacks. We provide a dummy one here so TypeScript
// knows that the correct return type is Promise, because there's no way
// for it to know the return type from a decorator.
// See https://github.com/Microsoft/TypeScript/issues/4881
return new Promise<boolean>((res, rej) => {});
2016-02-17 17:36:38 +08:00
}
/**
2016-03-05 05:42:21 +08:00
* Set the badge of the app icon.
* @param {number} number The new badge number.
* @returns {Promise}
2016-02-17 17:36:38 +08:00
*/
@Cordova()
2016-03-05 05:42:21 +08:00
static set(number: number) {
// This Promise is replaced by one from the @Cordova decorator that wraps
// the plugin's callbacks. We provide a dummy one here so TypeScript
// knows that the correct return type is Promise, because there's no way
// for it to know the return type from a decorator.
// See https://github.com/Microsoft/TypeScript/issues/4881
return new Promise<any>((res, rej) => {});
2016-02-17 17:36:38 +08:00
}
/**
2016-03-05 05:42:21 +08:00
* Get the badge of the app icon.
* @returns {Promise}
2016-02-17 17:36:38 +08:00
*/
@Cordova()
2016-03-05 05:42:21 +08:00
static get() {
// This Promise is replaced by one from the @Cordova decorator that wraps
// the plugin's callbacks. We provide a dummy one here so TypeScript
// knows that the correct return type is Promise, because there's no way
// for it to know the return type from a decorator.
// See https://github.com/Microsoft/TypeScript/issues/4881
return new Promise<any>((res, rej) => {});
}
2016-02-17 17:36:38 +08:00
/**
2016-03-05 05:42:21 +08:00
* Increase the badge number.
* @param {number} count Count to add to the current badge number
* @returns {Promise}
2016-02-17 17:36:38 +08:00
*/
@Cordova()
2016-03-05 05:42:21 +08:00
static increase(number: number) {
// This Promise is replaced by one from the @Cordova decorator that wraps
// the plugin's callbacks. We provide a dummy one here so TypeScript
// knows that the correct return type is Promise, because there's no way
// for it to know the return type from a decorator.
// See https://github.com/Microsoft/TypeScript/issues/4881
return new Promise<any>((res, rej) => {});
}
2016-02-17 17:36:38 +08:00
/**
2016-03-05 05:42:21 +08:00
* Decrease the badge number.
* @param {number} count Count to subtract from the current badge number
* @returns {Promise}
2016-02-17 17:36:38 +08:00
*/
@Cordova()
2016-03-05 05:42:21 +08:00
static decrease(number: number) {
// This Promise is replaced by one from the @Cordova decorator that wraps
// the plugin's callbacks. We provide a dummy one here so TypeScript
// knows that the correct return type is Promise, because there's no way
// for it to know the return type from a decorator.
// See https://github.com/Microsoft/TypeScript/issues/4881
return new Promise<any>((res, rej) => {});
}
2016-02-17 17:36:38 +08:00
/**
2016-03-05 05:42:21 +08:00
* Determine if the app has permission to show badges.
2016-02-17 17:36:38 +08:00
*/
@Cordova()
2016-03-05 05:42:21 +08:00
static hasPermission() {
// This Promise is replaced by one from the @Cordova decorator that wraps
// the plugin's callbacks. We provide a dummy one here so TypeScript
// knows that the correct return type is Promise, because there's no way
// for it to know the return type from a decorator.
// See https://github.com/Microsoft/TypeScript/issues/4881
return new Promise<boolean>((res, rej) => {});
}
2016-02-17 17:36:38 +08:00
2016-03-05 05:42:21 +08:00
/**
* Register permission to set badge notifications
* @returns {Promise}
*/
@Cordova()
static registerPermission() {
// This Promise is replaced by one from the @Cordova decorator that wraps
// the plugin's callbacks. We provide a dummy one here so TypeScript
// knows that the correct return type is Promise, because there's no way
// for it to know the return type from a decorator.
// See https://github.com/Microsoft/TypeScript/issues/4881
return new Promise<any>((res, rej) => {});
}
2016-02-17 17:36:38 +08:00
}