taro-hooks
Version:
为 Taro 而设计的 Hooks Library
82 lines (81 loc) • 2.21 kB
JavaScript
function _await(value, then, direct) {
if (direct) {
return then ? then(value) : value;
}
if (!value || !value.then) {
value = Promise.resolve(value);
}
return then ? value.then(then) : value;
}
function _catch(body, recover) {
try {
var result = body();
} catch (e) {
return recover(e);
}
if (result && result.then) {
return result.then(void 0, recover);
}
return result;
}
function _invoke(body, then) {
var result = body();
if (result && result.then) {
return result.then(then);
}
return then(result);
}
function _async(f) {
return function () {
for (var args = [], i = 0; i < arguments.length; i++) {
args[i] = arguments[i];
}
try {
return Promise.resolve(f.apply(this, args));
} catch (e) {
return Promise.reject(e);
}
};
}
Object.defineProperty(exports, "__esModule", {
value: true
});
var shared_1 = require("@taro-hooks/shared");
var spaceInfo_type_1 = require("./spaceInfo.type");
var getStorageSpaceInfo = _async(function () {
var _exit = false;
return _catch(function () {
return _invoke(function () {
if (navigator && 'storage' in navigator && 'estimate' in navigator.storage) {
return _catch(function () {
return _await(navigator.storage.estimate(), function (_ref) {
var _ref$usage = _ref.usage,
usage = _ref$usage === void 0 ? 0 : _ref$usage,
_ref$quota = _ref.quota,
quota = _ref$quota === void 0 ? 0 : _ref$quota;
var _currentSize$limitSiz = {
currentSize: usage,
limitSize: quota
};
_exit = true;
return _currentSize$limitSiz;
});
}, function (e) {
(0, shared_1.logError)('estimate failed', e);
var _currentSize$limitSiz2 = {
currentSize: Storage.length,
limitSize: 0
};
_exit = true;
return _currentSize$limitSiz2;
});
}
}, function (_result) {
return _exit ? _result : spaceInfo_type_1.INIT;
});
}, function () {
return spaceInfo_type_1.INIT;
});
});
exports["default"] = getStorageSpaceInfo;
;