Improve compatibility with old versions
- Remove starting "/sdcard/" from file paths on old Firefox OS versions - Cache results for faster navigation on old Firefox OS devices
This commit is contained in:
parent
66504df4cb
commit
6e52ca6246
@ -56,6 +56,7 @@ Version 1.0
|
||||
Version 2.0
|
||||
------------
|
||||
- [x] Different views (List, Grid)
|
||||
- [ ] Show storage usage statistics (free/used)
|
||||
- [ ] Sort Files
|
||||
- [ ] Zip / Unzip
|
||||
- [ ] Image Thumbnails
|
||||
|
@ -29952,6 +29952,10 @@ var root = _asyncToGenerator(function* () {
|
||||
if (ROOT_CACHE) return ROOT_CACHE;
|
||||
|
||||
ROOT_CACHE = shimDirectory((yield sdcard().getRoot()));
|
||||
Object.defineProperty(ROOT_CACHE, 'name', {
|
||||
value: '',
|
||||
enumerable: true
|
||||
});
|
||||
window.root = ROOT_CACHE;
|
||||
return ROOT_CACHE;
|
||||
});
|
||||
@ -29965,19 +29969,21 @@ var getFile = _asyncToGenerator(function* () {
|
||||
|
||||
if (dir === '/' || !dir) return parent;
|
||||
|
||||
return yield parent.get(dir);
|
||||
return yield parent.get((0, _utils.normalize)(dir));
|
||||
});
|
||||
|
||||
exports.getFile = getFile;
|
||||
|
||||
var children = _asyncToGenerator(function* (dir, gatherInfo) {
|
||||
if (CACHE[dir]) return CACHE[dir];
|
||||
|
||||
var parent = shimDirectory((yield getFile(dir)));
|
||||
if (!parent.path) {
|
||||
parent.path = dir.slice(0, dir.lastIndexOf('/') + 1);
|
||||
}
|
||||
var childs = yield parent.getFilesAndDirectories();
|
||||
|
||||
if (gatherInfo) {
|
||||
if (gatherInfo && !window.needsShim) {
|
||||
var _iteratorNormalCompletion = true;
|
||||
var _didIteratorError = false;
|
||||
var _iteratorError = undefined;
|
||||
@ -30019,6 +30025,8 @@ var children = _asyncToGenerator(function* (dir, gatherInfo) {
|
||||
;
|
||||
}
|
||||
|
||||
CACHE[dir] = childs;
|
||||
|
||||
return childs;
|
||||
});
|
||||
|
||||
@ -30074,7 +30082,7 @@ var remove = _asyncToGenerator(function* (file, deep) {
|
||||
exports.remove = remove;
|
||||
|
||||
var move = _asyncToGenerator(function* (file, newPath) {
|
||||
var path = (file.path || '').replace(/^\//, ''); // remove starting slash
|
||||
var path = (0, _utils.normalize)(file.path || '');
|
||||
var oldPath = path + file.name;
|
||||
|
||||
var process = yield copy(file, newPath);
|
||||
@ -30084,10 +30092,10 @@ var move = _asyncToGenerator(function* (file, newPath) {
|
||||
exports.move = move;
|
||||
|
||||
var copy = _asyncToGenerator(function* (file, newPath) {
|
||||
var path = (file.path || '').replace(/^\//, ''); // remove starting slash
|
||||
var path = (0, _utils.normalize)(file.path || '').replace(/^\//, '');
|
||||
var oldPath = path + file.name;
|
||||
|
||||
newPath = newPath.replace(/^\//, '');
|
||||
newPath = (0, _utils.normalize)(newPath);
|
||||
|
||||
var target = yield getFile(oldPath);
|
||||
var parent = yield root();
|
||||
@ -30106,7 +30114,8 @@ var copy = _asyncToGenerator(function* (file, newPath) {
|
||||
|
||||
if ((0, _utils.type)(child) === 'File') {
|
||||
Object.defineProperty(child, 'path', {
|
||||
value: oldPath + '/'
|
||||
value: oldPath + '/',
|
||||
enumerable: true
|
||||
});
|
||||
}
|
||||
|
||||
@ -30159,12 +30168,15 @@ var _actionsFilesView = require('actions/files-view');
|
||||
var _store = require('store');
|
||||
|
||||
var SD_CACHE = undefined;
|
||||
var CACHE = {};
|
||||
|
||||
exports.CACHE = CACHE;
|
||||
localStorage.setItem('cache', '{}');
|
||||
|
||||
function sdcard() {
|
||||
if (SD_CACHE) return SD_CACHE;
|
||||
|
||||
SD_CACHE = navigator.getDeviceStorage('sdcard');
|
||||
SD_CACHE.onchange = (0, _store.bind)((0, _actionsFilesView.refresh)());
|
||||
window.sdcard = SD_CACHE;
|
||||
|
||||
return SD_CACHE;
|
||||
@ -30445,8 +30457,7 @@ var Directory = (function (_Component) {
|
||||
_react2['default'].createElement(
|
||||
'span',
|
||||
null,
|
||||
this.props.children,
|
||||
' items'
|
||||
this.props.children ? this.props.children + ' items' : ''
|
||||
)
|
||||
);
|
||||
}
|
||||
@ -30645,6 +30656,8 @@ var File = (function (_Component) {
|
||||
label = _react2['default'].createElement('label', { htmlFor: checkId });
|
||||
}
|
||||
|
||||
console.log(this.props.type);
|
||||
|
||||
var clickHandler = this.props.selectView ? this.select.bind(this) : this.open.bind(this);
|
||||
|
||||
return _react2['default'].createElement(
|
||||
@ -31968,6 +31981,10 @@ exports['default'] = function (state, action) {
|
||||
return action.dir;
|
||||
}
|
||||
|
||||
if (action.type === _actionsTypes.REFRESH) {
|
||||
_apiFiles.CACHE[state] = null;
|
||||
}
|
||||
|
||||
if (action.type === _actionsTypes.REFRESH || action.type === _actionsTypes.SETTINGS) {
|
||||
changeTo(state);
|
||||
|
||||
@ -32301,7 +32318,7 @@ function search(keywords) {
|
||||
|
||||
var filtered = files.filter(function (file) {
|
||||
if ((0, _utils.type)(file) === 'Directory') {
|
||||
var path = (file.path + file.name).replace(/^\//, '');
|
||||
var path = (0, _utils.normalize)(file.path + file.name);
|
||||
(0, _apiFiles.children)(path, true).then(showResults, _utils.reportError);
|
||||
}
|
||||
return keys.some(function (key) {
|
||||
@ -32602,6 +32619,7 @@ exports.type = type;
|
||||
exports.template = template;
|
||||
exports.getKey = getKey;
|
||||
exports.reportError = reportError;
|
||||
exports.normalize = normalize;
|
||||
exports.humanSize = humanSize;
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
||||
@ -32644,6 +32662,10 @@ function reportError(err) {
|
||||
_store2['default'].dispatch(action);
|
||||
}
|
||||
|
||||
function normalize(path) {
|
||||
return path.replace(/^\//, '').replace('sdcard/', '');
|
||||
}
|
||||
|
||||
var sizes = {
|
||||
'GB': Math.pow(2, 30),
|
||||
'MB': Math.pow(2, 20),
|
||||
|
@ -36,7 +36,6 @@
|
||||
"grunt-contrib-copy": "^0.8.1",
|
||||
"grunt-contrib-less": "^1.0.1",
|
||||
"grunt-contrib-watch": "^0.6.1",
|
||||
"grunt-fxos": "^0.1.2",
|
||||
"grunt-task-loader": "^0.6.0",
|
||||
"grunt-zip": "^0.17.0",
|
||||
"hammerjs": "^2.0.4",
|
||||
|
Binary file not shown.
@ -1,13 +1,16 @@
|
||||
import { type } from 'utils';
|
||||
import { type, normalize } from 'utils';
|
||||
import { refresh } from 'actions/files-view';
|
||||
import { bind } from 'store';
|
||||
|
||||
let SD_CACHE;
|
||||
export let CACHE = {};
|
||||
|
||||
localStorage.setItem('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;
|
||||
@ -18,6 +21,10 @@ export async function root() {
|
||||
if (ROOT_CACHE) return ROOT_CACHE;
|
||||
|
||||
ROOT_CACHE = shimDirectory(await sdcard().getRoot());
|
||||
Object.defineProperty(ROOT_CACHE, 'name', {
|
||||
value: '',
|
||||
enumerable: true
|
||||
});
|
||||
window.root = ROOT_CACHE;
|
||||
return ROOT_CACHE;
|
||||
}
|
||||
@ -27,17 +34,19 @@ export async function getFile(dir = '/') {
|
||||
|
||||
if (dir === '/' || !dir) return parent;
|
||||
|
||||
return await parent.get(dir);
|
||||
return await parent.get(normalize(dir));
|
||||
}
|
||||
|
||||
export async function children(dir, gatherInfo) {
|
||||
if (CACHE[dir]) return CACHE[dir];
|
||||
|
||||
let parent = shimDirectory(await getFile(dir));
|
||||
if (!parent.path) {
|
||||
parent.path = dir.slice(0, dir.lastIndexOf('/') + 1);
|
||||
}
|
||||
let childs = await parent.getFilesAndDirectories();
|
||||
|
||||
if (gatherInfo) {
|
||||
if (gatherInfo && !window.needsShim) {
|
||||
for (let child of childs) {
|
||||
if (type(child) === 'Directory') {
|
||||
let subchildren;
|
||||
@ -56,6 +65,8 @@ export async function children(dir, gatherInfo) {
|
||||
};
|
||||
}
|
||||
|
||||
CACHE[dir] = childs;
|
||||
|
||||
return childs;
|
||||
}
|
||||
|
||||
@ -97,7 +108,7 @@ export async function remove(file, deep) {
|
||||
}
|
||||
|
||||
export async function move(file, newPath) {
|
||||
let path = (file.path || '').replace(/^\//, ''); // remove starting slash
|
||||
let path = normalize(file.path || '');
|
||||
let oldPath = path + file.name;
|
||||
|
||||
let process = await copy(file, newPath);
|
||||
@ -105,10 +116,10 @@ export async function move(file, newPath) {
|
||||
}
|
||||
|
||||
export async function copy(file, newPath) {
|
||||
let path = (file.path || '').replace(/^\//, ''); // remove starting slash
|
||||
let path = normalize(file.path || '').replace(/^\//, '');
|
||||
let oldPath = path + file.name;
|
||||
|
||||
newPath = newPath.replace(/^\//, '');
|
||||
newPath = normalize(newPath);
|
||||
|
||||
let target = await getFile(oldPath);
|
||||
let parent = await root();
|
||||
@ -120,7 +131,8 @@ export async function copy(file, newPath) {
|
||||
for (let child of childs) {
|
||||
if (type(child) === 'File') {
|
||||
Object.defineProperty(child, 'path', {
|
||||
value: oldPath + '/'
|
||||
value: oldPath + '/',
|
||||
enumerable: true
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ export default class Directory extends Component {
|
||||
|
||||
<i></i>
|
||||
<p>{this.props.name}</p>
|
||||
<span>{this.props.children} items</span>
|
||||
<span>{this.props.children ? this.props.children + ' items' : ''}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
@ -18,6 +18,8 @@ export default class File extends Component {
|
||||
label = <label htmlFor={checkId}></label>;
|
||||
}
|
||||
|
||||
console.log(this.props.type);
|
||||
|
||||
let clickHandler = this.props.selectView ? this.select.bind(this)
|
||||
: this.open.bind(this);
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { CHANGE_DIRECTORY, REFRESH, SETTINGS } from 'actions/types';
|
||||
import { children } from 'api/files';
|
||||
import { children, CACHE } from 'api/files';
|
||||
import store from 'store';
|
||||
import { reportError } from 'utils';
|
||||
import { listFiles } from 'actions/files-view';
|
||||
@ -11,6 +11,10 @@ export default function(state = '', action) {
|
||||
return action.dir;
|
||||
}
|
||||
|
||||
if (action.type === REFRESH) {
|
||||
CACHE[state] = null;
|
||||
}
|
||||
|
||||
if (action.type === REFRESH || action.type === SETTINGS) {
|
||||
changeTo(state);
|
||||
|
||||
|
@ -3,7 +3,7 @@ import store from 'store';
|
||||
import { reportError } from 'utils';
|
||||
import { listFiles } from 'actions/files-view';
|
||||
import { children } from 'api/files';
|
||||
import { type } from 'utils';
|
||||
import { type, normalize } from 'utils';
|
||||
|
||||
export default function(state = '', action) {
|
||||
if (action.type === SEARCH) {
|
||||
@ -36,7 +36,7 @@ function search(keywords) {
|
||||
|
||||
let filtered = files.filter(file => {
|
||||
if (type(file) === 'Directory') {
|
||||
let path = (file.path + file.name).replace(/^\//, '');
|
||||
let path = normalize(file.path + file.name);
|
||||
children(path, true).then(showResults, reportError);
|
||||
}
|
||||
return keys.some(key => {
|
||||
|
@ -31,6 +31,10 @@ export function reportError(err) {
|
||||
store.dispatch(action);
|
||||
}
|
||||
|
||||
export function normalize(path) {
|
||||
return path.replace(/^\//, '').replace('sdcard/', '');
|
||||
}
|
||||
|
||||
const sizes = {
|
||||
'GB': Math.pow(2, 30),
|
||||
'MB': Math.pow(2, 20),
|
||||
|
Loading…
Reference in New Issue
Block a user