mirror of
https://github.com/keeweb/keeweb.git
synced 2024-06-27 07:45:08 +02:00
Merge pull request #674 from alex-shpak/cordova
Cordova specific file system and fingerprint fixes.
This commit is contained in:
commit
f18d053cbf
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
||||
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 => {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -163,6 +163,7 @@ const SettingsFileView = Backbone.View.extend({
|
|||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.appModel.syncFile(this.model, arg);
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user