diff --git a/.travis.yml b/.travis.yml index 8d7d0cc..323e3b3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,8 +13,13 @@ install: - cd ../../ - node_modules/.bin/cordova create app-preferences-app - cd app-preferences-app +script: - ../node_modules/.bin/cordova platform add ios android - ../node_modules/.bin/cordova plugin add https://github.com/apla/me.apla.cordova.app-preferences - ../node_modules/.bin/cordova prepare -script: - - cordova-paramedic --platform ios --plugin plugins/me.apla.cordova.app-preferences + - ../node_modules/.bin/cordova platform rm android + - ../node_modules/.bin/cordova platform add android + - ../node_modules/.bin/cordova plugin rm cordova-plugin-app-preferences + - ../node_modules/.bin/cordova plugin add https://github.com/apla/me.apla.cordova.app-preferences + - ../node_modules/.bin/cordova prepare + diff --git a/bin/after_plugin_add.js b/bin/after_plugin_add.js deleted file mode 100644 index 3240dcc..0000000 --- a/bin/after_plugin_add.js +++ /dev/null @@ -1,18 +0,0 @@ -'use strict'; - -module.exports = function (context) { - var req = context.requireCordovaModule, - path = req('path'), - fs = require("./lib/filesystem")(req('q'), req('fs'), path), - settings = require("./lib/settings")(fs, path); - - return settings.get() - .catch(function(err) { - if (err.code === 'NEXIST') { - console.log("app-settings.json not found: creating a sample file"); - return settings.create(); - } - - throw err; - }); -}; diff --git a/bin/after_plugin_install.js b/bin/after_plugin_install.js new file mode 100644 index 0000000..4c2c3b8 --- /dev/null +++ b/bin/after_plugin_install.js @@ -0,0 +1,27 @@ +'use strict'; + +module.exports = function (context) { + var req = context.requireCordovaModule, + Q = req('q'), + path = req('path'), + fs = require("./lib/filesystem")(Q, req('fs'), path), + settings = require("./lib/settings")(fs, path), + android = require("./lib/android")(fs, path, req('elementtree'), req('cordova-lib/src/cordova/util'), req('cordova-lib').configparser), + ios = require("./lib/ios")(Q, fs, path, req('plist'), req('xcode')); + + return settings.get() + .then(function (config) { + return Q.all([ + android.afterPluginInstall(config), + // ios.afterPluginInstall(config) // not implemented for iOS + ]); + }) + .catch(function(err) { + if (err.code === 'NEXIST') { + console.log("app-settings.json not found: creating a sample file"); + return settings.create(); + } + + throw err; + }); +}; diff --git a/bin/before_plugin_rm.js b/bin/before_plugin_uninstall.js similarity index 100% rename from bin/before_plugin_rm.js rename to bin/before_plugin_uninstall.js diff --git a/bin/lib/android.js b/bin/lib/android.js index 860691e..94b3109 100644 --- a/bin/lib/android.js +++ b/bin/lib/android.js @@ -149,6 +149,19 @@ module.exports = function (fs, path, ET, cordova_util, ConfigParser) { .then(function () { return fs.mkdir('platforms/android/res/xml/values'); }) .then(function (prefs) { return fs.writeFile('platforms/android/res/xml/values/apppreferences.xml', preferencesStringDocument.write()); }) + .then(function () { console.log('android preferences file was successfully generated'); }) + .catch(function (err) { + if (err.code === 'NEXIST') { + console.log("Platform android not found: skipping"); + return; + } + + throw err; + }); + } + + function afterPluginInstall () { + return fs.exists('platforms/android') // Import preferences into native android project .then(function () { return fs.readFile(path.resolve(__dirname, '../../src/android/AppPreferencesActivity.template')); }) .then(function (tmpl) { @@ -167,7 +180,6 @@ module.exports = function (fs, path, ET, cordova_util, ConfigParser) { return fs.writeFile(activityFileName, data); }) - .then(function () { console.log('android preferences file was successfully generated'); }) .catch(function (err) { if (err.code === 'NEXIST') { console.log("Platform android not found: skipping"); @@ -176,8 +188,9 @@ module.exports = function (fs, path, ET, cordova_util, ConfigParser) { throw err; }); + } - + function clean(config) { return fs.exists('platforms/android') @@ -211,6 +224,7 @@ module.exports = function (fs, path, ET, cordova_util, ConfigParser) { buildSettings: buildSettings, build: build, + afterPluginInstall: afterPluginInstall, clean: clean }; -}; \ No newline at end of file +}; diff --git a/plugin.xml b/plugin.xml index b8e0a33..16c668c 100644 --- a/plugin.xml +++ b/plugin.xml @@ -18,8 +18,8 @@ - - + +