fix #283: preveng storage popup when no action is required

This commit is contained in:
antelle 2016-08-15 00:22:25 +03:00
parent 857c937df1
commit 871987d4e5
6 changed files with 105 additions and 109 deletions

View File

@ -69,9 +69,17 @@ var PopupNotifier = {
}
});
win.loadURL(url);
win.show();
win.once('page-title-updated', () => {
setTimeout(() => {
if (win) {
win.show();
win.focus();
}
}, Timeouts.PopupWaitTime);
});
win.on('closed', () => {
setTimeout(PopupNotifier.triggerClosed.bind(PopupNotifier, win), Timeouts.CheckWindowClosed);
win = null;
});
Backbone.trigger('popup-opened', win);
return win;

View File

@ -10,7 +10,8 @@ var Timeouts = {
OtpFadeDuration: 10000,
AutoTypeAfterHide: 100,
DrobDownClickWait: 500,
RedrawInactiveWindow: 50
RedrawInactiveWindow: 50,
PopupWaitTime: 1000
};
module.exports = Timeouts;

View File

@ -108,11 +108,7 @@ _.extend(StorageBase.prototype, {
};
settings = Object.keys(settings).map(key => key + '=' + settings[key]).join(',');
var win = window.open(url, title, settings);
if (win && win.focus) {
win.focus();
}
return win;
return window.open(url, title, settings);
},
_getOauthRedirectUrl: function() {

View File

@ -20,23 +20,22 @@ var StorageGDrive = StorageBase.extend({
},
load: function(path, opts, callback) {
var that = this;
that.stat(path, opts, (err, stat) => {
this.stat(path, opts, (err, stat) => {
if (err) { return callback && callback(err); }
that.logger.debug('Load', path);
var ts = that.logger.ts();
var url = that._baseUrl + '/files/{id}/revisions/{rev}?alt=media'
this.logger.debug('Load', path);
var ts = this.logger.ts();
var url = this._baseUrl + '/files/{id}/revisions/{rev}?alt=media'
.replace('{id}', path)
.replace('{rev}', stat.rev);
that._xhr({
this._xhr({
url: url,
responseType: 'arraybuffer',
success: function(response) {
that.logger.debug('Loaded', path, stat.rev, that.logger.ts(ts));
success: (response) => {
this.logger.debug('Loaded', path, stat.rev, this.logger.ts(ts));
return callback && callback(null, response, { rev: stat.rev });
},
error: function(err) {
that.logger.error('Load error', path, err, that.logger.ts(ts));
error: (err) => {
this.logger.error('Load error', path, err, this.logger.ts(ts));
return callback && callback(err);
}
});
@ -44,7 +43,6 @@ var StorageGDrive = StorageBase.extend({
},
stat: function(path, opts, callback) {
var that = this;
if (path.lastIndexOf(NewFileIdPrefix, 0) === 0) {
return callback && callback({ notFound: true });
}
@ -52,20 +50,20 @@ var StorageGDrive = StorageBase.extend({
if (err) {
return callback && callback(err);
}
that.logger.debug('Stat', path);
var ts = that.logger.ts();
var url = that._baseUrl + '/files/{id}?fields=headRevisionId'
this.logger.debug('Stat', path);
var ts = this.logger.ts();
var url = this._baseUrl + '/files/{id}?fields=headRevisionId'
.replace('{id}', path);
that._xhr({
this._xhr({
url: url,
responseType: 'json',
success: function(response) {
success: (response) => {
var rev = response.headRevisionId;
that.logger.debug('Stated', path, rev, that.logger.ts(ts));
this.logger.debug('Stated', path, rev, this.logger.ts(ts));
return callback && callback(null, { rev: rev });
},
error: function(err) {
that.logger.error('Stat error', that.logger.ts(ts), err);
error: (err) => {
this.logger.error('Stat error', this.logger.ts(ts), err);
return callback && callback(err);
}
});
@ -73,16 +71,15 @@ var StorageGDrive = StorageBase.extend({
},
save: function(path, opts, data, callback, rev) {
var that = this;
that.stat(path, opts, (err, stat) => {
this.stat(path, opts, (err, stat) => {
if (rev) {
if (err) { return callback && callback(err); }
if (stat.rev !== rev) {
return callback && callback({revConflict: true}, stat);
}
}
that.logger.debug('Save', path);
var ts = that.logger.ts();
this.logger.debug('Save', path);
var ts = this.logger.ts();
var isNew = path.lastIndexOf(NewFileIdPrefix, 0) === 0;
var url;
if (isNew) {
@ -103,21 +100,21 @@ var StorageGDrive = StorageBase.extend({
.replace('{id}', path);
data = new Blob([data], {type: 'application/octet-stream'});
}
that._xhr({
this._xhr({
url: url,
method: isNew ? 'POST' : 'PATCH',
responseType: 'json',
data: data,
success: function(response) {
that.logger.debug('Saved', path, that.logger.ts(ts));
success: (response) => {
this.logger.debug('Saved', path, this.logger.ts(ts));
var newRev = response.headRevisionId;
if (!newRev) {
return callback && callback('save error: no rev');
}
return callback && callback(null, { rev: newRev, path: isNew ? response.id : null });
},
error: function(err) {
that.logger.error('Save error', path, err, that.logger.ts(ts));
error: (err) => {
this.logger.error('Save error', path, err, this.logger.ts(ts));
return callback && callback(err);
}
});
@ -125,23 +122,22 @@ var StorageGDrive = StorageBase.extend({
},
list: function(callback) {
var that = this;
this._oauthAuthorize((err) => {
if (err) { return callback && callback(err); }
that.logger.debug('List');
var url = that._baseUrl + '/files?fields={fields}&q={q}'
this.logger.debug('List');
var url = this._baseUrl + '/files?fields={fields}&q={q}'
.replace('{fields}', encodeURIComponent('files'))
.replace('{q}', encodeURIComponent('fileExtension="kdbx" and trashed=false'));
var ts = that.logger.ts();
that._xhr({
var ts = this.logger.ts();
this._xhr({
url: url,
responseType: 'json',
success: function(response) {
success: (response) => {
if (!response) {
that.logger.error('List error', that.logger.ts(ts));
this.logger.error('List error', this.logger.ts(ts));
return callback && callback('list error');
}
that.logger.debug('Listed', that.logger.ts(ts));
this.logger.debug('Listed', this.logger.ts(ts));
var fileList = response.files.map(f => ({
name: f.name,
path: f.id,
@ -149,8 +145,8 @@ var StorageGDrive = StorageBase.extend({
}));
return callback && callback(null, fileList);
},
error: function(err) {
that.logger.error('List error', that.logger.ts(ts), err);
error: (err) => {
this.logger.error('List error', this.logger.ts(ts), err);
return callback && callback(err);
}
});
@ -158,21 +154,20 @@ var StorageGDrive = StorageBase.extend({
},
remove: function(path, callback) {
var that = this;
that.logger.debug('Remove', path);
var ts = that.logger.ts();
var url = that._baseUrl + '/files/{id}'.replace('{id}', path);
that._xhr({
this.logger.debug('Remove', path);
var ts = this.logger.ts();
var url = this._baseUrl + '/files/{id}'.replace('{id}', path);
this._xhr({
url: url,
method: 'DELETE',
responseType: 'json',
statuses: [200, 204],
success: function () {
that.logger.debug('Removed', path, that.logger.ts(ts));
success: () => {
this.logger.debug('Removed', path, this.logger.ts(ts));
return callback && callback();
},
error: function (err) {
that.logger.error('Remove error', path, err, that.logger.ts(ts));
error: (err) => {
this.logger.error('Remove error', path, err, this.logger.ts(ts));
return callback && callback(err);
}
});

View File

@ -31,40 +31,39 @@ var StorageOneDrive = StorageBase.extend({
},
load: function(path, opts, callback) {
var that = this;
this._oauthAuthorize(err => {
if (err) {
return callback && callback(err);
}
that.logger.debug('Load', path);
var ts = that.logger.ts();
var url = that._baseUrl + path;
that._xhr({
this.logger.debug('Load', path);
var ts = this.logger.ts();
var url = this._baseUrl + path;
this._xhr({
url: url,
responseType: 'json',
success: function (response) {
success: (response) => {
var downloadUrl = response['@content.downloadUrl'];
var rev = response.eTag;
if (!downloadUrl || !response.eTag) {
that.logger.debug('Load error', path, 'no download url', response, that.logger.ts(ts));
this.logger.debug('Load error', path, 'no download url', response, this.logger.ts(ts));
return callback && callback('no download url');
}
that._xhr({
this._xhr({
url: downloadUrl,
responseType: 'arraybuffer',
success: function (response, xhr) {
success: (response, xhr) => {
rev = xhr.getResponseHeader('ETag') || rev;
that.logger.debug('Loaded', path, rev, that.logger.ts(ts));
this.logger.debug('Loaded', path, rev, this.logger.ts(ts));
return callback && callback(null, response, {rev: rev});
},
error: function (err) {
that.logger.error('Load error', path, err, that.logger.ts(ts));
error: (err) => {
this.logger.error('Load error', path, err, this.logger.ts(ts));
return callback && callback(err);
}
});
},
error: function (err) {
that.logger.error('Load error', path, err, that.logger.ts(ts));
error: (err) => {
this.logger.error('Load error', path, err, this.logger.ts(ts));
return callback && callback(err);
}
});
@ -72,32 +71,31 @@ var StorageOneDrive = StorageBase.extend({
},
stat: function(path, opts, callback) {
var that = this;
this._oauthAuthorize(err => {
if (err) {
return callback && callback(err);
}
that.logger.debug('Stat', path);
var ts = that.logger.ts();
var url = that._baseUrl + path;
that._xhr({
this.logger.debug('Stat', path);
var ts = this.logger.ts();
var url = this._baseUrl + path;
this._xhr({
url: url,
responseType: 'json',
success: function (response) {
success: (response) => {
var rev = response.eTag;
if (!rev) {
that.logger.error('Stat error', path, 'no eTag', that.logger.ts(ts));
this.logger.error('Stat error', path, 'no eTag', this.logger.ts(ts));
return callback && callback('no eTag');
}
that.logger.debug('Stated', path, rev, that.logger.ts(ts));
this.logger.debug('Stated', path, rev, this.logger.ts(ts));
return callback && callback(null, {rev: rev});
},
error: function (err, xhr) {
error: (err, xhr) => {
if (xhr.status === 404) {
that.logger.debug('Stated not found', path, that.logger.ts(ts));
this.logger.debug('Stated not found', path, this.logger.ts(ts));
return callback && callback({ notFound: true });
}
that.logger.error('Stat error', path, err, that.logger.ts(ts));
this.logger.error('Stat error', path, err, this.logger.ts(ts));
return callback && callback(err);
}
});
@ -105,36 +103,35 @@ var StorageOneDrive = StorageBase.extend({
},
save: function(path, opts, data, callback, rev) {
var that = this;
this._oauthAuthorize(err => {
if (err) {
return callback && callback(err);
}
that.logger.debug('Save', path, rev);
var ts = that.logger.ts();
var url = that._baseUrl + path + ':/content';
that._xhr({
this.logger.debug('Save', path, rev);
var ts = this.logger.ts();
var url = this._baseUrl + path + ':/content';
this._xhr({
url: url,
method: 'PUT',
responseType: 'json',
headers: rev ? { 'If-Match': rev } : null,
data: new Blob([data], {type: 'application/octet-stream'}),
statuses: [200, 201, 412],
success: function (response, xhr) {
success: (response, xhr) => {
rev = response.eTag;
if (!rev) {
that.logger.error('Save error', path, 'no eTag', that.logger.ts(ts));
this.logger.error('Save error', path, 'no eTag', this.logger.ts(ts));
return callback && callback('no eTag');
}
if (xhr.status === 412) {
that.logger.debug('Save conflict', path, rev, that.logger.ts(ts));
this.logger.debug('Save conflict', path, rev, this.logger.ts(ts));
return callback && callback({ revConflict: true }, { rev: rev });
}
that.logger.debug('Saved', path, rev, that.logger.ts(ts));
this.logger.debug('Saved', path, rev, this.logger.ts(ts));
return callback && callback(null, {rev: rev});
},
error: function (err) {
that.logger.error('Save error', path, err, that.logger.ts(ts));
error: (err) => {
this.logger.error('Save error', path, err, this.logger.ts(ts));
return callback && callback(err);
}
});
@ -142,21 +139,20 @@ var StorageOneDrive = StorageBase.extend({
},
list: function(callback) {
var that = this;
this._oauthAuthorize(err => {
if (err) { return callback && callback(err); }
that.logger.debug('List');
var ts = that.logger.ts();
var url = that._baseUrl + '/drive/root/view.search?q=.kdbx&filter=' + encodeURIComponent('file ne null');
that._xhr({
this.logger.debug('List');
var ts = this.logger.ts();
var url = this._baseUrl + '/drive/root/view.search?q=.kdbx&filter=' + encodeURIComponent('file ne null');
this._xhr({
url: url,
responseType: 'json',
success: function(response) {
success: (response) => {
if (!response || !response.value) {
that.logger.error('List error', that.logger.ts(ts), response);
this.logger.error('List error', this.logger.ts(ts), response);
return callback && callback('list error');
}
that.logger.debug('Listed', that.logger.ts(ts));
this.logger.debug('Listed', this.logger.ts(ts));
var fileList = response.value
.filter(f => f.name && UrlUtil.isKdbx(f.name))
.map(f => ({
@ -166,8 +162,8 @@ var StorageOneDrive = StorageBase.extend({
}));
return callback && callback(null, fileList);
},
error: function(err) {
that.logger.error('List error', that.logger.ts(ts), err);
error: (err) => {
this.logger.error('List error', this.logger.ts(ts), err);
return callback && callback(err);
}
});
@ -175,21 +171,20 @@ var StorageOneDrive = StorageBase.extend({
},
remove: function(path, callback) {
var that = this;
that.logger.debug('Remove', path);
var ts = that.logger.ts();
var url = that._baseUrl + path;
that._xhr({
this.logger.debug('Remove', path);
var ts = this.logger.ts();
var url = this._baseUrl + path;
this._xhr({
url: url,
method: 'DELETE',
responseType: 'json',
statuses: [200, 204],
success: function () {
that.logger.debug('Removed', path, that.logger.ts(ts));
success: () => {
this.logger.debug('Removed', path, this.logger.ts(ts));
return callback && callback();
},
error: function (err) {
that.logger.error('Remove error', path, err, that.logger.ts(ts));
error: (err) => {
this.logger.error('Remove error', path, err, this.logger.ts(ts));
return callback && callback(err);
}
});

View File

@ -16,6 +16,7 @@ Audit, generator presets, auto-type and ui improvements
`+` field references decoding
`-` fix app redraw in background
`-` fix idle timer on computer sleep
`-` fix storage popup when no action is required
##### v1.2.4 (2016-07-20)
`+` digital signature in installer