From 8280fdeb3a7a1f3a5d745959a0e9a6644d022d29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Mon, 17 Nov 2014 14:19:29 +0100 Subject: [PATCH] Clean up --- src/android/BackgroundMode.java | 16 ++++++++-------- src/ios/APPBackgroundMode.m | 3 ++- src/wp8/BackgroundMode.cs | 9 --------- www/background-mode.js | 9 ++++++--- 4 files changed, 16 insertions(+), 21 deletions(-) diff --git a/src/android/BackgroundMode.java b/src/android/BackgroundMode.java index 0aa95e8..3b4fac6 100644 --- a/src/android/BackgroundMode.java +++ b/src/android/BackgroundMode.java @@ -81,14 +81,9 @@ public class BackgroundMode extends CordovaPlugin { public boolean execute (String action, JSONArray args, CallbackContext callback) throws JSONException { - if (action.equalsIgnoreCase("observeLifeCycle")) { - // Nothing to do here - return true; - } - if (action.equalsIgnoreCase("configure")) { setSettings(args.getJSONObject(0)); - + updateNotifcation(); return true; } @@ -160,15 +155,20 @@ public class BackgroundMode extends CordovaPlugin { } /** - * Update the settings and maybe the notification. + * Update the settings for the notification. * * @param newSettings * The new settings */ private void setSettings(JSONObject newSettings) { settings = newSettings; + } - if (inBackground) { + /** + * Update the notification. + */ + private void updateNotifcation() { + if (isBind) { stopService(); startService(); } diff --git a/src/ios/APPBackgroundMode.m b/src/ios/APPBackgroundMode.m index e6a940f..30c2e97 100644 --- a/src/ios/APPBackgroundMode.m +++ b/src/ios/APPBackgroundMode.m @@ -34,12 +34,13 @@ [self disable:NULL]; [self configureAudioPlayer]; [self configureAudioSession]; + [self observeLifeCycle]; } /** * Register the listener for pause and resume events. */ -- (void) observeLifeCycle:(CDVInvokedUrlCommand *)command +- (void) observeLifeCycle { NSNotificationCenter* listener = [NSNotificationCenter defaultCenter]; diff --git a/src/wp8/BackgroundMode.cs b/src/wp8/BackgroundMode.cs index df69b20..6eeb9e0 100644 --- a/src/wp8/BackgroundMode.cs +++ b/src/wp8/BackgroundMode.cs @@ -84,15 +84,6 @@ namespace Cordova.Extension.Commands Deactivate(); } - /// - /// @js-interface - /// Registriert die Listener für die (sleep/resume) Events - /// - public void observeLifeCycle (string args) - { - // Konstruktor wird aufgerufen, falls Instanz erstellt wurde - } - /// /// Startet das Aktualisieren des Standpunktes /// diff --git a/www/background-mode.js b/www/background-mode.js index 15f66cb..18ccdd3 100644 --- a/www/background-mode.js +++ b/www/background-mode.js @@ -19,7 +19,7 @@ under the License. */ -var exec = require('cordova/exec'), +var exec = require('cordova/exec'), channel = require('cordova/channel'); @@ -27,10 +27,13 @@ var exec = require('cordova/exec'), document.addEventListener('backbutton', function () {}, false); channel.deviceready.subscribe(function () { - // Registriert die Listener für die (sleep/resume) Events - cordova.exec(null, null, 'BackgroundMode', 'observeLifeCycle', []); // Set the default settings exports.configure(); + + // Only enable WP8 by default + if (['WinCE', 'Win32NT'].indexOf(device.platform)) { + exports.enable(); + } });