option to check updates without install

This commit is contained in:
Antelle 2015-11-16 22:04:33 +03:00
parent 6920cfeb39
commit 94fd93ab9d
8 changed files with 67 additions and 38 deletions

View File

@ -9,7 +9,7 @@ Nov
- [ ] custom icons, favicons
- [x] drag to trash
- [ ] switch view
- [ ] option to check updates without install
- [x] option to check updates without install
## v0.5
Dec

View File

@ -16,8 +16,15 @@ var Updater = {
nextCheckTimeout: null,
updateCheckDate: new Date(0),
enabledAutoUpdate: function() {
return Launcher && AppSettingsModel.instance.get('autoUpdate');
getAutoUpdateType: function() {
if (!Launcher) {
return false;
}
var autoUpdate = AppSettingsModel.instance.get('autoUpdate');
if (autoUpdate && autoUpdate === true) {
autoUpdate = 'install';
}
return autoUpdate;
},
updateInProgress: function() {
@ -27,7 +34,7 @@ var Updater = {
init: function() {
var willCheckNow = this.scheduleNextCheck();
if (!willCheckNow && this.enabledAutoUpdate()) {
if (!willCheckNow && this.getAutoUpdateType()) {
this.check();
}
if (!Launcher && window.applicationCache) {
@ -41,7 +48,7 @@ var Updater = {
clearTimeout(this.nextCheckTimeout);
this.nextCheckTimeout = null;
}
if (!this.enabledAutoUpdate()) {
if (!this.getAutoUpdateType()) {
return;
}
var timeDiff = this.MinUpdateTimeout;
@ -50,7 +57,7 @@ var Updater = {
timeDiff = Math.min(Math.max(this.UpdateInterval + (lastCheckDate - new Date()), this.MinUpdateTimeout), this.UpdateInterval);
}
this.nextCheckTimeout = setTimeout(this.check.bind(this), timeDiff);
console.log('Update check will happen in ' + Math.round(timeDiff / 1000) + 's');
console.log('Next update check will happen in ' + Math.round(timeDiff / 1000) + 's');
return timeDiff === this.MinUpdateTimeout;
},
@ -104,7 +111,11 @@ var Updater = {
console.log('Waiting for the user to apply downloaded update');
return;
}
that.update(startedByUser);
if (!startedByUser && that.getAutoUpdateType() === 'install') {
that.update(startedByUser);
} else if (UpdateModel.instance.get('lastVersion') !== RuntimeInfo.version) {
UpdateModel.instance.set('updateStatus', 'found');
}
},
error: function(e) {
console.error('Update check error', e);
@ -126,7 +137,7 @@ var Updater = {
}
},
update: function(startedByUser) {
update: function(startedByUser, successCallback) {
var ver = UpdateModel.instance.get('lastVersion');
if (!Launcher || ver === RuntimeInfo.version) {
console.log('You are using the latest version');
@ -151,6 +162,9 @@ var Updater = {
if (!startedByUser) {
Backbone.trigger('update-app');
}
if (typeof successCallback === 'function') {
successCallback();
}
}
});
},
@ -190,7 +204,6 @@ var Updater = {
if (window.applicationCache.status === window.applicationCache.UPDATEREADY) {
try { window.applicationCache.swapCache(); } catch (e) { }
UpdateModel.instance.set('updateStatus', 'ready');
Backbone.trigger('update-app');
}
}
};

View File

@ -12,7 +12,7 @@ var AppSettingsModel = Backbone.Model.extend({
listViewWidth: null,
menuViewWidth: null,
tagsViewHeight: null,
autoUpdate: true
autoUpdate: 'install'
},
initialize: function() {

View File

@ -13,7 +13,8 @@ var Backbone = require('backbone'),
Keys = require('../const/keys'),
KeyHandler = require('../comp/key-handler'),
Launcher = require('../comp/launcher'),
ThemeChanger = require('../util/theme-changer');
ThemeChanger = require('../util/theme-changer'),
UpdateModel = require('../models/update-model');
var AppView = Backbone.View.extend({
el: 'body',
@ -58,7 +59,8 @@ var AppView = Backbone.View.extend({
this.listenTo(Backbone, 'toggle-details', this.toggleDetails);
this.listenTo(Backbone, 'edit-group', this.editGroup);
this.listenTo(Backbone, 'launcher-open-file', this.launcherOpenFile);
this.listenTo(Backbone, 'update-app', this.updateApp);
this.listenTo(UpdateModel.instance, 'change:updateReady', this.updateApp);
window.onbeforeunload = this.beforeUnload.bind(this);
window.onresize = this.windowResize.bind(this);
@ -105,7 +107,8 @@ var AppView = Backbone.View.extend({
},
updateApp: function() {
if (!Launcher && !this.model.files.hasOpenFiles()) {
if (UpdateModel.instance.get('updateStatus') === 'ready' &&
!Launcher && !this.model.files.hasOpenFiles()) {
window.location.reload();
}
},

View File

@ -29,14 +29,13 @@ var FooterView = Backbone.View.extend({
KeyHandler.onKey(Keys.DOM_VK_COMMA, this.toggleSettings, this, KeyHandler.SHORTCUT_ACTION);
this.listenTo(this.model.files, 'update reset change', this.render);
this.listenTo(Backbone, 'update-app', this.render);
this.listenTo(UpdateModel.instance, 'change:updateStatus', this.render);
},
render: function () {
this.listenTo(Backbone, 'update-app', this.updateApp);
this.$el.html(this.template({
files: this.model.files,
updateAvailable: UpdateModel.instance.get('updateStatus') === 'ready'
updateAvailable: ['ready', 'found'].indexOf(UpdateModel.instance.get('updateStatus')) >= 0
}));
return this;
},

View File

@ -19,6 +19,7 @@ var SettingsGeneralView = Backbone.View.extend({
'click .settings__general-update-btn': 'checkUpdate',
'click .settings__general-restart-btn': 'restartApp',
'click .settings__general-download-update-btn': 'downloadUpdate',
'click .settings__general-update-found-btn': 'installFoundUpdate',
'click .settings__general-dev-tools-link': 'openDevTools'
},
@ -40,10 +41,11 @@ var SettingsGeneralView = Backbone.View.extend({
expandGroups: AppSettingsModel.instance.get('expandGroups'),
devTools: Launcher && Launcher.devTools,
canAutoUpdate: !!Launcher,
autoUpdate: Updater.enabledAutoUpdate(),
autoUpdate: Updater.getAutoUpdateType(),
updateInProgress: Updater.updateInProgress(),
updateInfo: this.getUpdateInfo(),
updateReady: UpdateModel.instance.get('updateStatus') === 'ready',
updateFound: UpdateModel.instance.get('updateStatus') === 'found',
updateManual: UpdateModel.instance.get('updateManual'),
releaseNotesLink: Links.ReleaseNotes
});
@ -91,7 +93,7 @@ var SettingsGeneralView = Backbone.View.extend({
},
changeAutoUpdate: function(e) {
var autoUpdate = e.target.checked;
var autoUpdate = e.target.value || false;
AppSettingsModel.instance.set('autoUpdate', autoUpdate);
if (autoUpdate) {
Updater.scheduleNextCheck();
@ -114,6 +116,12 @@ var SettingsGeneralView = Backbone.View.extend({
Launcher.openLink(Links.Desktop);
},
installFoundUpdate: function() {
Updater.update(true, function() {
Launcher.requestRestart();
});
},
changeExpandGroups: function(e) {
var expand = e.target.checked;
AppSettingsModel.instance.set('expandGroups', expand);

View File

@ -1,5 +1,6 @@
<div>
<h1><i class="fa fa-cog"></i> General Settings</h1>
<% if (updateReady && !canAutoUpdate) { %>
<h2 class="action-color">Update</h2>
<div>New app version was released and downloaded. <a href="<%= releaseNotesLink %>" target="_blank">View release notes</a></div>
@ -14,6 +15,28 @@
<button class="settings__general-download-update-btn">Download update</button>
</div>
<% } %>
<% if (canAutoUpdate && !updateManual) { %>
<h2>Update</h2>
<div>
<select class="settings__general-auto-update settings__select input-base">
<option value="install" <%= autoUpdate === 'install' ? 'selected' : '' %>>Download and install automatically</option>
<option value="check" <%= autoUpdate === 'check' ? 'selected' : '' %>>Check but don't install</option>
<option value="" <%= autoUpdate ? '' : 'selected' %>>Never check for updates</option>
</select>
<div><%- updateInfo %></div>
<a href="<%= releaseNotesLink %>" target="_blank">View release notes</a>
</div>
<div class="settings__general-update-buttons">
<% if (updateInProgress) { %>
<button class="settings__general-update-btn btn-silent" disabled>Checking for updates</button>
<% } else { %>
<button class="settings__general-update-btn btn-silent">Check for updates</button>
<% } %>
<% if (updateReady) { %><button class="settings__general-restart-btn">Restart to update</button><% } %>
<% if (updateFound) { %><button class="settings__general-update-found-btn">Download update and restart</button><% } %>
</div>
<% } %>
<h2>Appearance</h2>
<div>
<label for="settings__general-theme">Theme:</label>
@ -27,25 +50,7 @@
<input type="checkbox" class="settings__input input-base settings__general-expand" id="settings__general-expand" <%- expandGroups ? 'checked' : '' %> />
<label for="settings__general-expand">Show entries from all subgroups</label>
</div>
<% if (canAutoUpdate && !updateManual) { %>
<h2>Function</h2>
<div>
<input type="checkbox" class="settings__input settings__general-auto-update" id="settings__general-auto-update" <%- autoUpdate ? 'checked' : '' %> />
<label for="settings__general-auto-update">Automatic updates</label>
<div><%- updateInfo %></div>
<a href="<%= releaseNotesLink %>" target="_blank">View release notes</a>
</div>
<div class="settings__general-update-buttons">
<% if (updateInProgress) { %>
<button class="settings__general-update-btn btn-silent" disabled>Checking for updates</button>
<% } else { %>
<button class="settings__general-update-btn btn-silent">Check for updates</button>
<% } %>
<% if (updateReady) { %>
<button class="settings__general-restart-btn">Restart to update</button>
<% } %>
</div>
<% } %>
<% if (devTools) { %>
<h2>Advanced</h2>
<a class="settings__general-dev-tools-link">Show dev tools</a>

View File

@ -4,7 +4,8 @@ Release notes
Bugfixes
`-` fixed tag list scrolling
`+` desktop Dropbox
`+` Dropbox notification in self-hosted apps
`+` Dropbox notification in self-hosted apps
`+` option to check updates without install
##### v0.3.0 (2015-11-14)
Auto-update