From 5fdfb9885ceb4c7a8f874a655184c509718175b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Katzer?= Date: Fri, 10 Feb 2017 16:33:38 +0100 Subject: [PATCH] Previously configured settings got overwritten by defaults [Fixes #179] --- www/background-mode.js | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/www/background-mode.js b/www/background-mode.js index a96c3de..4731a27 100644 --- a/www/background-mode.js +++ b/www/background-mode.js @@ -88,6 +88,15 @@ exports.getDefaults = function () { return this._defaults; }; +/** + * The actual applied settings. + * + * @return [ Object ] + */ +exports.getSettings = function () { + return this._settings || {}; +}; + /** * Overwrite the default settings. * @@ -118,10 +127,15 @@ exports.setDefaults = function (overrides) { * @return [ Void ] */ exports.configure = function (options) { - var settings = this.mergeWithDefaults(options); + var settings = this.getSettings(), + defaults = this.getDefaults(); + + this.mergeObjects(options, settings); + this.mergeObjects(options, defaults); + this._settings = options; if (this._isAndroid) { - cordova.exec(null, null, 'BackgroundMode', 'configure', [settings, true]); + cordova.exec(null, null, 'BackgroundMode', 'configure', [options, true]); } }; @@ -348,15 +362,14 @@ exports.onfailure = function () {}; * Merge settings with default values. * * @param [ Object ] options The custom options. + * @param [ Object ] toMergeIn The options to merge in. * * @return [ Object ] Default values merged with custom values. */ -exports.mergeWithDefaults = function (options) { - var defaults = this.getDefaults(); - - for (var key in defaults) { +exports.mergeObjects = function (options, toMergeIn) { + for (var key in toMergeIn) { if (!options.hasOwnProperty(key)) { - options[key] = defaults[key]; + options[key] = toMergeIn[key]; continue; } }