Skip to content

Instantly share code, notes, and snippets.

@jokeyrhyme
Last active November 10, 2016 04:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jokeyrhyme/eadfdcd2959a1c988d6ea18e8faf5f33 to your computer and use it in GitHub Desktop.
Save jokeyrhyme/eadfdcd2959a1c988d6ea18e8faf5f33 to your computer and use it in GitHub Desktop.
ionic-deploy-plugin useCheckResponse
<!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 http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; connect-src https://my.test.com">
<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" type="text/css" href="css/index.css">
<title>Hello World</title>
</head>
<body>
<div class="app">
<h1>Apache Cordova 1</h1>
<div id="deviceready" class="blink">
<p class="event listening">Connecting to Device</p>
<p class="event received">Device is Ready</p>
</div>
<div id="update">
<progress id="update-progress" min="0" max="100" hidden></progress>
<p id="update-enabled" hidden>
You may check for available updates.
<button id="update-check">Check</button>
</p>
<p id="update-latest" hidden>This is the latest version.</p>
<p id="update-available" hidden>
There is an update available.
<button id="update-download">Download</button>
</p>
<p id="update-downloaded" hidden>
An update has been downloaded.
<button id="update-install">Install</button>
</p>
<p id="update-installed" hidden>
An update has been installed.
<button id="update-restart">Restart</button>
</p>
</div>
</div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/vendor/fetch.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript" src="js/update.js"></script>
</body>
</html>
(function (window) {
'use strict'
// from the global `app` from index.js
var app = window.app
var deploy
var APP_ID = 'io.cordova.hellocordova'
var CDN_ORIGIN = 'https://my.test.com'
var ZIP_URL = CDN_ORIGIN + '/www-android.zip'
document.getElementById('update-check').addEventListener('click', function () {
fetch(ZIP_URL, { method: 'HEAD' })
.then(function (res) {
console.log('fetch: HEAD=' + JSON.stringify(res.headers))
return res.headers
})
.then(function (headers) {
deploy.parseUpdate(APP_ID, {
data: {
available: true,
compatible: true,
snapshot: headers.get('etag').replace(/"/g, '').trim(),
url: ZIP_URL
}
}, function (result) { // onSuccess
console.log('parseUpdate: isNotAvailable=' + result)
if (result === 'true') {
document.getElementById('update-latest').hidden = true
document.getElementById('update-available').hidden = false
} else {
document.getElementById('update-latest').hidden = false
document.getElementById('update-available').hidden = true
}
}, function (err) { // onError
console.error('parseUpdate')
console.error(err)
})
})
.catch(function (err) {
console.error('fetch')
console.error(err)
})
}, false)
document.getElementById('update-download').addEventListener('click', function () {
deploy.download(APP_ID, function (result) {
console.log('deploy.download: result=' + result)
if (result === 'true') {
document.getElementById('update-available').hidden = true
document.getElementById('update-downloaded').hidden = false
}
}, function (err) { // onError
console.error('deploy.download')
console.error(err)
})
}, false)
document.getElementById('update-install').addEventListener('click', function () {
deploy.extract(APP_ID, function (result) {
console.log('deploy.extract: result=' + result)
if (result === 'done') {
document.getElementById('update-downloaded').hidden = true
document.getElementById('update-installed').hidden = false
}
}, function (err) { // onError
console.error('deploy.extract')
console.error(err)
})
}, false)
document.getElementById('update-restart').addEventListener('click', function () {
deploy.redirect(APP_ID)
}, false)
// be sure to call this from the onDeviceReady handler in index.js
app.onDeviceReady = function () {
deploy = window.IonicDeploy
deploy.init(APP_ID, CDN_ORIGIN + '/fake/deploy')
document.getElementById('update-enabled').hidden = false
}
}(this))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment