From c5bfe0f83ece2a4ecfdcc7a4d6bf4a1e177e1752 Mon Sep 17 00:00:00 2001 From: pniraula Date: Wed, 8 Jun 2016 10:25:24 -0400 Subject: [PATCH 1/8] Added backgroundMode.ts for plugin cordova.plugin.background-mode --- src/plugins/backgroundMode.ts | 103 ++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 src/plugins/backgroundMode.ts diff --git a/src/plugins/backgroundMode.ts b/src/plugins/backgroundMode.ts new file mode 100644 index 000000000..fec66b8be --- /dev/null +++ b/src/plugins/backgroundMode.ts @@ -0,0 +1,103 @@ +import {Plugin, Cordova} from './plugin'; + +/** +* @name Background Mode +* @description +* The ActionSheet plugin shows a native list of options the user can choose from. +* +* Requires Cordova plugin: `cordova-plugin-actionsheet`. For more info, please see the [ActionSheet plugin docs](https://github.com/EddyVerbruggen/cordova-plugin-actionsheet). +* +* @usage +* ```ts +* import {ActionSheet} from 'ionic-native'; +* +* let buttonLabels = ['Share via Facebook', 'Share via Twitter']; +* ActionSheet.show({ +* 'title': 'What do you want with this image?', +* 'buttonLabels': buttonLabels, +* 'addCancelButtonWithLabel': 'Cancel', +* 'addDestructiveButtonWithLabel' : 'Delete' +* }).then(buttonIndex => { +* console.log('Button pressed: ' + buttonLabels[buttonIndex - 1]); +* }); +* ``` +* +*/ +@Plugin({ + plugin: 'cordova-plugin-background-mode', + pluginRef: 'cordova.plugin.background-mode', + repo: 'https://github.com/katzer/cordova-plugin-background-mode', + platforms: ['Android', 'iOS', 'Windows Phone 8'] +}) +export class BackgroundMode { + @Cordova({ + sync: true + }) + static enable(): void{} + + @Cordova() + static disable(): void{} + + @Cordova() + static isEnabled(): Promise {return; } + + @Cordova() + static isActive(): Promise {return; } + + @Cordova() + static setDefaults(options?:Defaults):void{} + + @Cordova() + static configure(options?:Configure):void{} + /** + * Sets a callback for a specific event + * @param eventName The name of the event. Available events: activate, deactivate, failure + */ + @Cordova({ + sync: true + }) + static on(eventName: string, callback: any): void {} +} +/** +*Configurations avaialable only on Android +*/ +export interface Defaults{ + /** + *Title of the background task + */ + title?: String; + + /** + *The text that scrolls itself on statusbar + */ + ticker?: String; + + /** + *Description of background task + */ + text?: String; + +} + +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. + */ + silent?:boolean; + +} From 043f77a06c75190057a961eda41b2b4bb32bd3f5 Mon Sep 17 00:00:00 2001 From: pniraula Date: Wed, 8 Jun 2016 10:27:35 -0400 Subject: [PATCH 2/8] Registered backgroundmode --- src/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/index.ts b/src/index.ts index dfbdeb241..d73b13376 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,6 +12,7 @@ import {AppRate} from './plugins/apprate'; import {AppVersion} from './plugins/appversion'; import {Badge} from './plugins/badge'; import {BackgroundGeolocation} from './plugins/background-geolocation'; +import {BackgroundMode} from './plugins/backgroundmode'; import {BarcodeScanner} from './plugins/barcodescanner'; import {Base64ToGallery} from './plugins/base64togallery'; import {BatteryStatus} from './plugins/batterystatus'; From 18692b179700c1cb08676c670aed64021383c984 Mon Sep 17 00:00:00 2001 From: pniraula Date: Wed, 8 Jun 2016 10:30:02 -0400 Subject: [PATCH 3/8] updated file name --- src/plugins/{backgroundMode.ts => background-mode.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/plugins/{backgroundMode.ts => background-mode.ts} (100%) diff --git a/src/plugins/backgroundMode.ts b/src/plugins/background-mode.ts similarity index 100% rename from src/plugins/backgroundMode.ts rename to src/plugins/background-mode.ts From 715a33dceec2101f447c1851402b674a749e2ce0 Mon Sep 17 00:00:00 2001 From: pniraula Date: Wed, 8 Jun 2016 10:30:30 -0400 Subject: [PATCH 4/8] update file name to be backgorundmode.ts --- src/plugins/{background-mode.ts => backgroundmode.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/plugins/{background-mode.ts => backgroundmode.ts} (100%) diff --git a/src/plugins/background-mode.ts b/src/plugins/backgroundmode.ts similarity index 100% rename from src/plugins/background-mode.ts rename to src/plugins/backgroundmode.ts From c07e3f3e665016633db740632b3d7c418844941a Mon Sep 17 00:00:00 2001 From: pniraula Date: Wed, 8 Jun 2016 10:43:11 -0400 Subject: [PATCH 5/8] Cleaned and added comments --- src/plugins/backgroundmode.ts | 53 ++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/src/plugins/backgroundmode.ts b/src/plugins/backgroundmode.ts index fec66b8be..78ca8ec0e 100644 --- a/src/plugins/backgroundmode.ts +++ b/src/plugins/backgroundmode.ts @@ -3,25 +3,8 @@ import {Plugin, Cordova} from './plugin'; /** * @name Background Mode * @description -* The ActionSheet plugin shows a native list of options the user can choose from. -* -* Requires Cordova plugin: `cordova-plugin-actionsheet`. For more info, please see the [ActionSheet plugin docs](https://github.com/EddyVerbruggen/cordova-plugin-actionsheet). -* -* @usage -* ```ts -* import {ActionSheet} from 'ionic-native'; -* -* let buttonLabels = ['Share via Facebook', 'Share via Twitter']; -* ActionSheet.show({ -* 'title': 'What do you want with this image?', -* 'buttonLabels': buttonLabels, -* 'addCancelButtonWithLabel': 'Cancel', -* 'addDestructiveButtonWithLabel' : 'Delete' -* }).then(buttonIndex => { -* console.log('Button pressed: ' + buttonLabels[buttonIndex - 1]); -* }); -* ``` -* +* Cordova plugin to prevent the app from going to sleep while in background. +* For more info about plugin, vist: https://github.com/katzer/cordova-plugin-background-mode#android-customization */ @Plugin({ plugin: 'cordova-plugin-background-mode', @@ -30,27 +13,49 @@ import {Plugin, Cordova} from './plugin'; platforms: ['Android', 'iOS', 'Windows Phone 8'] }) export class BackgroundMode { + /** + * Enable the background mode. + * Once called, prevents the app from being puased while in background. + */ @Cordova({ sync: true }) static enable(): void{} + /** + * Disable the background mode. + * Once the background mode has been disabled, the app will be paused when in background. + */ @Cordova() static disable(): void{} + /** + * Checks if background mode is enabled or not. + */ @Cordova() static isEnabled(): Promise {return; } - + /** + * Can be used to get the information if the background mode is active. + */ @Cordova() static isActive(): Promise {return; } + /** + * Override the default title, ticker and text. + * Available only for Android platform. + */ @Cordova() static setDefaults(options?:Defaults):void{} + /** + * Modify the displayed information. + * Available only for Android platform. + */ @Cordova() - static configure(options?:Configure):void{} + static update(options?:Configure):void{} /** * Sets a callback for a specific event + * Can be used to get notified or run function when the background mode has been activated, deactivated or failed. * @param eventName The name of the event. Available events: activate, deactivate, failure */ @Cordova({ @@ -59,7 +64,7 @@ export class BackgroundMode { static on(eventName: string, callback: any): void {} } /** -*Configurations avaialable only on Android +*Default configurations avaialable only on Android */ export interface Defaults{ /** @@ -78,7 +83,9 @@ export interface Defaults{ text?: String; } - +/** +* Configurations items that can be updated. +*/ export interface Configure{ /** *Title of the background task From ab1d37d0064988c54ecbcad13048f130e9252841 Mon Sep 17 00:00:00 2001 From: P Niraula

Date: Wed, 8 Jun 2016 17:03:30 -0400 Subject: [PATCH 6/8] Added backgroundmode in index.ts --- src/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/index.ts b/src/index.ts index d73b13376..2a816d569 100644 --- a/src/index.ts +++ b/src/index.ts @@ -69,6 +69,7 @@ export { AppVersion, Badge, BackgroundGeolocation, + BackgroundMode, BarcodeScanner, Base64ToGallery, BatteryStatus, From 397515274bc8ab02772110a139b56ce7cfb9f2ae Mon Sep 17 00:00:00 2001 From: P Niraula

Date: Wed, 8 Jun 2016 21:30:41 -0400 Subject: [PATCH 7/8] Fixed pluginRef --- src/plugins/backgroundmode.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/backgroundmode.ts b/src/plugins/backgroundmode.ts index 78ca8ec0e..231b6a4de 100644 --- a/src/plugins/backgroundmode.ts +++ b/src/plugins/backgroundmode.ts @@ -7,8 +7,8 @@ import {Plugin, Cordova} from './plugin'; * For more info about plugin, vist: https://github.com/katzer/cordova-plugin-background-mode#android-customization */ @Plugin({ - plugin: 'cordova-plugin-background-mode', - pluginRef: 'cordova.plugin.background-mode', + plugin: 'de.appplant.cordova.plugin.background-mode', + pluginRef: 'cordova.plugins.backgroundMode', repo: 'https://github.com/katzer/cordova-plugin-background-mode', platforms: ['Android', 'iOS', 'Windows Phone 8'] }) From fd06247b067c5d583858a96a3bcbccda4b39af8d Mon Sep 17 00:00:00 2001 From: P Niraula

Date: Wed, 8 Jun 2016 21:40:16 -0400 Subject: [PATCH 8/8] Updated some comments and added resume option for android --- src/plugins/backgroundmode.ts | 41 +++++++++++++++-------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/src/plugins/backgroundmode.ts b/src/plugins/backgroundmode.ts index 231b6a4de..75ba0aa4d 100644 --- a/src/plugins/backgroundmode.ts +++ b/src/plugins/backgroundmode.ts @@ -4,7 +4,12 @@ import {Plugin, Cordova} from './plugin'; * @name Background Mode * @description * Cordova plugin to prevent the app from going to sleep while in background. -* For more info about plugin, vist: https://github.com/katzer/cordova-plugin-background-mode#android-customization +* Requires Cordova plugin: cordova-plugin-background-mode. For more info about plugin, vist: https://github.com/katzer/cordova-plugin-background-mode#android-customization +*@usage +* ```js +* import {BackgroundMode} from 'ionic-native'; +* +* BackgroundMode.enable(); */ @Plugin({ plugin: 'de.appplant.cordova.plugin.background-mode', @@ -44,14 +49,18 @@ export class BackgroundMode { * Override the default title, ticker and text. * Available only for Android platform. */ - @Cordova() - static setDefaults(options?:Defaults):void{} + @Cordova({ + platforms: ['Android'] + }) + static setDefaults(options?:Configure):void{} /** * Modify the displayed information. * Available only for Android platform. */ - @Cordova() + @Cordova({ + platforms: ['Android'] + }) static update(options?:Configure):void{} /** * Sets a callback for a specific event @@ -63,26 +72,7 @@ export class BackgroundMode { }) static on(eventName: string, callback: any): void {} } -/** -*Default configurations avaialable only on Android -*/ -export interface Defaults{ - /** - *Title of the background task - */ - title?: String; - /** - *The text that scrolls itself on statusbar - */ - ticker?: String; - - /** - *Description of background task - */ - text?: String; - -} /** * Configurations items that can be updated. */ @@ -107,4 +97,9 @@ export interface Configure{ */ 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. + */ + resume?:boolean; + }