@zero-bits/react-native-hot-update 1.0.0
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/README.md +159 -0
- package/es/constants.d.ts +20 -0
- package/es/constants.js +20 -0
- package/es/index.d.ts +4 -0
- package/es/index.js +3 -0
- package/es/initialize.d.ts +14 -0
- package/es/initialize.js +32 -0
- package/es/updateProvider.d.ts +75 -0
- package/es/updateProvider.js +74 -0
- package/es/updateState.d.ts +25 -0
- package/es/updateState.js +166 -0
- package/es/usePushyUpdate.d.ts +17 -0
- package/es/usePushyUpdate.js +108 -0
- package/es/widget/animated.overlay.d.ts +12 -0
- package/es/widget/animated.overlay.js +96 -0
- package/es/widget/content.widget.d.ts +5 -0
- package/es/widget/content.widget.js +55 -0
- package/es/widget/description.widget.d.ts +5 -0
- package/es/widget/description.widget.js +33 -0
- package/es/widget/download.modal.widget.d.ts +5 -0
- package/es/widget/download.modal.widget.js +130 -0
- package/es/widget/footer.widget.d.ts +5 -0
- package/es/widget/footer.widget.js +153 -0
- package/es/widget/title.widget.d.ts +5 -0
- package/es/widget/title.widget.js +27 -0
- package/es/widget/update.modal.widget.d.ts +5 -0
- package/es/widget/update.modal.widget.js +50 -0
- package/lib/constants.d.ts +20 -0
- package/lib/constants.js +26 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +36 -0
- package/lib/initialize.d.ts +14 -0
- package/lib/initialize.js +38 -0
- package/lib/updateProvider.d.ts +75 -0
- package/lib/updateProvider.js +83 -0
- package/lib/updateState.d.ts +25 -0
- package/lib/updateState.js +176 -0
- package/lib/usePushyUpdate.d.ts +17 -0
- package/lib/usePushyUpdate.js +114 -0
- package/lib/widget/animated.overlay.d.ts +12 -0
- package/lib/widget/animated.overlay.js +104 -0
- package/lib/widget/content.widget.d.ts +5 -0
- package/lib/widget/content.widget.js +63 -0
- package/lib/widget/description.widget.d.ts +5 -0
- package/lib/widget/description.widget.js +41 -0
- package/lib/widget/download.modal.widget.d.ts +5 -0
- package/lib/widget/download.modal.widget.js +138 -0
- package/lib/widget/footer.widget.d.ts +5 -0
- package/lib/widget/footer.widget.js +161 -0
- package/lib/widget/title.widget.d.ts +5 -0
- package/lib/widget/title.widget.js +35 -0
- package/lib/widget/update.modal.widget.d.ts +5 -0
- package/lib/widget/update.modal.widget.js +59 -0
- package/package.json +30 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React, { useContext } from 'react';
|
|
2
|
+
import { View, Text, StyleSheet } from 'react-native';
|
|
3
|
+
import { HotUpdateContext } from "../updateProvider";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @description 更新标题原子组件
|
|
7
|
+
* @returns 标题展示原子组件
|
|
8
|
+
*/
|
|
9
|
+
export default function TitleWidget() {
|
|
10
|
+
var config = useContext(HotUpdateContext);
|
|
11
|
+
var locale = config.localeText;
|
|
12
|
+
return /*#__PURE__*/React.createElement(View, {
|
|
13
|
+
style: Style.container
|
|
14
|
+
}, /*#__PURE__*/React.createElement(Text, {
|
|
15
|
+
style: Style.title
|
|
16
|
+
}, locale.updateTitle));
|
|
17
|
+
}
|
|
18
|
+
var Style = StyleSheet.create({
|
|
19
|
+
container: {
|
|
20
|
+
alignItems: 'center',
|
|
21
|
+
justifyContent: 'center'
|
|
22
|
+
},
|
|
23
|
+
title: {
|
|
24
|
+
fontSize: 18,
|
|
25
|
+
fontWeight: 'bold'
|
|
26
|
+
}
|
|
27
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import React, { useContext } from 'react';
|
|
2
|
+
import { View, StyleSheet } from 'react-native';
|
|
3
|
+
import { useUpdate } from 'react-native-update';
|
|
4
|
+
import TitleWidget from "./title.widget";
|
|
5
|
+
import DescriptWidget from "./description.widget";
|
|
6
|
+
import ContentWidget from "./content.widget";
|
|
7
|
+
import FooterWidget from "./footer.widget";
|
|
8
|
+
import { HotUpdateContext } from "../updateProvider";
|
|
9
|
+
import { useUpdateState } from "../updateState";
|
|
10
|
+
import AnimatedOverlay from "./animated.overlay";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @description 更新弹窗组件
|
|
14
|
+
* @returns 更新弹窗组件
|
|
15
|
+
*/
|
|
16
|
+
export default function UpdateModalWidget() {
|
|
17
|
+
var config = useContext(HotUpdateContext);
|
|
18
|
+
var _useUpdate = useUpdate(),
|
|
19
|
+
updateInfo = _useUpdate.updateInfo;
|
|
20
|
+
var _useUpdateState = useUpdateState(),
|
|
21
|
+
isUpdateVisible = _useUpdateState.isUpdateVisible,
|
|
22
|
+
hideUpdateModal = _useUpdateState.hideUpdateModal,
|
|
23
|
+
startDownloadFlow = _useUpdateState.startDownloadFlow;
|
|
24
|
+
var content = null;
|
|
25
|
+
if (config.renderUpdateModal) {
|
|
26
|
+
content = config.renderUpdateModal(updateInfo, {
|
|
27
|
+
hideModal: hideUpdateModal,
|
|
28
|
+
doUpdate: startDownloadFlow
|
|
29
|
+
});
|
|
30
|
+
} else {
|
|
31
|
+
content = /*#__PURE__*/React.createElement(View, {
|
|
32
|
+
style: Style.content
|
|
33
|
+
}, /*#__PURE__*/React.createElement(TitleWidget, null), /*#__PURE__*/React.createElement(DescriptWidget, null), /*#__PURE__*/React.createElement(ContentWidget, null), /*#__PURE__*/React.createElement(FooterWidget, null));
|
|
34
|
+
}
|
|
35
|
+
return /*#__PURE__*/React.createElement(AnimatedOverlay, {
|
|
36
|
+
visible: isUpdateVisible,
|
|
37
|
+
onAnimationComplete: function onAnimationComplete() {}
|
|
38
|
+
}, content);
|
|
39
|
+
}
|
|
40
|
+
var Style = StyleSheet.create({
|
|
41
|
+
content: {
|
|
42
|
+
backgroundColor: 'white',
|
|
43
|
+
marginHorizontal: 20,
|
|
44
|
+
borderRadius: 8,
|
|
45
|
+
paddingVertical: 20,
|
|
46
|
+
flexDirection: 'column',
|
|
47
|
+
width: '90%',
|
|
48
|
+
maxWidth: 400
|
|
49
|
+
}
|
|
50
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare const defaultLocaleText: {
|
|
2
|
+
updateTitle: string;
|
|
3
|
+
downloadingTitle: string;
|
|
4
|
+
downloadedBytes: string;
|
|
5
|
+
totalBytes: string;
|
|
6
|
+
updateExpired: string;
|
|
7
|
+
updateUpToDate: string;
|
|
8
|
+
updateAvailable: string;
|
|
9
|
+
btnUpdateLater: string;
|
|
10
|
+
btnUpdateNow: string;
|
|
11
|
+
btnGotIt: string;
|
|
12
|
+
btnAppStore: string;
|
|
13
|
+
btnDownload: string;
|
|
14
|
+
alertDownloadComplete: string;
|
|
15
|
+
alertDownloadCompleteDesc: string;
|
|
16
|
+
alertMissingAppId: string;
|
|
17
|
+
alertMissingDownloadUrl: string;
|
|
18
|
+
alertCantOpenDownloadUrl: string;
|
|
19
|
+
alertDownloadUrlFailed: string;
|
|
20
|
+
};
|
package/lib/constants.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.defaultLocaleText = void 0;
|
|
7
|
+
var defaultLocaleText = exports.defaultLocaleText = {
|
|
8
|
+
updateTitle: '应用更新提示',
|
|
9
|
+
downloadingTitle: '正在下载资源,请稍后...',
|
|
10
|
+
downloadedBytes: '已下载:',
|
|
11
|
+
totalBytes: '总大小:',
|
|
12
|
+
updateExpired: '应用有新的安装包,请下载安装包或前往应用市场进行更新,或联系运营人员进行下载更新。',
|
|
13
|
+
updateUpToDate: '当前应用版本已是最新版本,无需进行更新!如需下载新的安装包请前往应用市场或自行下载安装',
|
|
14
|
+
updateAvailable: '当前有需要更新的应用版本',
|
|
15
|
+
btnUpdateLater: '稍后更新',
|
|
16
|
+
btnUpdateNow: '立即更新',
|
|
17
|
+
btnGotIt: '我知道了',
|
|
18
|
+
btnAppStore: '应用市场',
|
|
19
|
+
btnDownload: '下载更新',
|
|
20
|
+
alertDownloadComplete: '系统提示',
|
|
21
|
+
alertDownloadCompleteDesc: '资源文件下载完成,是否立即更新?',
|
|
22
|
+
alertMissingAppId: '未配置苹果应用商店ID',
|
|
23
|
+
alertMissingDownloadUrl: '未配置应用下载地址,请先进行配置!',
|
|
24
|
+
alertCantOpenDownloadUrl: '无法打开应用下载地址,请前往应用市场更新!',
|
|
25
|
+
alertDownloadUrlFailed: '应用下载地址打开失败,请前往应用市场更新!'
|
|
26
|
+
};
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
Object.defineProperty(exports, "HotUpdateContext", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function get() {
|
|
10
|
+
return _updateProvider.HotUpdateContext;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(exports, "UpdateClient", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function get() {
|
|
16
|
+
return _initialize.default;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports, "UpdateProvider", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function get() {
|
|
22
|
+
return _updateProvider.default;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
Object.defineProperty(exports, "usePushyUpdate", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function get() {
|
|
28
|
+
return _usePushyUpdate.default;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
var _initialize = _interopRequireDefault(require("./initialize"));
|
|
32
|
+
var _usePushyUpdate = _interopRequireDefault(require("./usePushyUpdate"));
|
|
33
|
+
var _updateProvider = _interopRequireWildcard(require("./updateProvider"));
|
|
34
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
35
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
36
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Pushy } from 'react-native-update';
|
|
2
|
+
import { HotUpdateConfig } from './updateProvider';
|
|
3
|
+
/**
|
|
4
|
+
* @description 热更新初始化配置
|
|
5
|
+
* @param config 热更新配置对象
|
|
6
|
+
* - appKey: 您的App的Key,请在Pushy后台获取
|
|
7
|
+
* - debug: 是否开启调试模式
|
|
8
|
+
* - checkStrategy: 检查更新策略
|
|
9
|
+
* - updateStrategy: 更新策略
|
|
10
|
+
* - autoMarkSuccess: 是否自动标记更新成功
|
|
11
|
+
* - notifyInterval: 同一版本最短通知间隔(ms)
|
|
12
|
+
* @returns 返回更新类实例
|
|
13
|
+
*/
|
|
14
|
+
export default function initialize(config: HotUpdateConfig): Pushy;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = initialize;
|
|
7
|
+
var _reactNativeUpdate = require("react-native-update");
|
|
8
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
9
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
10
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
11
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
12
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
13
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
14
|
+
/**
|
|
15
|
+
* @description 热更新初始化配置
|
|
16
|
+
* @param config 热更新配置对象
|
|
17
|
+
* - appKey: 您的App的Key,请在Pushy后台获取
|
|
18
|
+
* - debug: 是否开启调试模式
|
|
19
|
+
* - checkStrategy: 检查更新策略
|
|
20
|
+
* - updateStrategy: 更新策略
|
|
21
|
+
* - autoMarkSuccess: 是否自动标记更新成功
|
|
22
|
+
* - notifyInterval: 同一版本最短通知间隔(ms)
|
|
23
|
+
* @returns 返回更新类实例
|
|
24
|
+
*/
|
|
25
|
+
function initialize(config) {
|
|
26
|
+
var _config$checkStrategy, _config$updateStrateg;
|
|
27
|
+
if (!config.appKey) return;
|
|
28
|
+
return new _reactNativeUpdate.Pushy(_objectSpread(_objectSpread({
|
|
29
|
+
appKey: config.appKey,
|
|
30
|
+
debug: __DEV__,
|
|
31
|
+
checkStrategy: (_config$checkStrategy = config.checkStrategy) !== null && _config$checkStrategy !== void 0 ? _config$checkStrategy : null,
|
|
32
|
+
updateStrategy: (_config$updateStrateg = config.updateStrategy) !== null && _config$updateStrateg !== void 0 ? _config$updateStrateg : null
|
|
33
|
+
}, config.autoMarkSuccess !== undefined && {
|
|
34
|
+
autoMarkSuccess: config.autoMarkSuccess
|
|
35
|
+
}), config.notifyInterval !== undefined && {
|
|
36
|
+
notifyInterval: config.notifyInterval
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { defaultLocaleText } from './constants';
|
|
3
|
+
export type LocaleText = typeof defaultLocaleText;
|
|
4
|
+
/**
|
|
5
|
+
* @description 更新信息类型
|
|
6
|
+
* - upToDate: 是否已是最新版本
|
|
7
|
+
* - update: 是否有更新
|
|
8
|
+
* - expired: 版本是否已过期
|
|
9
|
+
* - name: 版本名称
|
|
10
|
+
* - hash: 版本哈希
|
|
11
|
+
* - description: 版本描述
|
|
12
|
+
* - metaInfo: 版本元信息
|
|
13
|
+
* - downloadUrl: 版本下载地址
|
|
14
|
+
*/
|
|
15
|
+
export interface UpdateInfo {
|
|
16
|
+
upToDate?: boolean;
|
|
17
|
+
update?: boolean;
|
|
18
|
+
expired?: boolean;
|
|
19
|
+
name?: string;
|
|
20
|
+
hash?: string;
|
|
21
|
+
description?: string;
|
|
22
|
+
metaInfo?: string;
|
|
23
|
+
downloadUrl?: string;
|
|
24
|
+
[key: string]: any;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* @description 热更新配置类型
|
|
28
|
+
* - appKey: 您的App的Key,请在Pushy后台获取
|
|
29
|
+
* - iosAppId: 苹果商店ID
|
|
30
|
+
* - themeColor: 主题颜色
|
|
31
|
+
* - checkStrategy: 检查更新策略
|
|
32
|
+
* - updateStrategy: 更新策略
|
|
33
|
+
* - autoMarkSuccess: 是否自动标记更新成功,默认 true;设为 false 时需用户手动调用 markSuccess()
|
|
34
|
+
* - notifyInterval: 同一版本最短通知间隔(ms),默认 300000 (5分钟)
|
|
35
|
+
* - localeText: 国际化/自定义文案配置
|
|
36
|
+
* - renderUpdateModal: 自定义更新弹窗渲染
|
|
37
|
+
* - renderDownloadModal: 自定义下载弹窗渲染
|
|
38
|
+
*/
|
|
39
|
+
export interface HotUpdateConfig {
|
|
40
|
+
appKey: string;
|
|
41
|
+
iosAppId?: string;
|
|
42
|
+
themeColor?: string;
|
|
43
|
+
checkStrategy?: 'onAppStart' | 'both' | null;
|
|
44
|
+
updateStrategy?: 'alertUpdateAndIgnoreError' | 'silentAndNow' | null;
|
|
45
|
+
autoMarkSuccess?: boolean;
|
|
46
|
+
notifyInterval?: number;
|
|
47
|
+
localeText?: Partial<LocaleText>;
|
|
48
|
+
renderUpdateModal?: (updateInfo: UpdateInfo, handlers: {
|
|
49
|
+
hideModal: () => void;
|
|
50
|
+
doUpdate: () => void;
|
|
51
|
+
}) => React.ReactElement | null;
|
|
52
|
+
renderDownloadModal?: (progress: {
|
|
53
|
+
received: number;
|
|
54
|
+
total: number;
|
|
55
|
+
}, handlers: {
|
|
56
|
+
hideModal: () => void;
|
|
57
|
+
}) => React.ReactElement | null;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* @description 热更新提供者组件属性类型
|
|
61
|
+
*/
|
|
62
|
+
interface IProps extends HotUpdateConfig {
|
|
63
|
+
children?: React.ReactNode;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* @description 热更新上下文类型
|
|
67
|
+
*/
|
|
68
|
+
export declare const HotUpdateContext: any;
|
|
69
|
+
/**
|
|
70
|
+
* @description 热更新提供者组件,每个业务的入口页引入即可
|
|
71
|
+
* @param props 包含appKey, iosAppId, themeColor等配置
|
|
72
|
+
* @returns 热更新提供者组件
|
|
73
|
+
*/
|
|
74
|
+
export default function UpdateProvider({ children, ...config }: IProps): any;
|
|
75
|
+
export {};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.HotUpdateContext = void 0;
|
|
8
|
+
exports.default = UpdateProvider;
|
|
9
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _reactNativeUpdate = require("react-native-update");
|
|
11
|
+
var _initialize = _interopRequireDefault(require("./initialize"));
|
|
12
|
+
var _constants = require("./constants");
|
|
13
|
+
var _updateState = require("./updateState");
|
|
14
|
+
var _excluded = ["children"];
|
|
15
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
17
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
18
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
19
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
20
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
21
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
22
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
23
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
24
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
25
|
+
/**
|
|
26
|
+
* @description 更新信息类型
|
|
27
|
+
* - upToDate: 是否已是最新版本
|
|
28
|
+
* - update: 是否有更新
|
|
29
|
+
* - expired: 版本是否已过期
|
|
30
|
+
* - name: 版本名称
|
|
31
|
+
* - hash: 版本哈希
|
|
32
|
+
* - description: 版本描述
|
|
33
|
+
* - metaInfo: 版本元信息
|
|
34
|
+
* - downloadUrl: 版本下载地址
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @description 热更新配置类型
|
|
39
|
+
* - appKey: 您的App的Key,请在Pushy后台获取
|
|
40
|
+
* - iosAppId: 苹果商店ID
|
|
41
|
+
* - themeColor: 主题颜色
|
|
42
|
+
* - checkStrategy: 检查更新策略
|
|
43
|
+
* - updateStrategy: 更新策略
|
|
44
|
+
* - autoMarkSuccess: 是否自动标记更新成功,默认 true;设为 false 时需用户手动调用 markSuccess()
|
|
45
|
+
* - notifyInterval: 同一版本最短通知间隔(ms),默认 300000 (5分钟)
|
|
46
|
+
* - localeText: 国际化/自定义文案配置
|
|
47
|
+
* - renderUpdateModal: 自定义更新弹窗渲染
|
|
48
|
+
* - renderDownloadModal: 自定义下载弹窗渲染
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @description 热更新提供者组件属性类型
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @description 热更新上下文类型
|
|
57
|
+
*/
|
|
58
|
+
var HotUpdateContext = exports.HotUpdateContext = /*#__PURE__*/(0, _react.createContext)({});
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @description 热更新提供者组件,每个业务的入口页引入即可
|
|
62
|
+
* @param props 包含appKey, iosAppId, themeColor等配置
|
|
63
|
+
* @returns 热更新提供者组件
|
|
64
|
+
*/
|
|
65
|
+
function UpdateProvider(_ref) {
|
|
66
|
+
var children = _ref.children,
|
|
67
|
+
config = _objectWithoutProperties(_ref, _excluded);
|
|
68
|
+
if (!config.appKey) return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, children);
|
|
69
|
+
var client = (0, _react.useMemo)(function () {
|
|
70
|
+
return (0, _initialize.default)(config);
|
|
71
|
+
}, [config.appKey]);
|
|
72
|
+
var finalConfig = (0, _react.useMemo)(function () {
|
|
73
|
+
return _objectSpread(_objectSpread({}, config), {}, {
|
|
74
|
+
localeText: _objectSpread(_objectSpread({}, _constants.defaultLocaleText), config.localeText)
|
|
75
|
+
});
|
|
76
|
+
}, [config.appKey, config.iosAppId, config.themeColor, config.localeText, config.renderUpdateModal, config.renderDownloadModal]);
|
|
77
|
+
return /*#__PURE__*/_react.default.createElement(HotUpdateContext.Provider, {
|
|
78
|
+
value: finalConfig
|
|
79
|
+
}, /*#__PURE__*/_react.default.createElement(_reactNativeUpdate.UpdateProvider, {
|
|
80
|
+
client: client,
|
|
81
|
+
children: /*#__PURE__*/_react.default.createElement(_updateState.UpdateStateProvider, null, children)
|
|
82
|
+
}));
|
|
83
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* @description 更新状态上下文类型
|
|
4
|
+
* - isUpdateVisible: 更新弹窗是否可见
|
|
5
|
+
* - isDownloadVisible: 下载弹窗是否可见
|
|
6
|
+
* - showUpdateModal: 显示更新弹窗
|
|
7
|
+
* - hideUpdateModal: 隐藏更新弹窗
|
|
8
|
+
* - showDownloadModal: 显示下载弹窗
|
|
9
|
+
* - hideDownloadModal: 隐藏下载弹窗
|
|
10
|
+
* - startDownloadFlow: 开始下载更新
|
|
11
|
+
*/
|
|
12
|
+
export declare const UpdateStateContext: any;
|
|
13
|
+
/**
|
|
14
|
+
* @description 更新状态钩子
|
|
15
|
+
* @returns 更新状态钩子
|
|
16
|
+
*/
|
|
17
|
+
export declare function useUpdateState(): any;
|
|
18
|
+
/**
|
|
19
|
+
* @description 更新状态提供者
|
|
20
|
+
* @param children
|
|
21
|
+
* @returns 更新状态提供者
|
|
22
|
+
*/
|
|
23
|
+
export declare function UpdateStateProvider({ children }: {
|
|
24
|
+
children?: React.ReactNode;
|
|
25
|
+
}): any;
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.UpdateStateContext = void 0;
|
|
8
|
+
exports.UpdateStateProvider = UpdateStateProvider;
|
|
9
|
+
exports.useUpdateState = useUpdateState;
|
|
10
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
11
|
+
var _reactNative = require("react-native");
|
|
12
|
+
var _reactNativeUpdate = require("react-native-update");
|
|
13
|
+
var _updateProvider = require("./updateProvider");
|
|
14
|
+
var _updateModal = _interopRequireDefault(require("./widget/update.modal.widget"));
|
|
15
|
+
var _downloadModal = _interopRequireDefault(require("./widget/download.modal.widget"));
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
18
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
19
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
20
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
21
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
22
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
23
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
24
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
25
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
26
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
27
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
28
|
+
/**
|
|
29
|
+
* @description 更新状态上下文类型
|
|
30
|
+
* - isUpdateVisible: 更新弹窗是否可见
|
|
31
|
+
* - isDownloadVisible: 下载弹窗是否可见
|
|
32
|
+
* - showUpdateModal: 显示更新弹窗
|
|
33
|
+
* - hideUpdateModal: 隐藏更新弹窗
|
|
34
|
+
* - showDownloadModal: 显示下载弹窗
|
|
35
|
+
* - hideDownloadModal: 隐藏下载弹窗
|
|
36
|
+
* - startDownloadFlow: 开始下载更新
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @description 更新状态上下文类型
|
|
41
|
+
* - isUpdateVisible: 更新弹窗是否可见
|
|
42
|
+
* - isDownloadVisible: 下载弹窗是否可见
|
|
43
|
+
* - showUpdateModal: 显示更新弹窗
|
|
44
|
+
* - hideUpdateModal: 隐藏更新弹窗
|
|
45
|
+
* - showDownloadModal: 显示下载弹窗
|
|
46
|
+
* - hideDownloadModal: 隐藏下载弹窗
|
|
47
|
+
* - startDownloadFlow: 开始下载更新
|
|
48
|
+
*/
|
|
49
|
+
var UpdateStateContext = exports.UpdateStateContext = /*#__PURE__*/(0, _react.createContext)(null);
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @description 更新状态钩子
|
|
53
|
+
* @returns 更新状态钩子
|
|
54
|
+
*/
|
|
55
|
+
function useUpdateState() {
|
|
56
|
+
var context = (0, _react.useContext)(UpdateStateContext);
|
|
57
|
+
if (!context) {
|
|
58
|
+
throw new Error('useUpdateState must be used within an UpdateStateProvider');
|
|
59
|
+
}
|
|
60
|
+
return context;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @description 更新状态提供者
|
|
65
|
+
* @param children
|
|
66
|
+
* @returns 更新状态提供者
|
|
67
|
+
*/
|
|
68
|
+
function UpdateStateProvider(_ref) {
|
|
69
|
+
var children = _ref.children;
|
|
70
|
+
var _useUpdate = (0, _reactNativeUpdate.useUpdate)(),
|
|
71
|
+
downloadUpdate = _useUpdate.downloadUpdate,
|
|
72
|
+
switchVersion = _useUpdate.switchVersion,
|
|
73
|
+
switchVersionLater = _useUpdate.switchVersionLater,
|
|
74
|
+
updateInfo = _useUpdate.updateInfo;
|
|
75
|
+
var config = (0, _react.useContext)(_updateProvider.HotUpdateContext);
|
|
76
|
+
var locale = config.localeText || {};
|
|
77
|
+
var isForceUpdate = (0, _react.useMemo)(function () {
|
|
78
|
+
try {
|
|
79
|
+
if (!(updateInfo !== null && updateInfo !== void 0 && updateInfo.metaInfo)) return false;
|
|
80
|
+
var meta = JSON.parse(updateInfo.metaInfo);
|
|
81
|
+
return meta.force === true || meta.forceUpdate === true;
|
|
82
|
+
} catch (_unused) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
}, [updateInfo === null || updateInfo === void 0 ? void 0 : updateInfo.metaInfo]);
|
|
86
|
+
var _useState = (0, _react.useState)(false),
|
|
87
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
88
|
+
isUpdateVisible = _useState2[0],
|
|
89
|
+
setIsUpdateVisible = _useState2[1];
|
|
90
|
+
var _useState3 = (0, _react.useState)(false),
|
|
91
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
92
|
+
isDownloadVisible = _useState4[0],
|
|
93
|
+
setIsDownloadVisible = _useState4[1];
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* @description 开始下载更新
|
|
97
|
+
* @returns Promise<void>
|
|
98
|
+
*/
|
|
99
|
+
var startDownloadFlow = (0, _react.useCallback)( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
100
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
101
|
+
while (1) switch (_context.prev = _context.next) {
|
|
102
|
+
case 0:
|
|
103
|
+
setIsUpdateVisible(false);
|
|
104
|
+
setIsDownloadVisible(true);
|
|
105
|
+
_context.prev = 2;
|
|
106
|
+
_context.next = 5;
|
|
107
|
+
return downloadUpdate();
|
|
108
|
+
case 5:
|
|
109
|
+
setIsDownloadVisible(false);
|
|
110
|
+
_reactNative.Alert.alert(locale.alertDownloadComplete || '系统提示', locale.alertDownloadCompleteDesc || '资源文件下载完成,是否立即更新?', isForceUpdate ? [{
|
|
111
|
+
text: locale.btnUpdateNow || '立即更新',
|
|
112
|
+
onPress: switchVersion
|
|
113
|
+
}] : [{
|
|
114
|
+
text: locale.btnUpdateLater || '稍后更新',
|
|
115
|
+
onPress: switchVersionLater
|
|
116
|
+
}, {
|
|
117
|
+
text: locale.btnUpdateNow || '立即更新',
|
|
118
|
+
onPress: switchVersion
|
|
119
|
+
}], {
|
|
120
|
+
cancelable: !isForceUpdate
|
|
121
|
+
});
|
|
122
|
+
_context.next = 14;
|
|
123
|
+
break;
|
|
124
|
+
case 9:
|
|
125
|
+
_context.prev = 9;
|
|
126
|
+
_context.t0 = _context["catch"](2);
|
|
127
|
+
setIsDownloadVisible(false);
|
|
128
|
+
if (isForceUpdate) {
|
|
129
|
+
setIsUpdateVisible(true);
|
|
130
|
+
}
|
|
131
|
+
_reactNative.Alert.alert('提示', locale.alertDownloadUrlFailed || '下载失败,请检查网络或稍后重试');
|
|
132
|
+
case 14:
|
|
133
|
+
case "end":
|
|
134
|
+
return _context.stop();
|
|
135
|
+
}
|
|
136
|
+
}, _callee, null, [[2, 9]]);
|
|
137
|
+
})), [downloadUpdate, switchVersion, switchVersionLater, locale, isForceUpdate]);
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* @description 更新状态提供者
|
|
141
|
+
* @returns 更新状态提供者
|
|
142
|
+
*/
|
|
143
|
+
var value = (0, _react.useMemo)(function () {
|
|
144
|
+
return {
|
|
145
|
+
isUpdateVisible: isUpdateVisible,
|
|
146
|
+
isDownloadVisible: isDownloadVisible,
|
|
147
|
+
showUpdateModal: function showUpdateModal() {
|
|
148
|
+
return setIsUpdateVisible(true);
|
|
149
|
+
},
|
|
150
|
+
hideUpdateModal: function hideUpdateModal() {
|
|
151
|
+
return setIsUpdateVisible(false);
|
|
152
|
+
},
|
|
153
|
+
showDownloadModal: function showDownloadModal() {
|
|
154
|
+
return setIsDownloadVisible(true);
|
|
155
|
+
},
|
|
156
|
+
hideDownloadModal: function hideDownloadModal() {
|
|
157
|
+
return setIsDownloadVisible(false);
|
|
158
|
+
},
|
|
159
|
+
startDownloadFlow: startDownloadFlow
|
|
160
|
+
};
|
|
161
|
+
}, [isUpdateVisible, isDownloadVisible, startDownloadFlow]);
|
|
162
|
+
return /*#__PURE__*/_react.default.createElement(UpdateStateContext.Provider, {
|
|
163
|
+
value: value
|
|
164
|
+
}, children, /*#__PURE__*/_react.default.createElement(UpdatePortalManager, null));
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* @description 更新弹窗管理器
|
|
169
|
+
* @returns 更新弹窗管理器
|
|
170
|
+
*/
|
|
171
|
+
function UpdatePortalManager() {
|
|
172
|
+
var _useUpdateState = useUpdateState(),
|
|
173
|
+
isUpdateVisible = _useUpdateState.isUpdateVisible,
|
|
174
|
+
isDownloadVisible = _useUpdateState.isDownloadVisible;
|
|
175
|
+
return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, isUpdateVisible && /*#__PURE__*/_react.default.createElement(_updateModal.default, null), isDownloadVisible && /*#__PURE__*/_react.default.createElement(_downloadModal.default, null));
|
|
176
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { UpdateInfo } from './updateProvider';
|
|
2
|
+
/**
|
|
3
|
+
* @description 更新检查钩子
|
|
4
|
+
* @returns 更新检查钩子
|
|
5
|
+
*/
|
|
6
|
+
export default function usePushyUpdate(): {
|
|
7
|
+
checkUpdateApp: (flag?: boolean) => Promise<UpdateInfo | void>;
|
|
8
|
+
updateInfo: any;
|
|
9
|
+
isChecking: any;
|
|
10
|
+
error: any;
|
|
11
|
+
startDownloadFlow: any;
|
|
12
|
+
downloadUpdate: any;
|
|
13
|
+
switchVersion: any;
|
|
14
|
+
switchVersionLater: any;
|
|
15
|
+
progress: any;
|
|
16
|
+
markSuccess: any;
|
|
17
|
+
};
|