fix compatibility: polyfill device storage "getFilesAndDirectories" method

This commit is contained in:
Mahdi Dibaiee
2015-09-14 00:59:58 +04:30
parent 2b51a7df09
commit d925dfb082
7 changed files with 173 additions and 9 deletions

View File

@ -1,11 +1,15 @@
import { type } from 'utils';
import { refresh } from 'actions/files-view';
import { bind } from 'store';
let SD_CACHE;
export function sdcard() {
if (SD_CACHE) return SD_CACHE;
SD_CACHE = navigator.getDeviceStorage('sdcard');
SD_CACHE.onchange = bind(refresh());
window.sdcard = SD_CACHE;
return SD_CACHE;
}
@ -27,7 +31,7 @@ export async function getFile(dir = '/') {
}
export async function children(dir, gatherInfo) {
let parent = await getFile(dir);
let parent = shimDirectory(await getFile(dir));
let childs = await parent.getFilesAndDirectories();
if (gatherInfo) {
@ -42,7 +46,9 @@ export async function children(dir, gatherInfo) {
child.children = subchildren.length;
} else {
child.path = dir + '/';
if (typeof child.path === 'undefined') {
child.path = dir + '/';
}
}
};
}

View File

@ -23,5 +23,5 @@ export default function(state = '', action) {
function changeTo(dir) {
children(dir, true).then(files => {
store.dispatch(listFiles(files));
}, reportError);
}, reportError)
}

View File

@ -2,7 +2,7 @@ import store from 'store';
import { show } from 'actions/dialog';
export function type(obj) {
return Object.prototype.toString.call(obj).slice(8, -1);
return obj.toString().slice(8, -1);
}
export function template(string, props) {
@ -26,6 +26,7 @@ export function getKey(object = store.getState().toJS(), key) {
}
export function reportError(err) {
console.error(err);
let action = show('errorDialog', {description: err.message});
store.dispatch(action);
}