Skip to content

Commit

Permalink
fixes apla#57, apla#53
Browse files Browse the repository at this point in the history
Hook for plugin add/rm will be used when every plugin is installed, need to use install/uninstall
  • Loading branch information
apla committed Nov 9, 2015
1 parent bb3a0c0 commit 1f6e12e
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 25 deletions.
9 changes: 7 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

18 changes: 0 additions & 18 deletions bin/after_plugin_add.js

This file was deleted.

27 changes: 27 additions & 0 deletions bin/after_plugin_install.js
Original file line number Diff line number Diff line change
@@ -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;
});
};
File renamed without changes.
20 changes: 17 additions & 3 deletions bin/lib/android.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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");
Expand All @@ -176,8 +188,9 @@ module.exports = function (fs, path, ET, cordova_util, ConfigParser) {

throw err;
});

}

function clean(config) {

return fs.exists('platforms/android')
Expand Down Expand Up @@ -211,6 +224,7 @@ module.exports = function (fs, path, ET, cordova_util, ConfigParser) {
buildSettings: buildSettings,

build: build,
afterPluginInstall: afterPluginInstall,
clean: clean
};
};
};
4 changes: 2 additions & 2 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
<asset src="www/task/AppPreferences.js" target="task/AppPreferences.js" />

<hook type="after_prepare" src="bin/after_prepare.js" />
<hook type="after_plugin_add" src="bin/after_plugin_add.js" />
<hook type="before_plugin_rm" src="bin/before_plugin_rm.js" />
<hook type="after_plugin_install" src="bin/after_plugin_install.js" />
<hook type="before_plugin_uninstall" src="bin/before_plugin_uninstall.js" />

<!-- android -->
<platform name="android">
Expand Down

0 comments on commit 1f6e12e

Please sign in to comment.