wip on custom autoupdate for cordova

This commit is contained in:
Slava Kim
2014-07-24 17:41:20 -07:00
parent 5649b0347f
commit e2bd2a3d42
3 changed files with 72 additions and 2 deletions

View File

@@ -0,0 +1,64 @@
var autoupdateVersion = __meteor_runtime_config__.autoupdateVersion || "unknown";
var autoupdateVersionRefreshable =
__meteor_runtime_config__.autoupdateVersionRefreshable || "unknown";
// The collection of acceptable client versions.
ClientVersions = new Meteor.Collection("meteor_autoupdate_clientVersions");
Autoupdate = {};
Autoupdate.newClientAvailable = function () {
return !! ClientVersions.findOne(
{$and: [
{current: true},
{_id: {$ne: autoupdateVersion}}
]}
);
};
var retry = new Retry({
minCount: 0, // don't do any immediate retries
baseTimeout: 30*1000 // start with 30s
});
var failures = 0;
Autoupdate._retrySubscription = function () {
Meteor.subscribe("meteor_autoupdate_clientVersions", {
onError: function (error) {
Meteor._debug("autoupdate subscription failed:", error);
failures++;
retry.retryLater(failures, function () {
Autoupdate._retrySubscription();
});
},
onReady: function () {
if (Package.reload) {
var handle = ClientVersions.find().observeChanges({
added: function (id, fields) {
var self = this;
if (fields.refreshable && id !== autoupdateVersionRefreshable) {
autoupdateVersionRefreshable = id;
onNewVersion();
} else if (! fields.refreshable && id !== autoupdateVersion) {
autoupdateVersion = id;
onNewVersion();
}
}
});
function onNewVersion () {
if (handle) {
handle.stop();
}
HTTP.get(Meteor.absoluteUrl() + 'cordova_manifest.json', function (err, res) {
console.log(res);
//Package.reload.Reload._reload();
});
}
}
}
});
};
Autoupdate._retrySubscription();

View File

@@ -64,7 +64,7 @@ var updateVersions = function (shouldReloadClientProgram) {
// Step 1: load the current client program on the server and update the
// hash values in __meteor_runtime_config__.
if (shouldReloadClientProgram) {
WebAppInternals.reloadClientProgram();
WebAppInternals.reloadClientPrograms();
}
if (startupVersion === null) {
@@ -132,4 +132,4 @@ Meteor.publish(
// Listen for SIGUSR2, which signals that a client asset has changed.
process.on('SIGUSR2', Meteor.bindEnvironment(function () {
updateVersions(true);
}));
}));

View File

@@ -3,14 +3,20 @@ Package.describe({
version: '1.0.0'
});
Cordova.depends({
'org.apache.cordova.file': '1.2.0'
});
Package.on_use(function (api) {
api.use('webapp', 'server');
api.use(['deps', 'retry'], 'client');
api.use(['livedata', 'mongo-livedata'], ['client', 'server']);
api.use('deps', 'client');
api.use('reload', 'client', {weak: true});
api.use('http', 'client.cordova');
api.export('Autoupdate');
api.add_files('autoupdate_server.js', 'server');
api.add_files('autoupdate_client.js', 'client.browser');
api.add_files('autoupdate_cordova.js', 'client.cordova');
});