1
- import { CheckResult , PushyOptions , ProgressData , EventType } from './type' ;
1
+ import { CheckResult , ClientOptions , ProgressData , EventType } from './type' ;
2
2
import { emptyObj , joinUrls , log , noop , promiseAny , testUrls } from './utils' ;
3
3
import { EmitterSubscription , Platform } from 'react-native' ;
4
4
import { PermissionsAndroid } from './permissions' ;
@@ -15,31 +15,45 @@ import {
15
15
isRolledBack ,
16
16
} from './core' ;
17
17
18
- const defaultServer = {
19
- main : 'https://update.react-native.cn/api' ,
20
- backups : [ 'https://update.reactnative.cn/api' ] ,
21
- queryUrls : [
22
- 'https://gitee.com/sunnylqm/react-native-pushy/raw/master/endpoints.json' ,
23
- 'https://cdn.jsdelivr.net/gh/reactnativecn/react-native-update@master/endpoints.json' ,
24
- ] ,
18
+ const SERVER_PRESETS = {
19
+ pushy : {
20
+ main : 'https://update.react-native.cn/api' ,
21
+ backups : [ 'https://update.reactnative.cn/api' ] ,
22
+ queryUrls : [
23
+ 'https://gitee.com/sunnylqm/react-native-pushy/raw/master/endpoints.json' ,
24
+ 'https://cdn.jsdelivr.net/gh/reactnativecn/react-native-update@master/endpoints.json' ,
25
+ ] ,
26
+ } ,
27
+ cresc : {
28
+ main : 'https://api.cresc.dev' ,
29
+ backups : [ 'https://api.cresc.app' ] ,
30
+ queryUrls : [
31
+ 'https://cdn.jsdelivr.net/gh/reactnativecn/react-native-update@master/endpoints_cresc.json' ,
32
+ ] ,
33
+ } ,
25
34
} ;
26
-
27
35
if ( Platform . OS === 'web' ) {
28
- console . warn ( 'react-native-update 不支持 web 端热更,不会执行操作' ) ;
36
+ console . warn (
37
+ 'react-native-update does not support hot updates on the web platform and will not perform any operations' ,
38
+ ) ;
29
39
}
30
40
41
+ const defaultClientOptions : ClientOptions = {
42
+ appKey : '' ,
43
+ autoMarkSuccess : true ,
44
+ updateStrategy : __DEV__ ? 'alwaysAlert' : 'alertUpdateAndIgnoreError' ,
45
+ checkStrategy : 'both' ,
46
+ logger : noop ,
47
+ debug : false ,
48
+ throwError : false ,
49
+ } ;
50
+
31
51
export class Pushy {
32
- options : PushyOptions = {
33
- appKey : '' ,
34
- server : defaultServer ,
35
- autoMarkSuccess : true ,
36
- updateStrategy : __DEV__ ? 'alwaysAlert' : 'alertUpdateAndIgnoreError' ,
37
- checkStrategy : 'both' ,
38
- logger : noop ,
39
- debug : false ,
40
- throwError : false ,
52
+ options : ClientOptions = {
53
+ ...defaultClientOptions ,
54
+ server : SERVER_PRESETS . pushy ,
41
55
} ;
42
-
56
+ clientType : 'pushy' | 'cresc' = 'pushy' ;
43
57
lastChecking ?: number ;
44
58
lastRespJson ?: Promise < any > ;
45
59
@@ -50,7 +64,7 @@ export class Pushy {
50
64
51
65
static marked = false ;
52
66
static applyingUpdate = false ;
53
- version = cInfo . pushy ;
67
+ version = cInfo . rnu ;
54
68
loggerPromise = ( ( ) => {
55
69
let resolve : ( value ?: unknown ) => void = ( ) => { } ;
56
70
const promise = new Promise ( res => {
@@ -62,7 +76,7 @@ export class Pushy {
62
76
} ;
63
77
} ) ( ) ;
64
78
65
- constructor ( options : PushyOptions ) {
79
+ constructor ( options : ClientOptions ) {
66
80
if ( Platform . OS === 'ios' || Platform . OS === 'android' ) {
67
81
if ( ! options . appKey ) {
68
82
throw new Error ( 'appKey is required' ) ;
@@ -79,7 +93,7 @@ export class Pushy {
79
93
}
80
94
}
81
95
82
- setOptions = ( options : Partial < PushyOptions > ) => {
96
+ setOptions = ( options : Partial < ClientOptions > ) => {
83
97
for ( const [ key , value ] of Object . entries ( options ) ) {
84
98
if ( value !== undefined ) {
85
99
( this . options as any ) [ key ] = value ;
@@ -124,10 +138,10 @@ export class Pushy {
124
138
return `${ endpoint } /checkUpdate/${ this . options . appKey } ` ;
125
139
} ;
126
140
static assertHash = ( hash : string ) => {
127
- if ( ! Pushy . downloadedHash ) {
141
+ if ( ! this . downloadedHash ) {
128
142
return ;
129
143
}
130
- if ( hash !== Pushy . downloadedHash ) {
144
+ if ( hash !== this . downloadedHash ) {
131
145
log ( `use downloaded hash ${ Pushy . downloadedHash } first` ) ;
132
146
return ;
133
147
}
@@ -144,7 +158,7 @@ export class Pushy {
144
158
switchVersion = async ( hash : string ) => {
145
159
if ( __DEV__ ) {
146
160
console . warn (
147
- '您调用了switchVersion方法,但是当前是开发环境,不会进行任何操作。 ' ,
161
+ 'switchVersion() is not supported in development environment; no action taken. ' ,
148
162
) ;
149
163
return ;
150
164
}
@@ -158,7 +172,7 @@ export class Pushy {
158
172
switchVersionLater = async ( hash : string ) => {
159
173
if ( __DEV__ ) {
160
174
console . warn (
161
- '您调用了switchVersionLater方法,但是当前是开发环境,不会进行任何操作。 ' ,
175
+ 'switchVersionLater() is not supported in development environment; no action taken. ' ,
162
176
) ;
163
177
return ;
164
178
}
@@ -170,19 +184,19 @@ export class Pushy {
170
184
checkUpdate = async ( extra ?: Record < string , any > ) => {
171
185
if ( __DEV__ && ! this . options . debug ) {
172
186
console . info (
173
- '您当前处于开发环境且未启用 debug,不会进行热更检查。如需在开发环境中调试热更,请在 client 中设置 debug 为 true' ,
187
+ 'You are currently in the development environment and have not enabled debug mode. The hot update check will not be performed. If you need to debug hot updates in the development environment, please set debug to true in the client. ' ,
174
188
) ;
175
189
return ;
176
190
}
177
191
if ( Platform . OS === 'web' ) {
178
- console . warn ( 'web 端不支持热更新检查 ' ) ;
192
+ console . warn ( 'web platform does not support hot update check ' ) ;
179
193
return ;
180
194
}
181
195
if (
182
196
this . options . beforeCheckUpdate &&
183
197
( await this . options . beforeCheckUpdate ( ) ) === false
184
198
) {
185
- log ( 'beforeCheckUpdate 返回 false, 忽略检查 ' ) ;
199
+ log ( 'beforeCheckUpdate returned false, skipping check ' ) ;
186
200
return ;
187
201
}
188
202
const now = Date . now ( ) ;
@@ -310,7 +324,7 @@ export class Pushy {
310
324
this . options . beforeDownloadUpdate &&
311
325
( await this . options . beforeDownloadUpdate ( info ) ) === false
312
326
) {
313
- log ( 'beforeDownloadUpdate 返回 false, 忽略下载 ' ) ;
327
+ log ( 'beforeDownloadUpdate returned false, skipping download ' ) ;
314
328
return ;
315
329
}
316
330
if ( ! info . update || ! hash ) {
@@ -489,3 +503,11 @@ export class Pushy {
489
503
}
490
504
} ;
491
505
}
506
+
507
+ export class Cresc extends Pushy {
508
+ clientType : 'cresc' | 'pushy' = 'cresc' ;
509
+ options : ClientOptions = {
510
+ ...defaultClientOptions ,
511
+ server : SERVER_PRESETS . cresc ,
512
+ } ;
513
+ }
0 commit comments