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

@ -99,7 +99,7 @@ module.exports = function(grunt) {
tasks: ['browserify:dev'] tasks: ['browserify:dev']
}, },
assets: { assets: {
files: ['src/index.html', 'src/manifest.webapp', files: ['src/index.html', 'src/manifest.webapp', 'src/polyfill.js',
'src/fonts/**', 'src/img/**', 'src/data/**'], 'src/fonts/**', 'src/img/**', 'src/data/**'],
tasks: ['copy'] tasks: ['copy']
} }

View File

@ -29971,7 +29971,7 @@ var getFile = _asyncToGenerator(function* () {
exports.getFile = getFile; exports.getFile = getFile;
var children = _asyncToGenerator(function* (dir, gatherInfo) { var children = _asyncToGenerator(function* (dir, gatherInfo) {
var parent = yield getFile(dir); var parent = shimDirectory((yield getFile(dir)));
var childs = yield parent.getFilesAndDirectories(); var childs = yield parent.getFilesAndDirectories();
if (gatherInfo) { if (gatherInfo) {
@ -29993,9 +29993,11 @@ var children = _asyncToGenerator(function* (dir, gatherInfo) {
child.children = subchildren.length; child.children = subchildren.length;
} else { } else {
if (typeof child.path === 'undefined') {
child.path = dir + '/'; child.path = dir + '/';
} }
} }
}
} catch (err) { } catch (err) {
_didIteratorError = true; _didIteratorError = true;
_iteratorError = err; _iteratorError = err;
@ -30139,19 +30141,25 @@ function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, a
var _utils = require('utils'); var _utils = require('utils');
var _actionsFilesView = require('actions/files-view');
var _store = require('store');
var SD_CACHE = undefined; var SD_CACHE = undefined;
function sdcard() { function sdcard() {
if (SD_CACHE) return SD_CACHE; if (SD_CACHE) return SD_CACHE;
SD_CACHE = navigator.getDeviceStorage('sdcard'); SD_CACHE = navigator.getDeviceStorage('sdcard');
SD_CACHE.onchange = (0, _store.bind)((0, _actionsFilesView.refresh)());
window.sdcard = SD_CACHE; window.sdcard = SD_CACHE;
return SD_CACHE; return SD_CACHE;
} }
var ROOT_CACHE = undefined; var ROOT_CACHE = undefined;
},{"utils":"utils"}],229:[function(require,module,exports){ },{"actions/files-view":220,"store":"store","utils":"utils"}],229:[function(require,module,exports){
'use strict'; 'use strict';
Object.defineProperty(exports, '__esModule', { Object.defineProperty(exports, '__esModule', {
@ -32584,7 +32592,7 @@ var _store2 = _interopRequireDefault(_store);
var _actionsDialog = require('actions/dialog'); var _actionsDialog = require('actions/dialog');
function type(obj) { function type(obj) {
return Object.prototype.toString.call(obj).slice(8, -1); return obj.toString().slice(8, -1);
} }
function template(string, props) { function template(string, props) {
@ -32610,6 +32618,7 @@ function getKey(object, key) {
} }
function reportError(err) { function reportError(err) {
console.error(err);
var action = (0, _actionsDialog.show)('errorDialog', { description: err.message }); var action = (0, _actionsDialog.show)('errorDialog', { description: err.message });
_store2['default'].dispatch(action); _store2['default'].dispatch(action);
} }

File diff suppressed because one or more lines are too long

View File

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

View File

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

View File

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

File diff suppressed because one or more lines are too long