@gfean/react-native-bundle-drop 0.1.94 → 0.1.97
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import './bootstrap';
|
|
|
2
2
|
export { getAvailableChannels, checkForUpdate, getInstalledBundleInfo } from './manager/updateCheck';
|
|
3
3
|
export { downloadUpdate } from './manager/downloadAndInstall';
|
|
4
4
|
export { getUpdateState, applyUpdate } from './manager/updateState';
|
|
5
|
-
export { initUpdateManager } from './manager/initUpdateManager';
|
|
5
|
+
export { initUpdateManager, isUpdateFlowActive } from './manager/initUpdateManager';
|
|
6
6
|
export { BundleDropError, isBundleDropError } from './errors';
|
|
7
7
|
export { getCurrentUserProperties, getUserProperties, setUserProperty, setUserPropery, removeUserProperty, resetUserProperties, } from './fs/userProperties';
|
|
8
8
|
export type { BundleInfo } from './bundleInfo';
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useBundleDrop = exports.resetUserProperties = exports.removeUserProperty = exports.setUserPropery = exports.setUserProperty = exports.getUserProperties = exports.getCurrentUserProperties = exports.isBundleDropError = exports.BundleDropError = exports.initUpdateManager = exports.applyUpdate = exports.getUpdateState = exports.downloadUpdate = exports.getInstalledBundleInfo = exports.checkForUpdate = exports.getAvailableChannels = void 0;
|
|
3
|
+
exports.useBundleDrop = exports.resetUserProperties = exports.removeUserProperty = exports.setUserPropery = exports.setUserProperty = exports.getUserProperties = exports.getCurrentUserProperties = exports.isBundleDropError = exports.BundleDropError = exports.isUpdateFlowActive = exports.initUpdateManager = exports.applyUpdate = exports.getUpdateState = exports.downloadUpdate = exports.getInstalledBundleInfo = exports.checkForUpdate = exports.getAvailableChannels = void 0;
|
|
4
4
|
require("./bootstrap");
|
|
5
5
|
var updateCheck_1 = require("./manager/updateCheck");
|
|
6
6
|
Object.defineProperty(exports, "getAvailableChannels", { enumerable: true, get: function () { return updateCheck_1.getAvailableChannels; } });
|
|
@@ -13,6 +13,7 @@ Object.defineProperty(exports, "getUpdateState", { enumerable: true, get: functi
|
|
|
13
13
|
Object.defineProperty(exports, "applyUpdate", { enumerable: true, get: function () { return updateState_1.applyUpdate; } });
|
|
14
14
|
var initUpdateManager_1 = require("./manager/initUpdateManager");
|
|
15
15
|
Object.defineProperty(exports, "initUpdateManager", { enumerable: true, get: function () { return initUpdateManager_1.initUpdateManager; } });
|
|
16
|
+
Object.defineProperty(exports, "isUpdateFlowActive", { enumerable: true, get: function () { return initUpdateManager_1.isUpdateFlowActive; } });
|
|
16
17
|
var errors_1 = require("./errors");
|
|
17
18
|
Object.defineProperty(exports, "BundleDropError", { enumerable: true, get: function () { return errors_1.BundleDropError; } });
|
|
18
19
|
Object.defineProperty(exports, "isBundleDropError", { enumerable: true, get: function () { return errors_1.isBundleDropError; } });
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { UpdatePolicy } from '../types';
|
|
2
|
+
export declare function isUpdateFlowActive(): boolean;
|
|
3
|
+
export declare function acquireUpdateLock(): boolean;
|
|
4
|
+
export declare function releaseUpdateLock(): void;
|
|
2
5
|
export declare function initUpdateManager(opts?: {
|
|
3
6
|
channelName?: string;
|
|
4
7
|
policy?: UpdatePolicy;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isUpdateFlowActive = isUpdateFlowActive;
|
|
4
|
+
exports.acquireUpdateLock = acquireUpdateLock;
|
|
5
|
+
exports.releaseUpdateLock = releaseUpdateLock;
|
|
3
6
|
exports.initUpdateManager = initUpdateManager;
|
|
4
7
|
const downloadAndInstall_1 = require("./downloadAndInstall");
|
|
5
8
|
const updateCheck_1 = require("./updateCheck");
|
|
@@ -9,7 +12,30 @@ const bundleInfo_1 = require("../bundleInfo");
|
|
|
9
12
|
const context_1 = require("../context");
|
|
10
13
|
const bundlePointer_1 = require("../fs/bundlePointer");
|
|
11
14
|
const bundleDropNative_1 = require("../native/bundleDropNative");
|
|
15
|
+
let _updateFlowActive = false;
|
|
16
|
+
function isUpdateFlowActive() {
|
|
17
|
+
return _updateFlowActive;
|
|
18
|
+
}
|
|
19
|
+
function acquireUpdateLock() {
|
|
20
|
+
if (_updateFlowActive)
|
|
21
|
+
return false;
|
|
22
|
+
_updateFlowActive = true;
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
function releaseUpdateLock() {
|
|
26
|
+
_updateFlowActive = false;
|
|
27
|
+
}
|
|
12
28
|
async function initUpdateManager(opts) {
|
|
29
|
+
if (!acquireUpdateLock())
|
|
30
|
+
return;
|
|
31
|
+
try {
|
|
32
|
+
await _initUpdateManagerInner(opts);
|
|
33
|
+
}
|
|
34
|
+
finally {
|
|
35
|
+
releaseUpdateLock();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
async function _initUpdateManagerInner(opts) {
|
|
13
39
|
const policy = opts?.policy || 'manual';
|
|
14
40
|
const channelName = opts?.channelName || context_1.defaultChannel;
|
|
15
41
|
const statusCb = opts?.onStatusUpdate;
|
package/lib/useBundleDrop.js
CHANGED
|
@@ -7,6 +7,7 @@ const updateCheck_1 = require("./manager/updateCheck");
|
|
|
7
7
|
const downloadAndInstall_1 = require("./manager/downloadAndInstall");
|
|
8
8
|
const updateState_1 = require("./manager/updateState");
|
|
9
9
|
const rollbackState_1 = require("./manager/rollbackState");
|
|
10
|
+
const initUpdateManager_1 = require("./manager/initUpdateManager");
|
|
10
11
|
function useBundleDrop(options) {
|
|
11
12
|
const channelName = options?.channelName || context_1.defaultChannel;
|
|
12
13
|
const [status, setStatus] = (0, react_1.useState)('Click the button to check for updates');
|
|
@@ -22,6 +23,9 @@ function useBundleDrop(options) {
|
|
|
22
23
|
setHasBundle(state.hasBundle);
|
|
23
24
|
}, []);
|
|
24
25
|
const withBusy = (0, react_1.useCallback)(async (fn) => {
|
|
26
|
+
if (!(0, initUpdateManager_1.acquireUpdateLock)()) {
|
|
27
|
+
throw new Error('Another update flow is already in progress');
|
|
28
|
+
}
|
|
25
29
|
setIsBusy(true);
|
|
26
30
|
try {
|
|
27
31
|
const result = await fn();
|
|
@@ -30,6 +34,7 @@ function useBundleDrop(options) {
|
|
|
30
34
|
}
|
|
31
35
|
finally {
|
|
32
36
|
setIsBusy(false);
|
|
37
|
+
(0, initUpdateManager_1.releaseUpdateLock)();
|
|
33
38
|
}
|
|
34
39
|
}, [refresh]);
|
|
35
40
|
const checkLatest = (0, react_1.useCallback)(async () => {
|
|
@@ -121,7 +126,9 @@ function useBundleDrop(options) {
|
|
|
121
126
|
}, [setAvailableChannels, setStatus]);
|
|
122
127
|
(0, react_1.useEffect)(() => {
|
|
123
128
|
refresh();
|
|
124
|
-
(0,
|
|
129
|
+
if (!(0, initUpdateManager_1.isUpdateFlowActive)()) {
|
|
130
|
+
(0, rollbackState_1.commitActiveBundle)();
|
|
131
|
+
}
|
|
125
132
|
}, [refresh]);
|
|
126
133
|
return {
|
|
127
134
|
status,
|