2017-02-05 22:01:46 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const Launcher = {
|
2017-02-22 01:35:16 +01:00
|
|
|
name: 'cordova',
|
2017-02-05 22:01:46 +01:00
|
|
|
version: '6.0.0',
|
|
|
|
autoTypeSupported: false,
|
|
|
|
ready: function(callback) {
|
2017-02-22 01:12:42 +01:00
|
|
|
document.addEventListener('deviceready', callback, false);
|
2017-02-05 22:01:46 +01:00
|
|
|
},
|
|
|
|
platform: function() {
|
|
|
|
return 'cordova';
|
|
|
|
},
|
|
|
|
openLink: function(href) {
|
|
|
|
window.open(href, '_system');
|
|
|
|
},
|
|
|
|
getSaveFileName: function(defaultPath, callback) {
|
2017-02-22 01:35:16 +01:00
|
|
|
// Not in cordova
|
2017-02-05 22:01:46 +01:00
|
|
|
},
|
|
|
|
getDir: function() {
|
|
|
|
const storagePath = window.cordova.file.externalDataDirectory;
|
|
|
|
return [storagePath].concat(Array.from(arguments)).filter(s => !!s);
|
|
|
|
},
|
|
|
|
getUserDataPath: function(fileName) {
|
|
|
|
return this.getDir('userdata', fileName).join('/');
|
|
|
|
},
|
|
|
|
getTempPath: function(fileName) {
|
|
|
|
return this.getDir('temp', fileName).join('/');
|
|
|
|
},
|
|
|
|
getDocumentsPath: function(fileName) {
|
|
|
|
return this.getDir('documents', fileName).join('/');
|
|
|
|
},
|
|
|
|
getAppPath: function(fileName) {
|
|
|
|
return this.getDir(fileName).join('/');
|
|
|
|
},
|
|
|
|
getWorkDirPath: function(fileName) {
|
|
|
|
return this.getDir(fileName).join('/');
|
|
|
|
},
|
|
|
|
writeFile: function(path, data, callback) {
|
|
|
|
const writeFile = fileEntry => {
|
|
|
|
fileEntry.createWriter(fileWriter => {
|
|
|
|
fileWriter.onerror = callback;
|
|
|
|
fileWriter.onwriteend = () => callback();
|
|
|
|
fileWriter.write(data);
|
|
|
|
}, callback);
|
|
|
|
};
|
|
|
|
|
2017-02-22 01:12:42 +01:00
|
|
|
window.resolveLocalFileSystemURL(path, writeFile, callback, callback);
|
2017-02-05 22:01:46 +01:00
|
|
|
},
|
|
|
|
readFile: function(path, encoding, callback) {
|
|
|
|
window.resolveLocalFileSystemURL(path, fileEntry => {
|
|
|
|
fileEntry.file(file => {
|
|
|
|
const reader = new FileReader();
|
|
|
|
reader.onerror = callback;
|
|
|
|
reader.onloadend = () => {
|
|
|
|
const contents = new Uint8Array(reader.result);
|
|
|
|
callback(encoding ? String.fromCharCode.apply(null, contents) : contents);
|
|
|
|
};
|
|
|
|
reader.readAsArrayBuffer(file);
|
|
|
|
}, err => callback(undefined, err));
|
|
|
|
}, err => callback(undefined, err));
|
|
|
|
},
|
|
|
|
fileExists: function(path, callback) {
|
|
|
|
window.resolveLocalFileSystemURL(path, fileEntry => callback(true), err => callback(false)); // eslint-disable-line handle-callback-err
|
|
|
|
},
|
|
|
|
deleteFile: function(path, callback) {
|
|
|
|
window.resolveLocalFileSystemURL(path, fileEntry => {
|
|
|
|
fileEntry.remove(callback, callback, callback);
|
|
|
|
}, callback);
|
|
|
|
},
|
|
|
|
statFile: function(path, callback) {
|
|
|
|
window.resolveLocalFileSystemURL(path, fileEntry => {
|
|
|
|
fileEntry.file(file => {
|
|
|
|
callback({
|
|
|
|
ctime: new Date(file.lastModified),
|
|
|
|
mtime: new Date(file.lastModified)
|
|
|
|
});
|
|
|
|
}, err => callback(undefined, err));
|
|
|
|
}, err => callback(undefined, err));
|
|
|
|
},
|
2017-02-22 01:12:42 +01:00
|
|
|
mkdir: function(dir, callback) {
|
|
|
|
const createDir = (dirEntry, path, callback) => {
|
|
|
|
const name = path.shift();
|
|
|
|
dirEntry.getDirectory(name, { create: true }, dirEntry => {
|
|
|
|
if (path.length) { // there is more to create
|
|
|
|
createDir(dirEntry, path, callback);
|
|
|
|
} else {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
}, callback);
|
|
|
|
};
|
|
|
|
|
|
|
|
const localPath = dir.replace(this.appStorage, '').split('/').filter(s => !!s);
|
|
|
|
localPath.pop(); // pop file name
|
|
|
|
|
|
|
|
if (localPath.length) {
|
|
|
|
window.resolveLocalFileSystemURL(this.appStorage, dirEntry => {
|
|
|
|
createDir(dirEntry, localPath, callback);
|
|
|
|
}, callback);
|
|
|
|
} else {
|
|
|
|
callback();
|
|
|
|
}
|
2017-02-05 22:01:46 +01:00
|
|
|
},
|
|
|
|
parsePath: function(fileName) {
|
|
|
|
const parts = fileName.split('/');
|
|
|
|
|
|
|
|
return {
|
|
|
|
path: fileName,
|
|
|
|
dir: parts.pop(),
|
|
|
|
file: parts.join('/')
|
|
|
|
};
|
|
|
|
},
|
|
|
|
createFsWatcher: function(path) {
|
|
|
|
return null; // not in android with content provider
|
|
|
|
},
|
|
|
|
preventExit: function(e) {
|
|
|
|
e.returnValue = false;
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
exit: function() {
|
|
|
|
// skip
|
|
|
|
},
|
|
|
|
requestRestart: function() {
|
|
|
|
window.location.reload();
|
|
|
|
},
|
|
|
|
cancelRestart: function() {
|
|
|
|
// skip
|
|
|
|
},
|
|
|
|
setClipboardText: function(text) {
|
|
|
|
return document.execCommand('copy');
|
|
|
|
},
|
|
|
|
getClipboardText: function() {
|
|
|
|
// TODO
|
|
|
|
},
|
|
|
|
clearClipboardText: function() {
|
|
|
|
// TODO
|
|
|
|
},
|
|
|
|
minimizeApp: function() {
|
|
|
|
this.hideApp();
|
|
|
|
},
|
|
|
|
canMinimize: function() {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
updaterEnabled: function() {
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
resolveProxy: function(url, callback) {
|
|
|
|
// TODO
|
|
|
|
},
|
|
|
|
openWindow: function(opts) {
|
|
|
|
// skip
|
|
|
|
},
|
|
|
|
hideApp: function() { // home button
|
|
|
|
// TODO
|
|
|
|
},
|
|
|
|
isAppFocused: function() {
|
|
|
|
return false; // skip
|
|
|
|
},
|
|
|
|
showMainWindow: function() {
|
|
|
|
// skip
|
|
|
|
},
|
|
|
|
|
2017-02-22 01:12:42 +01:00
|
|
|
openFileChooser: function(callback, button) {
|
2017-02-05 22:36:32 +01:00
|
|
|
const onFileSelected = function(selected) {
|
2017-02-22 01:12:42 +01:00
|
|
|
window.resolveLocalFileSystemURL(selected.uri, fileEntry => {
|
|
|
|
fileEntry.file(file => {
|
|
|
|
file.path = file.localURL;
|
|
|
|
file.name = selected.name;
|
|
|
|
callback(file);
|
|
|
|
});
|
|
|
|
});
|
2017-02-05 22:36:32 +01:00
|
|
|
};
|
|
|
|
|
2017-02-22 01:12:42 +01:00
|
|
|
window.cordova.exec(onFileSelected, e => {
|
|
|
|
// TODO logging
|
|
|
|
}, 'FileChooser', 'choose');
|
2017-02-05 22:36:32 +01:00
|
|
|
},
|
|
|
|
|
2017-02-05 22:01:46 +01:00
|
|
|
fingerprints: {
|
2017-02-05 22:36:32 +01:00
|
|
|
config: {
|
|
|
|
disableBackup: true,
|
|
|
|
clientId: 'keeweb'
|
|
|
|
},
|
|
|
|
|
2017-02-05 22:01:46 +01:00
|
|
|
register: function(appModel, fileInfo, password) {
|
2017-02-05 22:36:32 +01:00
|
|
|
FingerprintAuth.isAvailable(result => { // eslint-disable-line no-undef
|
|
|
|
if (!result.isAvailable) {
|
|
|
|
return;
|
|
|
|
}
|
2017-02-05 22:01:46 +01:00
|
|
|
|
2017-02-05 22:36:32 +01:00
|
|
|
const encryptConfig = _.extend({}, this.config, {
|
|
|
|
username: fileInfo.id,
|
|
|
|
password: password.getText()
|
|
|
|
});
|
|
|
|
|
|
|
|
FingerprintAuth.encrypt(encryptConfig, result => { // eslint-disable-line no-undef
|
|
|
|
fileInfo.set('fingerprint', result.token);
|
|
|
|
appModel.fileInfos.save();
|
|
|
|
});
|
|
|
|
});
|
2017-02-05 22:01:46 +01:00
|
|
|
},
|
2017-02-05 22:36:32 +01:00
|
|
|
|
2017-02-05 22:01:46 +01:00
|
|
|
auth: function(fileInfo, callback) {
|
2017-02-05 22:36:32 +01:00
|
|
|
if (!fileInfo.has('fingerprint')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const decryptConfig = _.extend({}, this.config, {
|
|
|
|
username: fileInfo.id,
|
|
|
|
token: fileInfo.get('fingerprint')
|
|
|
|
});
|
2017-02-05 22:01:46 +01:00
|
|
|
|
2017-02-05 22:36:32 +01:00
|
|
|
FingerprintAuth.decrypt(decryptConfig, result => { // eslint-disable-line no-undef
|
|
|
|
callback(result.password);
|
|
|
|
});
|
2017-02-05 22:01:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = Launcher;
|