1
0
mirror of https://github.com/keeweb/keeweb.git synced 2024-06-21 07:06:39 +02:00

Fixed aligned launcher methods

This commit is contained in:
Alex Shpak 2017-03-19 00:30:29 +01:00
parent c799574aee
commit ad246ba180
4 changed files with 44 additions and 24 deletions

View File

@ -13,27 +13,29 @@ const Launcher = {
openLink: function(href) { openLink: function(href) {
window.open(href, '_system'); window.open(href, '_system');
}, },
devTools: false,
// openDevTools: function() { },
getSaveFileName: function(defaultPath, callback) { getSaveFileName: function(defaultPath, callback) {
// Not in cordova // Not in cordova
}, },
getDir: function() { getDataPath: function() {
const storagePath = window.cordova.file.externalDataDirectory; const storagePath = window.cordova.file.externalDataDirectory;
return [storagePath].concat(Array.from(arguments)).filter(s => !!s); return [storagePath].concat(Array.from(arguments)).filter(s => !!s);
}, },
getUserDataPath: function(fileName) { getUserDataPath: function(fileName) {
return this.getDir('userdata', fileName).join('/'); return this.getDataPath('userdata', fileName).join('/');
}, },
getTempPath: function(fileName) { getTempPath: function(fileName) {
return this.getDir('temp', fileName).join('/'); return this.getDataPath('temp', fileName).join('/');
}, },
getDocumentsPath: function(fileName) { getDocumentsPath: function(fileName) {
return this.getDir('documents', fileName).join('/'); return this.getDataPath('documents', fileName).join('/');
}, },
getAppPath: function(fileName) { getAppPath: function(fileName) {
return this.getDir(fileName).join('/'); return this.getDataPath(fileName).join('/');
}, },
getWorkDirPath: function(fileName) { getWorkDirPath: function(fileName) {
return this.getDir(fileName).join('/'); return this.getDataPath(fileName).join('/');
}, },
writeFile: function(path, data, callback) { writeFile: function(path, data, callback) {
const writeFile = fileEntry => { const writeFile = fileEntry => {
@ -77,7 +79,11 @@ const Launcher = {
}, err => callback(undefined, err)); }, err => callback(undefined, err));
}, err => callback(undefined, err)); }, err => callback(undefined, err));
}, },
statFileSync: function(path) {
this.req('fs').statSync(path);
},
mkdir: function(dir, callback) { mkdir: function(dir, callback) {
const basePath = this.getDataPath().join('/');
const createDir = (dirEntry, path, callback) => { const createDir = (dirEntry, path, callback) => {
const name = path.shift(); const name = path.shift();
dirEntry.getDirectory(name, { create: true }, dirEntry => { dirEntry.getDirectory(name, { create: true }, dirEntry => {
@ -89,11 +95,10 @@ const Launcher = {
}, callback); }, callback);
}; };
const localPath = dir.replace(this.appStorage, '').split('/').filter(s => !!s); const localPath = dir.replace(basePath, '').split('/').filter(s => !!s);
localPath.pop(); // pop file name
if (localPath.length) { if (localPath.length) {
window.resolveLocalFileSystemURL(this.appStorage, dirEntry => { window.resolveLocalFileSystemURL(basePath, dirEntry => {
createDir(dirEntry, localPath, callback); createDir(dirEntry, localPath, callback);
}, callback); }, callback);
} else { } else {
@ -109,21 +114,28 @@ const Launcher = {
file: parts.join('/') file: parts.join('/')
}; };
}, },
joinPath: function(dir, fileName) {
return [dir, fileName].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) { },
preventExit: function(e) { preventExit: function(e) {
e.returnValue = false; e.returnValue = false;
return false; return false;
}, },
exit: function() { exit: function() {
// skip this.hideApp();
},
requestExit: function() {
// skip in cordova
}, },
requestRestart: function() { requestRestart: function() {
window.location.reload(); window.location.reload();
}, },
cancelRestart: function() { cancelRestart: function() {
// skip // skip in cordova
}, },
setClipboardText: function(text) { setClipboardText: function(text) {
return document.execCommand('copy'); return document.execCommand('copy');
@ -143,36 +155,35 @@ const Launcher = {
updaterEnabled: function() { updaterEnabled: function() {
return false; return false;
}, },
// getMainWindow: function() { },
resolveProxy: function(url, callback) { resolveProxy: function(url, callback) {
// TODO // skip in cordova
}, },
openWindow: function(opts) { openWindow: function(opts) {
// skip // skip in cordova
}, },
hideApp: function() { // home button hideApp: function() { // home button
// TODO // TODO
}, },
isAppFocused: function() { isAppFocused: function() {
return false; // skip return false; // skip in cordova
}, },
showMainWindow: function() { showMainWindow: function() {
// skip // skip in cordova
}, },
// spawn: function(config) { },
openFileChooser: function(callback, button) { openFileChooser: function(callback, button) {
const onFileSelected = function(selected) { const onFileSelected = function(selected) {
window.resolveLocalFileSystemURL(selected.uri, fileEntry => { window.resolveLocalFileSystemURL(selected.uri, fileEntry => {
fileEntry.file(file => { fileEntry.file(file => {
file.path = file.localURL; file.path = file.localURL;
file.name = selected.name; file.name = selected.name;
callback(file); callback(null, file);
}); });
}); });
}; };
window.cordova.exec(onFileSelected, e => { window.cordova.exec(onFileSelected, callback, 'FileChooser', 'choose');
// TODO logging
}, 'FileChooser', 'choose');
}, },
fingerprints: { fingerprints: {

View File

@ -119,6 +119,9 @@ const Launcher = {
file: path.basename(fileName) file: path.basename(fileName)
}; };
}, },
joinPath: function(dir, fileName) {
return this.req('path').join(dir, fileName);
},
createFsWatcher: function(path) { createFsWatcher: function(path) {
return this.req('fs').watch(path, { persistent: false }); return this.req('fs').watch(path, { persistent: false });
}, },
@ -245,8 +248,8 @@ const Launcher = {
} }
return ps; return ps;
}, },
openFileChooser: function(context, fileInput) { openFileChooser: function(callback, button) {
fileInput.click(); button.click();
} }
}; };

View File

@ -9,7 +9,7 @@ const StorageFileCache = StorageBase.extend({
path: null, path: null,
getPath: function(id) { getPath: function(id) {
return Launcher.req('path').join(this.path, id); return Launcher.joinPath(this.path, id);
}, },
initFs: function(callback) { initFs: function(callback) {

View File

@ -323,7 +323,13 @@ const OpenView = Backbone.View.extend({
const fileInput = this.$el.find('.open__file-ctrl').attr('accept', ext || '').val(null); const fileInput = this.$el.find('.open__file-ctrl').attr('accept', ext || '').val(null);
if (Launcher) { if (Launcher) {
Launcher.openFileChooser(this.processFile.bind(this), fileInput); Launcher.openFileChooser((err, file) => {
if (err) {
logger.error('Error opening ашду срщщыук', err);
} else {
this.processFile(file);
}
}, fileInput);
} else { } else {
fileInput.click(); fileInput.click();
} }