Merge pull request #674 from alex-shpak/cordova

Cordova specific file system and fingerprint fixes.
This commit is contained in:
antelle 2019-01-10 18:48:49 +01:00 committed by GitHub
commit f18d053cbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 70 additions and 33 deletions

View File

@ -3,10 +3,10 @@ const Launcher = require('./launcher');
const AppSettingsModel = require('../models/app-settings-model');
const CopyPaste = {
simpleCopy: !!Launcher,
simpleCopy: !!(Launcher && Launcher.clipboardSupported),
copy: function(text) {
if (Launcher) {
if (this.simpleCopy) {
Launcher.setClipboardText(text);
const clipboardSeconds = AppSettingsModel.instance.get('clipboardSeconds');
if (clipboardSeconds > 0) {

View File

@ -1,12 +1,18 @@
/* global FingerprintAuth */
const Backbone = require('backbone');
const Launcher = {
name: 'cordova',
version: '6.0.0',
autoTypeSupported: false,
thirdPartyStoragesSupported: false,
clipboardSupported: false,
ready: function(callback) {
document.addEventListener('deviceready', callback, false);
document.addEventListener('pause', () => {
Backbone.trigger('app-minimized');
}, false);
},
platform: function() {
return 'cordova';
@ -40,6 +46,12 @@ const Launcher = {
return [...parts].join('/');
},
writeFile: function(path, data, callback) {
const createFile = filePath => {
window.resolveLocalFileSystemURL(filePath.dir, dir => {
dir.getFile(filePath.file, {create: true}, writeFile);
}, callback, callback);
};
const writeFile = fileEntry => {
fileEntry.createWriter(fileWriter => {
fileWriter.onerror = callback;
@ -48,7 +60,14 @@ const Launcher = {
}, callback);
};
window.resolveLocalFileSystemURL(path, writeFile, callback, callback);
if (path.startsWith('cdvfile://')) { // then file exists
window.resolveLocalFileSystemURL(path, writeFile, callback, callback);
} else { // create file on sd card
const filePath = this.parsePath(path);
this.mkdir(filePath.dir, () => {
createFile(filePath);
});
}
},
readFile: function(path, encoding, callback) {
window.resolveLocalFileSystemURL(path, fileEntry => {
@ -109,14 +128,15 @@ const Launcher = {
return {
path: fileName,
dir: parts.pop(),
file: parts.join('/')
file: parts.pop(),
dir: parts.join('/')
};
},
createFsWatcher: function(path) {
return null; // not in android with content provider
},
// ensureRunnable: function(path) { },
preventExit: function(e) {
e.returnValue = false;
return false;
@ -124,29 +144,30 @@ const Launcher = {
exit: function() {
this.hideApp();
},
requestExit: function() { /* skip in cordova */ },
requestRestart: function() {
window.location.reload();
},
cancelRestart: function() { /* skip in cordova */ },
setClipboardText: function(text) {
// TODO
},
getClipboardText: function() {
// TODO
},
clearClipboardText: function() {
// TODO
},
setClipboardText: function(text) {},
getClipboardText: function() {},
clearClipboardText: function() {},
minimizeApp: function() {
this.hideApp();
},
canMinimize: function() {
return false;
},
canDetectOsSleep: function() {
return false;
},
updaterEnabled: function() {
return false;
},
// getMainWindow: function() { },
resolveProxy: function(url, callback) { /* skip in cordova */ },
openWindow: function(opts) { /* skip in cordova */ },
@ -169,6 +190,12 @@ const Launcher = {
window.cordova.exec(onFileSelected, callback, 'FileChooser', 'choose');
},
getCookies(callback) {
// TODO
},
setCookies(cookies) {
// TODO
},
fingerprints: {
config: {
@ -184,7 +211,7 @@ const Launcher = {
const encryptConfig = _.extend({}, this.config, {
username: fileId,
password: password
password: password.getText()
});
FingerprintAuth.encrypt(encryptConfig, result => {

View File

@ -9,6 +9,7 @@ const Launcher = {
version: window.process.versions.electron,
autoTypeSupported: true,
thirdPartyStoragesSupported: true,
clipboardSupported: true,
req: window.require,
platform: function() {
return process.platform;

View File

@ -1021,12 +1021,12 @@ const AppModel = Backbone.Model.extend({
},
saveFileFingerprint: function(file, password) {
if (Launcher && Launcher.fingerprints && password) {
if (Launcher && Launcher.fingerprints && !file.has('fingerprint')) {
const fileInfo = this.fileInfos.get(file.id);
Launcher.fingerprints.register(file.id, this.params.password, token => {
Launcher.fingerprints.register(file.id, password, token => {
if (token) {
fileInfo.set('fingerprint', token);
this.model.fileInfos.save();
fileInfo.set({ fingerprint: token });
this.fileInfos.save();
}
});
}

View File

@ -421,6 +421,12 @@ const FileModel = Backbone.Model.extend({
syncing: false,
syncError: error
});
const shouldResetFingerprint = this.get('passwordChanged') && this.has('fingerprint');
if (shouldResetFingerprint && !error) {
this.set({ fingerprint: null });
}
if (!this.get('open')) {
return;
}

View File

@ -378,20 +378,6 @@ const OpenView = Backbone.View.extend({
const fileInfo = this.model.fileInfos.get(id);
this.showOpenFileInfo(fileInfo);
if (fileInfo && Launcher && Launcher.fingerprints) {
this.openFileWithFingerprint(fileInfo);
}
},
openFileWithFingerprint(fileInfo) {
if (fileInfo.get('fingerprint')) {
Launcher.fingerprints.auth(fileInfo.id, fileInfo.get('fingerprint'), password => {
this.inputEl.val(password);
this.inputEl.trigger('input');
this.openDb();
});
}
},
removeFile: function(id) {
@ -515,6 +501,8 @@ const OpenView = Backbone.View.extend({
this.params.keyFileData = null;
this.displayOpenFile();
this.displayOpenKeyFile();
this.openFileWithFingerprint(fileInfo);
},
showOpenLocalFile: function(path, keyFilePath) {
@ -537,6 +525,20 @@ const OpenView = Backbone.View.extend({
}
},
openFileWithFingerprint: function(fileInfo) {
if (!fileInfo.has('fingerprint')) {
return;
}
if (Launcher && Launcher.fingerprints) {
Launcher.fingerprints.auth(fileInfo.id, fileInfo.get('fingerprint'), password => {
this.inputEl.val(password);
this.inputEl.trigger('input');
this.openDb();
});
}
},
createDemo: function() {
if (!this.busy) {
this.closeConfig();

View File

@ -163,6 +163,7 @@ const SettingsFileView = Backbone.View.extend({
return;
}
}
this.appModel.syncFile(this.model, arg);
},