Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelistik committed Mar 25, 2016
2 parents daafce0 + 87c005f commit 2b360dd
Show file tree
Hide file tree
Showing 10 changed files with 379 additions and 57 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Debug Freifunk wifi nodes with the popular
[Wifi Analyzer](https://play.google.com/store/apps/details?id=com.farproc.wifi.analyzer)
app - and get the human readably node names displayed, instead of their MAC
app - and get the human readable node names displayed, instead of their MAC
addresses.

## How
Expand All @@ -12,4 +12,3 @@ a file `WifiAnalyzer_Alias.txt` from your phone's SD storage.

This app will generate such an alias file in the correct location, so you
can import it: open Wifi Analyzer and do Settings > Manage aliases > Import.

10 changes: 10 additions & 0 deletions build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"android":
{
"release":
{
"keystore": "../android-releasekey.keystore",
"alias": "releasekey"
}
}
}
196 changes: 196 additions & 0 deletions hooks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
<!--
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
-->
# Cordova Hooks

Cordova Hooks represent special scripts which could be added by application and plugin developers or even by your own build system to customize cordova commands. Hook scripts could be defined by adding them to the special predefined folder (`/hooks`) or via configuration files (`config.xml` and `plugin.xml`) and run serially in the following order:
* Application hooks from `/hooks`;
* Application hooks from `config.xml`;
* Plugin hooks from `plugins/.../plugin.xml`.

__Remember__: Make your scripts executable.

__Note__: `.cordova/hooks` directory is also supported for backward compatibility, but we don't recommend using it as it is deprecated.

## Supported hook types
The following hook types are supported:

after_build/
after_compile/
after_docs/
after_emulate/
after_platform_add/
after_platform_rm/
after_platform_ls/
after_plugin_add/
after_plugin_ls/
after_plugin_rm/
after_plugin_search/
after_plugin_install/ <-- Plugin hooks defined in plugin.xml are executed exclusively for a plugin being installed
after_prepare/
after_run/
after_serve/
before_build/
before_compile/
before_docs/
before_emulate/
before_platform_add/
before_platform_rm/
before_platform_ls/
before_plugin_add/
before_plugin_ls/
before_plugin_rm/
before_plugin_search/
before_plugin_install/ <-- Plugin hooks defined in plugin.xml are executed exclusively for a plugin being installed
before_plugin_uninstall/ <-- Plugin hooks defined in plugin.xml are executed exclusively for a plugin being uninstalled
before_prepare/
before_run/
before_serve/
pre_package/ <-- Windows 8 and Windows Phone only.

## Ways to define hooks
### Via '/hooks' directory
To execute custom action when corresponding hook type is fired, use hook type as a name for a subfolder inside 'hooks' directory and place you script file here, for example:

# script file will be automatically executed after each build
hooks/after_build/after_build_custom_action.js


### Config.xml

Hooks can be defined in project's `config.xml` using `<hook>` elements, for example:

<hook type="before_build" src="scripts/appBeforeBuild.bat" />
<hook type="before_build" src="scripts/appBeforeBuild.js" />
<hook type="before_plugin_install" src="scripts/appBeforePluginInstall.js" />

<platform name="wp8">
<hook type="before_build" src="scripts/wp8/appWP8BeforeBuild.bat" />
<hook type="before_build" src="scripts/wp8/appWP8BeforeBuild.js" />
<hook type="before_plugin_install" src="scripts/wp8/appWP8BeforePluginInstall.js" />
...
</platform>

<platform name="windows8">
<hook type="before_build" src="scripts/windows8/appWin8BeforeBuild.bat" />
<hook type="before_build" src="scripts/windows8/appWin8BeforeBuild.js" />
<hook type="before_plugin_install" src="scripts/windows8/appWin8BeforePluginInstall.js" />
...
</platform>

### Plugin hooks (plugin.xml)

As a plugin developer you can define hook scripts using `<hook>` elements in a `plugin.xml` like that:

<hook type="before_plugin_install" src="scripts/beforeInstall.js" />
<hook type="after_build" src="scripts/afterBuild.js" />

<platform name="wp8">
<hook type="before_plugin_install" src="scripts/wp8BeforeInstall.js" />
<hook type="before_build" src="scripts/wp8BeforeBuild.js" />
...
</platform>

`before_plugin_install`, `after_plugin_install`, `before_plugin_uninstall` plugin hooks will be fired exclusively for the plugin being installed/uninstalled.

## Script Interface

### Javascript

If you are writing hooks in Javascript you should use the following module definition:
```javascript
module.exports = function(context) {
...
}
```

You can make your scipts async using Q:
```javascript
module.exports = function(context) {
var Q = context.requireCordovaModule('q');
var deferral = new Q.defer();

setTimeout(function(){
console.log('hook.js>> end');
deferral.resolve();
}, 1000);

return deferral.promise;
}
```

`context` object contains hook type, executed script full path, hook options, command-line arguments passed to Cordova and top-level "cordova" object:
```json
{
"hook": "before_plugin_install",
"scriptLocation": "c:\\script\\full\\path\\appBeforePluginInstall.js",
"cmdLine": "The\\exact\\command\\cordova\\run\\with arguments",
"opts": {
"projectRoot":"C:\\path\\to\\the\\project",
"cordova": {
"platforms": ["wp8"],
"plugins": ["com.plugin.withhooks"],
"version": "0.21.7-dev"
},
"plugin": {
"id": "com.plugin.withhooks",
"pluginInfo": {
...
},
"platform": "wp8",
"dir": "C:\\path\\to\\the\\project\\plugins\\com.plugin.withhooks"
}
},
"cordova": {...}
}

```
`context.opts.plugin` object will only be passed to plugin hooks scripts.

You can also require additional Cordova modules in your script using `context.requireCordovaModule` in the following way:
```javascript
var Q = context.requireCordovaModule('q');
```

__Note__: new module loader script interface is used for the `.js` files defined via `config.xml` or `plugin.xml` only.
For compatibility reasons hook files specified via `/hooks` folders are run via Node child_process spawn, see 'Non-javascript' section below.

### Non-javascript

Non-javascript scripts are run via Node child_process spawn from the project's root directory and have the root directory passes as the first argument. All other options are passed to the script using environment variables:

* CORDOVA_VERSION - The version of the Cordova-CLI.
* CORDOVA_PLATFORMS - Comma separated list of platforms that the command applies to (e.g.: android, ios).
* CORDOVA_PLUGINS - Comma separated list of plugin IDs that the command applies to (e.g.: org.apache.cordova.file, org.apache.cordova.file-transfer)
* CORDOVA_HOOK - Path to the hook that is being executed.
* CORDOVA_CMDLINE - The exact command-line arguments passed to cordova (e.g.: cordova run ios --emulate)

If a script returns a non-zero exit code, then the parent cordova command will be aborted.

## Writing hooks

We highly recommend writing your hooks using Node.js so that they are
cross-platform. Some good examples are shown here:

[http://devgirl.org/2013/11/12/three-hooks-your-cordovaphonegap-project-needs/](http://devgirl.org/2013/11/12/three-hooks-your-cordovaphonegap-project-needs/)

Also, note that even if you are working on Windows, and in case your hook scripts aren't bat files (which is recommended, if you want your scripts to work in non-Windows operating systems) Cordova CLI will expect a shebang line as the first line for it to know the interpreter it needs to use to launch the script. The shebang line should match the following example:

#!/usr/bin/env [name_of_interpreter_executable]
37 changes: 0 additions & 37 deletions spec/test.js → spec/domainListFromFreifunkApiSpec.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,8 @@
var rewire = require("rewire");
var assert = require("chai").assert
var sinon = require("sinon")
var models = rewire("../www/js/models.js");
var FfAliasList = rewire("../www/js/models.js").FfAliasList;
var domainListFromFreifunkApi = rewire("../www/js/domainListFromFreifunkApi");

describe("App view model", function () {
var app;

beforeEach(function () {
app = new FfAliasList();
});

it("should instantiate", function () {
assert.isDefined(app);
});

describe("Data download", function () {
it("should download from the correct URL", function () {
var xhr = sinon.useFakeXMLHttpRequest();

var requests = [];

xhr.onCreate = function (xhr) {
requests.push(xhr);
};

models.__set__("XMLHttpRequest", xhr);

app.selectedDomainDataUrl("http://map.ffdus.de/data/nodes.json");
app.saveAliasList();
app.selectedDomainDataUrl("http://ffmap.freifunk-rheinland.net/nodes.json");
app.saveAliasList();

assert.equal(requests.length, 2);
assert.equal(requests[0].url, "http://map.ffdus.de/data/nodes.json");
assert.equal(requests[1].url, "http://ffmap.freifunk-rheinland.net/nodes.json");
});
});
});

describe("Domain list from Freifunk API", function () {
describe("Request to Community List", function () {
it("should return an array of Communities on success", function () {
Expand Down
40 changes: 40 additions & 0 deletions spec/modelsSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
var rewire = require("rewire");
var assert = require("chai").assert
var sinon = require("sinon")
var models = rewire("../www/js/models.js");
var FfAliasList = rewire("../www/js/models.js").FfAliasList;

describe("App view model", function () {
var app;

beforeEach(function () {
app = new FfAliasList();
});

it("should instantiate", function () {
assert.isDefined(app);
});

describe("Data download", function () {
it("should download from the correct URL", function () {
var xhr = sinon.useFakeXMLHttpRequest();

var requests = [];

xhr.onCreate = function (xhr) {
requests.push(xhr);
};

models.__set__("XMLHttpRequest", xhr);

app.selectedDomainDataUrl("http://map.ffdus.de/data/nodes.json");
app.saveAliasList();
app.selectedDomainDataUrl("http://ffmap.freifunk-rheinland.net/nodes.json");
app.saveAliasList();

assert.equal(requests.length, 2);
assert.equal(requests[0].url, "http://map.ffdus.de/data/nodes.json");
assert.equal(requests[1].url, "http://ffmap.freifunk-rheinland.net/nodes.json");
});
});
});
84 changes: 84 additions & 0 deletions www/about.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<!DOCTYPE html>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<html>
<head>
<!--
Customize this policy to fit your own app's needs. For more guidance, see:
https://github.com/apache/cordova-plugin-whitelist/blob/master/README.md#content-security-policy
Some notes:
* gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication
* https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly
* Disables use of inline scripts in order to mitigate risk of XSS vulnerabilities. To change this:
* Enable inline JS: add 'unsafe-inline' to default-src
-->
<meta charset="utf-8">
<meta http-equiv="Content-Security-Policy" content="default-src * 'unsafe-eval'; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; media-src *">
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<!--<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">-->
<link rel="stylesheet" type="text/css" href="lib/material-design-lite/material.min.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
<title>Freifunk Alias List</title>
</head>
<body>
<div class="mdl-layout mdl-js-layout mdl-layout--fixed-header ">
<header class="mdl-layout__header mdl-layout__header--scroll ffa-header">
<div class="mdl-layout__header-row ffa-header-row">
<span class="mdl-layout-title">About</span>
<div class="mdl-layout-spacer"></div>
<nav class="mdl-navigation">
<a class="mdl-navigation__link" href="index.html">Zurück</a>
</nav>
</div>
</header>
<main class="mdl-layout__content">
<div class="mdl-grid">
<div class="mdl-cell mdl-cell--4-col">
<h2 class="mdl-typography--headline">ff-alias-list-app</h2>
<p>
<a href="https://github.com/pixelistik/ff-alias-list-app">Source on Github</a>
</p>
<p>
License: <a href="https://raw.githubusercontent.com/pixelistik/ff-alias-list-app/master/LICENSE">GPLv3</a>
</p>
<h2 class="mdl-typography--headline">Libraries:</h2>
<h3 class="mdl-typography--subhead">Cordova</h3>
<p>
License: <a href="https://www.apache.org/licenses/LICENSE-2.0">Apache License 2.0</a>
</p>

<h3 class="mdl-typography--subhead">Knockout.js</h3>
<p>
License: <a href="https://raw.githubusercontent.com/knockout/knockout/master/LICENSE">MIT License</a>
</p>

<h3 class="mdl-typography--subhead">Material Design Lite</h3>
<p>
License: <a href="https://raw.githubusercontent.com/google/material-design-lite/master/LICENSE">Apache License 2.0</a>
</p>
</div>
</div>
</main>
</div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="lib/material-design-lite/material.min.js"></script>
</body>
</html>
Loading

0 comments on commit 2b360dd

Please sign in to comment.