Permalink
Browse files

show version when updating

  • Loading branch information...
1 parent 770019d commit c17af534ca2ae148b040a161279e5b102e0aefd7 @coolaj86 committed May 28, 2012
Showing with 68 additions and 13 deletions.
  1. +4 −1 browser/index.jade
  2. +5 −3 package.json
  3. +59 −9 server/index.js
View
@@ -13,7 +13,10 @@ html
a(href='/update') Check for Updates...
#update-server
form#update-form(action='/settings', method='POST', enctype='application/json')
- input(name='webapp-server') hurpdurp.iriscouch.com
+ label(for='webapp-server').
+ WebApp Center Server:
+ input(name='webapp-server', value='hurpdurp.iriscouch.com')
+ br
input(type='submit')
#todo
ul
View
@@ -5,7 +5,7 @@
],
"name": "webappcenter-client",
"description": "The client (laptop / desktop) side of appr.",
- "version": "0.1.09",
+ "version": "0.1.16",
"repository": {
"url": "git://github.com/coolaj86/appr-client.git"
},
@@ -41,6 +41,8 @@
"npm": "1.1.x",
"rimraf": "2.0.x",
"connect_router": "~1.8.6",
- "fs.extra": "~1.1.1"
+ "fs.extra": "~1.1.1",
+ "dom-storage": "~1.0.0",
+ "json-storage": "~1.1.2"
}
-}
+}
View
@@ -8,15 +8,15 @@
/*
* CONFIG STUFF that should be moved out
*/
- , xcorsOptions = {
+ , xcorsOptions
+ , xcorsDefaultOptions = {
origins: ["http://apps.spotterrf.com", "http://hurpdurp.com"]
, methods: ['GET', 'POST']
, headers: ['Content-Type', 'Accept']
, credentials: false
}
, port = 7770
- , wacServerUrl = "http://apps.spotterrf.com:3999"
- //, wacServerUrl = "http://hurpdurp.com:3999"
+ , wacServerUrl = "http://hurpdurp.com"
/*
* NORMAL STUFF
*/
@@ -32,33 +32,60 @@
, pullRoute = require('./router')
, args = process.argv
, publicPath = path.join(__dirname, '..', 'webclient-deployed')
+ , releasesPath = path.join(__dirname, '..', 'webclient-deployed', 'releases')
, mountDir = path.join(__dirname, 'mounts')
, mounterFactory = require('connect-mounter')
+ , DomStorage = require('dom-storage')
+ , jsonStorage = require('json-storage').create(DomStorage.create(path.join(__dirname, 'settings.json')))
, mounter = mounterFactory.create(mountDir)
, failures = mounterFactory.fail
+ , installLock
, app
;
+ // TODO allow 3rd party stores to be used via oauth or something
+ //xcorsOptions = jsonStorage.get('xcors');
+ if (!xcorsOptions) {
+ xcorsOptions = xcorsDefaultOptions;
+ }
+
if (failures) {
console.log('BAD APPS:', failures);
}
- function update() {
+ function update(cb) {
request.get(wacServerUrl + "/version").when(function(err, ahr, data) {
var newVer
, selfUpdate = true
, callback = null
+ , installLockTimeout
;
+ function removeInstallLock() {
+ installLock = false;
+ clearTimeout(installLockTimeout);
+ installLockTimeout = 0;
+ }
+
if(err || data.error === true) {
console.log('Could not contact WebAppsCenter update service. Going it alone...');
return;
}
+ if (cb) {
+ cb (err || data.error, curVer, newVer);
+ }
+
+ if (installLock) {
+ return;
+ }
+
if(semver.gt(data.result, curVer)) {
- console.log("New version detected... downloading and installing!");
+ console.log("New version (" + data.result + ") detected... downloading and installing!");
newVer = data.result;
+ installLock = true;
installer(null, "client", newVer, selfUpdate, callback, wacServerUrl);
+ installLockTimeout = setTimeout(removeInstallLock, 15 * 60 * 1000);
}
});
}
@@ -76,13 +103,35 @@
}
}
+ function sendUpdateInfo(req, res) {
+ function sendUpdateInfoHelper(err, curVer, newVer) {
+ var errors = []
+ , success = true
+ ;
+
+ if (err) {
+ errors.push(err);
+ success = false;
+ }
+
+ res.end(JSON.stringify({
+ "success": success
+ , "result": {
+ current: curVer
+ , latest: newVer
+ }
+ , "errors": errors
+ }));
+ }
+ update(sendUpdateInfoHelper);
+ }
+
function router(rest) {
- rest.get('/update', function (req, res) {
- update();
- res.end('{"success": true, "result": null, "errors": []}');
- });
+ rest.get('/update', sendUpdateInfo);
}
+ // check for updates every 3 hours
+ setInterval(update, 3 * 60 * 60 * 1000);
update();
app = connect()
@@ -93,6 +142,7 @@
//TODO remove this static / directory serving. Everything should be
// being pulled from the HTML5 webapp already.
.use(connect.static(publicPath))
+ .use(connect.static(releasesPath))
.use(connect.directory(publicPath))
;

0 comments on commit c17af53

Please sign in to comment.