12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = void 0;
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
- var _CoreManager = _interopRequireDefault(require("./CoreManager"));
- var _Storage = _interopRequireDefault(require("./Storage"));
- var _ParseInstallation = _interopRequireDefault(require("./ParseInstallation"));
- var _uuid = _interopRequireDefault(require("./uuid"));
- var CURRENT_INSTALLATION_KEY = 'currentInstallation';
- var CURRENT_INSTALLATION_ID_KEY = 'currentInstallationId';
- var iidCache = null;
- var currentInstallationCache = null;
- var currentInstallationCacheMatchesDisk = false;
- var InstallationController = {
- updateInstallationOnDisk: function () {
- var _updateInstallationOnDisk = (0, _asyncToGenerator2.default)(function* (installation) {
- var path = _Storage.default.generatePath(CURRENT_INSTALLATION_KEY);
- yield _Storage.default.setItemAsync(path, JSON.stringify(installation.toJSON()));
- this._setCurrentInstallationCache(installation);
- });
- function updateInstallationOnDisk() {
- return _updateInstallationOnDisk.apply(this, arguments);
- }
- return updateInstallationOnDisk;
- }(),
- currentInstallationId: function () {
- var _currentInstallationId = (0, _asyncToGenerator2.default)(function* () {
- if (typeof iidCache === 'string') {
- return iidCache;
- }
- var path = _Storage.default.generatePath(CURRENT_INSTALLATION_ID_KEY);
- var iid = yield _Storage.default.getItemAsync(path);
- if (!iid) {
- iid = (0, _uuid.default)();
- return _Storage.default.setItemAsync(path, iid).then(function () {
- iidCache = iid;
- return iid;
- });
- }
- iidCache = iid;
- return iid;
- });
- function currentInstallationId() {
- return _currentInstallationId.apply(this, arguments);
- }
- return currentInstallationId;
- }(),
- currentInstallation: function () {
- var _currentInstallation = (0, _asyncToGenerator2.default)(function* () {
- if (currentInstallationCache) {
- return currentInstallationCache;
- }
- if (currentInstallationCacheMatchesDisk) {
- return null;
- }
- var path = _Storage.default.generatePath(CURRENT_INSTALLATION_KEY);
- var installationData = yield _Storage.default.getItemAsync(path);
- currentInstallationCacheMatchesDisk = true;
- if (installationData) {
- installationData = JSON.parse(installationData);
- installationData.className = '_Installation';
- var current = _ParseInstallation.default.fromJSON(installationData);
- currentInstallationCache = current;
- return current;
- }
- var installationId = yield this.currentInstallationId();
- var installation = new _ParseInstallation.default();
- installation.set('deviceType', _ParseInstallation.default.DEVICE_TYPES.WEB);
- installation.set('installationId', installationId);
- installation.set('parseVersion', _CoreManager.default.get('VERSION'));
- currentInstallationCache = installation;
- yield _Storage.default.setItemAsync(path, JSON.stringify(installation.toJSON()));
- return installation;
- });
- function currentInstallation() {
- return _currentInstallation.apply(this, arguments);
- }
- return currentInstallation;
- }(),
- _clearCache: function () {
- iidCache = null;
- currentInstallationCache = null;
- currentInstallationCacheMatchesDisk = false;
- },
- _setInstallationIdCache: function (iid) {
- iidCache = iid;
- },
- _setCurrentInstallationCache: function (installation) {
- var matchesDisk = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
- currentInstallationCache = installation;
- currentInstallationCacheMatchesDisk = matchesDisk;
- }
- };
- module.exports = InstallationController;
- var _default = exports.default = InstallationController;
|