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 AppSettingsModel = require('../models/app-settings-model');
|
||||||
|
|
||||||
const CopyPaste = {
|
const CopyPaste = {
|
||||||
simpleCopy: !!Launcher,
|
simpleCopy: !!(Launcher && Launcher.clipboardSupported),
|
||||||
|
|
||||||
copy: function(text) {
|
copy: function(text) {
|
||||||
if (Launcher) {
|
if (this.simpleCopy) {
|
||||||
Launcher.setClipboardText(text);
|
Launcher.setClipboardText(text);
|
||||||
const clipboardSeconds = AppSettingsModel.instance.get('clipboardSeconds');
|
const clipboardSeconds = AppSettingsModel.instance.get('clipboardSeconds');
|
||||||
if (clipboardSeconds > 0) {
|
if (clipboardSeconds > 0) {
|
||||||
|
|
|
@ -1,12 +1,18 @@
|
||||||
/* global FingerprintAuth */
|
/* global FingerprintAuth */
|
||||||
|
|
||||||
|
const Backbone = require('backbone');
|
||||||
|
|
||||||
const Launcher = {
|
const Launcher = {
|
||||||
name: 'cordova',
|
name: 'cordova',
|
||||||
version: '6.0.0',
|
version: '6.0.0',
|
||||||
autoTypeSupported: false,
|
autoTypeSupported: false,
|
||||||
thirdPartyStoragesSupported: false,
|
thirdPartyStoragesSupported: false,
|
||||||
|
clipboardSupported: false,
|
||||||
ready: function(callback) {
|
ready: function(callback) {
|
||||||
document.addEventListener('deviceready', callback, false);
|
document.addEventListener('deviceready', callback, false);
|
||||||
|
document.addEventListener('pause', () => {
|
||||||
|
Backbone.trigger('app-minimized');
|
||||||
|
}, false);
|
||||||
},
|
},
|
||||||
platform: function() {
|
platform: function() {
|
||||||
return 'cordova';
|
return 'cordova';
|
||||||
|
@ -40,6 +46,12 @@ const Launcher = {
|
||||||
return [...parts].join('/');
|
return [...parts].join('/');
|
||||||
},
|
},
|
||||||
writeFile: function(path, data, callback) {
|
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 => {
|
const writeFile = fileEntry => {
|
||||||
fileEntry.createWriter(fileWriter => {
|
fileEntry.createWriter(fileWriter => {
|
||||||
fileWriter.onerror = callback;
|
fileWriter.onerror = callback;
|
||||||
|
@ -48,7 +60,14 @@ const Launcher = {
|
||||||
}, callback);
|
}, 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) {
|
readFile: function(path, encoding, callback) {
|
||||||
window.resolveLocalFileSystemURL(path, fileEntry => {
|
window.resolveLocalFileSystemURL(path, fileEntry => {
|
||||||
|
@ -109,14 +128,15 @@ const Launcher = {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
path: fileName,
|
path: fileName,
|
||||||
dir: parts.pop(),
|
file: parts.pop(),
|
||||||
file: parts.join('/')
|
dir: parts.join('/')
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
createFsWatcher: function(path) {
|
createFsWatcher: function(path) {
|
||||||
return null; // not in android with content provider
|
return null; // not in android with content provider
|
||||||
},
|
},
|
||||||
// ensureRunnable: function(path) { },
|
// ensureRunnable: function(path) { },
|
||||||
|
|
||||||
preventExit: function(e) {
|
preventExit: function(e) {
|
||||||
e.returnValue = false;
|
e.returnValue = false;
|
||||||
return false;
|
return false;
|
||||||
|
@ -124,29 +144,30 @@ const Launcher = {
|
||||||
exit: function() {
|
exit: function() {
|
||||||
this.hideApp();
|
this.hideApp();
|
||||||
},
|
},
|
||||||
|
|
||||||
requestExit: function() { /* skip in cordova */ },
|
requestExit: function() { /* skip in cordova */ },
|
||||||
requestRestart: function() {
|
requestRestart: function() {
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
},
|
},
|
||||||
cancelRestart: function() { /* skip in cordova */ },
|
cancelRestart: function() { /* skip in cordova */ },
|
||||||
setClipboardText: function(text) {
|
|
||||||
// TODO
|
setClipboardText: function(text) {},
|
||||||
},
|
getClipboardText: function() {},
|
||||||
getClipboardText: function() {
|
clearClipboardText: function() {},
|
||||||
// TODO
|
|
||||||
},
|
|
||||||
clearClipboardText: function() {
|
|
||||||
// TODO
|
|
||||||
},
|
|
||||||
minimizeApp: function() {
|
minimizeApp: function() {
|
||||||
this.hideApp();
|
this.hideApp();
|
||||||
},
|
},
|
||||||
canMinimize: function() {
|
canMinimize: function() {
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
canDetectOsSleep: function() {
|
||||||
|
return false;
|
||||||
|
},
|
||||||
updaterEnabled: function() {
|
updaterEnabled: function() {
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
// getMainWindow: function() { },
|
// getMainWindow: function() { },
|
||||||
resolveProxy: function(url, callback) { /* skip in cordova */ },
|
resolveProxy: function(url, callback) { /* skip in cordova */ },
|
||||||
openWindow: function(opts) { /* skip in cordova */ },
|
openWindow: function(opts) { /* skip in cordova */ },
|
||||||
|
@ -169,6 +190,12 @@ const Launcher = {
|
||||||
|
|
||||||
window.cordova.exec(onFileSelected, callback, 'FileChooser', 'choose');
|
window.cordova.exec(onFileSelected, callback, 'FileChooser', 'choose');
|
||||||
},
|
},
|
||||||
|
getCookies(callback) {
|
||||||
|
// TODO
|
||||||
|
},
|
||||||
|
setCookies(cookies) {
|
||||||
|
// TODO
|
||||||
|
},
|
||||||
|
|
||||||
fingerprints: {
|
fingerprints: {
|
||||||
config: {
|
config: {
|
||||||
|
@ -184,7 +211,7 @@ const Launcher = {
|
||||||
|
|
||||||
const encryptConfig = _.extend({}, this.config, {
|
const encryptConfig = _.extend({}, this.config, {
|
||||||
username: fileId,
|
username: fileId,
|
||||||
password: password
|
password: password.getText()
|
||||||
});
|
});
|
||||||
|
|
||||||
FingerprintAuth.encrypt(encryptConfig, result => {
|
FingerprintAuth.encrypt(encryptConfig, result => {
|
||||||
|
|
|
@ -9,6 +9,7 @@ const Launcher = {
|
||||||
version: window.process.versions.electron,
|
version: window.process.versions.electron,
|
||||||
autoTypeSupported: true,
|
autoTypeSupported: true,
|
||||||
thirdPartyStoragesSupported: true,
|
thirdPartyStoragesSupported: true,
|
||||||
|
clipboardSupported: true,
|
||||||
req: window.require,
|
req: window.require,
|
||||||
platform: function() {
|
platform: function() {
|
||||||
return process.platform;
|
return process.platform;
|
||||||
|
|
|
@ -1021,12 +1021,12 @@ const AppModel = Backbone.Model.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
saveFileFingerprint: function(file, password) {
|
saveFileFingerprint: function(file, password) {
|
||||||
if (Launcher && Launcher.fingerprints && password) {
|
if (Launcher && Launcher.fingerprints && !file.has('fingerprint')) {
|
||||||
const fileInfo = this.fileInfos.get(file.id);
|
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) {
|
if (token) {
|
||||||
fileInfo.set('fingerprint', token);
|
fileInfo.set({ fingerprint: token });
|
||||||
this.model.fileInfos.save();
|
this.fileInfos.save();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -421,6 +421,12 @@ const FileModel = Backbone.Model.extend({
|
||||||
syncing: false,
|
syncing: false,
|
||||||
syncError: error
|
syncError: error
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const shouldResetFingerprint = this.get('passwordChanged') && this.has('fingerprint');
|
||||||
|
if (shouldResetFingerprint && !error) {
|
||||||
|
this.set({ fingerprint: null });
|
||||||
|
}
|
||||||
|
|
||||||
if (!this.get('open')) {
|
if (!this.get('open')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -378,20 +378,6 @@ const OpenView = Backbone.View.extend({
|
||||||
|
|
||||||
const fileInfo = this.model.fileInfos.get(id);
|
const fileInfo = this.model.fileInfos.get(id);
|
||||||
this.showOpenFileInfo(fileInfo);
|
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) {
|
removeFile: function(id) {
|
||||||
|
@ -515,6 +501,8 @@ const OpenView = Backbone.View.extend({
|
||||||
this.params.keyFileData = null;
|
this.params.keyFileData = null;
|
||||||
this.displayOpenFile();
|
this.displayOpenFile();
|
||||||
this.displayOpenKeyFile();
|
this.displayOpenKeyFile();
|
||||||
|
|
||||||
|
this.openFileWithFingerprint(fileInfo);
|
||||||
},
|
},
|
||||||
|
|
||||||
showOpenLocalFile: function(path, keyFilePath) {
|
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() {
|
createDemo: function() {
|
||||||
if (!this.busy) {
|
if (!this.busy) {
|
||||||
this.closeConfig();
|
this.closeConfig();
|
||||||
|
|
|
@ -163,6 +163,7 @@ const SettingsFileView = Backbone.View.extend({
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.appModel.syncFile(this.model, arg);
|
this.appModel.syncFile(this.model, arg);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user