Fixed some PR comments

This commit is contained in:
Alex Shpak 2017-04-12 00:06:44 +02:00
parent 12603ff2ab
commit 945a902071
5 changed files with 21 additions and 21 deletions

View File

@ -1,9 +1,10 @@
'use strict';
/* global FingerprintAuth */
const Launcher = {
name: 'cordova',
version: '6.0.0',
autoTypeSupported: false,
thirdPartyStoragesSupported: false,
ready: function(callback) {
document.addEventListener('deviceready', callback, false);
},
@ -158,7 +159,7 @@ const Launcher = {
},
showMainWindow: function() { /* skip in cordova */ },
// spawn: function(config) { },
openFileChooser: function(callback, button) {
openFileChooser: function(callback) {
const onFileSelected = function(selected) {
window.resolveLocalFileSystemURL(selected.uri, fileEntry => {
fileEntry.file(file => {
@ -178,20 +179,19 @@ const Launcher = {
clientId: 'keeweb'
},
register: function(appModel, fileInfo, password) {
FingerprintAuth.isAvailable(result => { // eslint-disable-line no-undef
register: function(fileId, password, callback) {
FingerprintAuth.isAvailable(result => {
if (!result.isAvailable) {
return;
}
const encryptConfig = _.extend({}, this.config, {
username: fileInfo.id,
password: password.getText()
username: fileId,
password: password
});
FingerprintAuth.encrypt(encryptConfig, result => { // eslint-disable-line no-undef
fileInfo.set('fingerprint', result.token);
appModel.fileInfos.save();
FingerprintAuth.encrypt(encryptConfig, result => {
callback(result.token);
});
});
},
@ -206,7 +206,7 @@ const Launcher = {
token: fileInfo.get('fingerprint')
});
FingerprintAuth.decrypt(decryptConfig, result => { // eslint-disable-line no-undef
FingerprintAuth.decrypt(decryptConfig, result => {
callback(result.password);
});
}

View File

@ -8,6 +8,7 @@ const Launcher = {
name: 'electron',
version: window.process.versions.electron,
autoTypeSupported: true,
thirdPartyStoragesSupported: true,
req: window.require,
platform: function() {
return process.platform;
@ -244,10 +245,8 @@ const Launcher = {
}
}
return ps;
},
openFileChooser: function(callback, button) {
button.click();
}
// openFileChooser: function(callback) { }
};
Backbone.on('launcher-exit-request', () => {

View File

@ -550,8 +550,11 @@ const AppModel = Backbone.Model.extend({
this.fileInfos.unshift(fileInfo);
this.fileInfos.save();
if (Launcher && Launcher.fingerprints && !existing) {
Launcher.fingerprints.register(this, fileInfo, password);
if (Launcher && Launcher.fingerprints && !existing) { // only if file is not registered yet
Launcher.fingerprints.register(fileInfo.id, password.getText(), token => {
fileInfo.set('fingerprint', token);
this.fileInfos.save();
});
}
},

View File

@ -12,11 +12,9 @@ const ThirdPartyStorage = {
onedrive: require('./storage-onedrive')
};
let storages;
if (Launcher.name === 'cordova') {
let storages = _.extend(BuiltInStorage, ThirdPartyStorage);
if (Launcher && !Launcher.thirdPartyStoragesSupported) {
storages = BuiltInStorage;
} else {
storages = _.extend(BuiltInStorage, ThirdPartyStorage);
}
module.exports = storages;

View File

@ -322,14 +322,14 @@ const OpenView = Backbone.View.extend({
const fileInput = this.$el.find('.open__file-ctrl').attr('accept', ext || '').val(null);
if (Launcher) {
if (Launcher && Launcher.openFileChooser) {
Launcher.openFileChooser((err, file) => {
if (err) {
logger.error('Error opening file chooser', err);
} else {
this.processFile(file);
}
}, fileInput);
});
} else {
fileInput.click();
}