Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade all dependencies and create a new build for iOS #1

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package-lock.json

# system and tools
npm-debug.log
/node_modules
Expand Down
19 changes: 13 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,25 @@ Features:
- Allows scanning a barcode, initiated from the website.
- Works on Android and iOS.

## Build
## Set up

1. [Install Cordova](http://cordova.apache.org/docs/en/latest/guide/cli/index.html): `npm install -g cordova`
2. [Add platforms](https://cordova.apache.org/docs/en/latest/guide/cli/index.html#add-platforms): `cordova platform add android` and/or `cordova platform add ios`.
3. [Check (and install) requirements](https://cordova.apache.org/docs/en/latest/guide/cli/index.html#install-pre-requisites-for-building): `cordova requirements`
4. [Build](https://cordova.apache.org/docs/en/latest/guide/cli/index.html#build-the-app): `cordova build`
wvengen marked this conversation as resolved.
Show resolved Hide resolved
```
npm i
madhums marked this conversation as resolved.
Show resolved Hide resolved
npx cordova requirements # check requirements for building the app
npx cordova platform add ios # only on iOS supported platform
npm i ios-deploy -g # only on iOS supported platform
npx cordova platform add android
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest

npm install
npx cordova platform add ios      # when building iOS app on Mac OS
npx cordova platform add android  # when building Android app
npx cordova requirements          # check build requirements
npx cordova build ios             # when building iOS app on Mac OS
npx cordova build android         # when building Android app

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, feel free to do so!

npx cordova build ios # only on iOS supported platform
npx cordova build android
```
madhums marked this conversation as resolved.
Show resolved Hide resolved

The URL loaded is specified by `LANDING_URL` in [`www/js/index.js`](www/js/index.js#L21).

Refer [cordova docs](https://cordova.apache.org/docs/en/11.x/guide/cli/index.html) for more details.

### iOS

On iOS `cordova build ios` may not be enough. After running this, you can open the folder `platforms/ios` in Xcode.
On iOS `npx cordova build ios` may not be enough. After running this, you can open the folder `platforms/ios` in Xcode.
In the warnings shown there are two items about updating build settings. Accept the modifications (ignoring the warning
about uncommited changes), and build it from Xcode.

Expand Down
10 changes: 8 additions & 2 deletions config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,20 @@
<edit-config file="*-Info.plist" mode="merge" target="NSCameraUsageDescription">
<string>To scan barcodes</string>
</edit-config>
<config-file target="*-Info.plist" parent="LSApplicationQueriesSchemes">
<array>
<string>app</string>
</array>
</config-file>
</platform>
<preference name="Orientation" value="portrait" />
<preference name="AppendUserAgent" value=" QuestionmarkApp" />
<preference name="AllowedSchemes" value="app" />
<preference name="PreferredContentMode" value="mobile" />
<plugin name="cordova-plugin-whitelist" spec="^1.3.3" />
<plugin name="cordova-plugin-inappbrowser" spec="git+https://github.com/q-m/cordova-plugin-inappbrowser.git#2eacaa" />
<plugin name="cordova-plugin-inappbrowser" spec="^5.0.0" />
madhums marked this conversation as resolved.
Show resolved Hide resolved
<plugin name="cordova-plugin-network-information" spec="^2.0.1" />
<plugin name="cordova-plugin-splashscreen" spec="^5.0.2" />
<plugin name="cordova-plugin-splashscreen" spec="^6.0.2" />
<plugin name="phonegap-plugin-barcodescanner" spec="^7.1.2">
<variable name="ANDROID_SUPPORT_V4_VERSION" value="27.+" />
</plugin>
Expand Down
17 changes: 11 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "org.thequestionmark.questionmark",
"displayName": "Questionmark",
"version": "3.0.4",
"version": "4.0.0",
"description": "Duurzaam en gezond eten? Wij help je kiezen!",
"homepage": "https://github.com/q-m/questionmark-app",
"license": "Apache-2.0",
Expand All @@ -12,9 +12,9 @@
"author": "The Questionmark",
"dependencies": {
"cordova-plugin-app-launcher": "^0.4.0",
"cordova-plugin-inappbrowser": "git+https://github.com/q-m/cordova-plugin-inappbrowser.git#2eacaa",
"cordova-plugin-inappbrowser": "~5.0.0",
"cordova-plugin-network-information": "^2.0.1",
"cordova-plugin-splashscreen": "^5.0.2",
"cordova-plugin-splashscreen": "~6.0.2",
"cordova-plugin-whitelist": "^1.3.3",
"phonegap-plugin-barcodescanner": "^7.1.2"
},
Expand All @@ -23,12 +23,17 @@
"cordova-plugin-whitelist": {},
"cordova-plugin-inappbrowser": {},
"cordova-plugin-network-information": {},
"cordova-plugin-splashscreen": {},
"phonegap-plugin-barcodescanner": {
"ANDROID_SUPPORT_V4_VERSION": "27.+"
},
"cordova-plugin-app-launcher": {}
"cordova-plugin-app-launcher": {},
"cordova-plugin-splashscreen": {}
},
"platforms": []
"platforms": [
"ios"
]
},
"devDependencies": {
"cordova": "~11.1.0"
}
}
41 changes: 22 additions & 19 deletions www/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

// Page to open when app starts.
var LANDING_URL = "https://www.thequestionmark.org/index-app?app=Questionmark";
var LANDING_URL = "https://checker.thequestionmark.org/index-app?app=Questionmark";
// URLs listed here open in the app, others in the system web browser.
// Both absolute and host-relative URLs (with respect to LANDING_URL) are allowed.
// The URL on test includes a leading slash, but does not include query string or hash.
Expand All @@ -29,9 +29,13 @@ var LOCAL_URLS = "/index-app /lookup /search /404 /contact /over-ons /categories


// Regular expression for parsing full URLs, returning: base, path, query, hash.
var SPLIT_URL_RE = /^([^:/]+:\/\/[^/]+)(\/[^?]*)(?:\?([^#]*))?(?:#(.*))?$/i;
var SPLIT_URL_RE = /^(http[s]?:)+\/\/([^:\/\s]+)([^#?\s]+)?([^#]*)?(#.*)?$/i;

madhums marked this conversation as resolved.
Show resolved Hide resolved
// Base URL for matching, derived from LANDING_URL (without trailing slash).
var BASE_URL = LANDING_URL.match(SPLIT_URL_RE)[1];
// Test the regex https://regex101.com/r/ZpSUnQ/1
// ["https://checker.thequestionmark.org/index-app", "https:", "checker.thequestionmark.org", "/index-app", "?app=Questionmark", undefined]
// Index [url, protocol, base, path, querystring, hash]
madhums marked this conversation as resolved.
Show resolved Hide resolved
var BASE_URL = LANDING_URL.match(SPLIT_URL_RE)[2];

// Main functionality using a state machine.
var Fsm = machina.Fsm.extend({
Expand Down Expand Up @@ -388,7 +392,7 @@ var Fsm = machina.Fsm.extend({
isLocalUrl: function(url) {
var parts = url.match(SPLIT_URL_RE);
if (parts) {
var base = parts[1], path = parts[2];
var base = parts[2], path = parts[3];
return (base + path).match(this.localUrlRe) || (base === BASE_URL && path.match(this.localUrlRe));
}
},
Expand All @@ -397,21 +401,20 @@ var Fsm = machina.Fsm.extend({
// Catch links that were clicked to route external ones through our custom protocol.
// We'd rather not do this in the loadstart event, because the page then already started loading.
this.app.executeScript({ code:
'window.addEventListener("click", function(e) {\n' +
' if (e.target.tagName !== "A") return;\n' +
' var href = e.target.href;\n' +
' if (!href || href.startsWith("app:")) return;\n' +
' var BASE_URL = ' + JSON.stringify(BASE_URL) + ';\n' +
' var SPLIT_URL_RE = ' + SPLIT_URL_RE.toString() + ';\n' +
' var localUrlRe = ' + this.localUrlRe.toString() + ';\n' +
' var parts = href.match(SPLIT_URL_RE);\n' +
' var base = parts[1], path = parts[2];\n' +
' if (!(base + path).match(localUrlRe) && !(base === BASE_URL && path.match(localUrlRe))) {\n' +
' e.preventDefault();\n' +
' window.location.assign("app://open?url=" + encodeURIComponent(href));\n' +
' }\n' +
'});\n' +
'console.log("installed click event listener for external links");\n'
`window.addEventListener("click", function(e) {
if (e.target.tagName !== "A") return;
var href = e.target.href;
if (!href || href.startsWith("app:")) return;
var BASE_URL = ${JSON.stringify(BASE_URL)};
var SPLIT_URL_RE = ${SPLIT_URL_RE.toString()};
var localUrlRe = ${this.localUrlRe.toString()};
var parts = href.match(SPLIT_URL_RE);
var base = parts[1], path = parts[2];
if (!(base + path).match(localUrlRe) && !(base === BASE_URL && path.match(localUrlRe))) {
e.preventDefault();
window.location.assign("app://open?url=" + encodeURIComponent(href));
}
});`
wvengen marked this conversation as resolved.
Show resolved Hide resolved
}, function() {
// Also log in app console.
debug("installed click event listener for external links");
Expand Down