1- import { CheckResult , PushyOptions , ProgressData , EventType } from './type' ;
1+ import { CheckResult , ClientOptions , ProgressData , EventType } from './type' ;
22import { emptyObj , joinUrls , log , noop , promiseAny , testUrls } from './utils' ;
33import { EmitterSubscription , Platform } from 'react-native' ;
44import { PermissionsAndroid } from './permissions' ;
@@ -15,31 +15,45 @@ import {
1515 isRolledBack ,
1616} from './core' ;
1717
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+ } ,
2534} ;
26-
2735if ( 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+ ) ;
2939}
3040
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+
3151export 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 ,
4155 } ;
42-
56+ clientType : 'pushy' | 'cresc' = 'pushy' ;
4357 lastChecking ?: number ;
4458 lastRespJson ?: Promise < any > ;
4559
@@ -50,7 +64,7 @@ export class Pushy {
5064
5165 static marked = false ;
5266 static applyingUpdate = false ;
53- version = cInfo . pushy ;
67+ version = cInfo . rnu ;
5468 loggerPromise = ( ( ) => {
5569 let resolve : ( value ?: unknown ) => void = ( ) => { } ;
5670 const promise = new Promise ( res => {
@@ -62,7 +76,7 @@ export class Pushy {
6276 } ;
6377 } ) ( ) ;
6478
65- constructor ( options : PushyOptions ) {
79+ constructor ( options : ClientOptions ) {
6680 if ( Platform . OS === 'ios' || Platform . OS === 'android' ) {
6781 if ( ! options . appKey ) {
6882 throw new Error ( 'appKey is required' ) ;
@@ -79,7 +93,7 @@ export class Pushy {
7993 }
8094 }
8195
82- setOptions = ( options : Partial < PushyOptions > ) => {
96+ setOptions = ( options : Partial < ClientOptions > ) => {
8397 for ( const [ key , value ] of Object . entries ( options ) ) {
8498 if ( value !== undefined ) {
8599 ( this . options as any ) [ key ] = value ;
@@ -124,10 +138,10 @@ export class Pushy {
124138 return `${ endpoint } /checkUpdate/${ this . options . appKey } ` ;
125139 } ;
126140 static assertHash = ( hash : string ) => {
127- if ( ! Pushy . downloadedHash ) {
141+ if ( ! this . downloadedHash ) {
128142 return ;
129143 }
130- if ( hash !== Pushy . downloadedHash ) {
144+ if ( hash !== this . downloadedHash ) {
131145 log ( `use downloaded hash ${ Pushy . downloadedHash } first` ) ;
132146 return ;
133147 }
@@ -144,7 +158,7 @@ export class Pushy {
144158 switchVersion = async ( hash : string ) => {
145159 if ( __DEV__ ) {
146160 console . warn (
147- '您调用了switchVersion方法,但是当前是开发环境,不会进行任何操作。 ' ,
161+ 'switchVersion() is not supported in development environment; no action taken. ' ,
148162 ) ;
149163 return ;
150164 }
@@ -158,7 +172,7 @@ export class Pushy {
158172 switchVersionLater = async ( hash : string ) => {
159173 if ( __DEV__ ) {
160174 console . warn (
161- '您调用了switchVersionLater方法,但是当前是开发环境,不会进行任何操作。 ' ,
175+ 'switchVersionLater() is not supported in development environment; no action taken. ' ,
162176 ) ;
163177 return ;
164178 }
@@ -170,19 +184,19 @@ export class Pushy {
170184 checkUpdate = async ( extra ?: Record < string , any > ) => {
171185 if ( __DEV__ && ! this . options . debug ) {
172186 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. ' ,
174188 ) ;
175189 return ;
176190 }
177191 if ( Platform . OS === 'web' ) {
178- console . warn ( 'web 端不支持热更新检查 ' ) ;
192+ console . warn ( 'web platform does not support hot update check ' ) ;
179193 return ;
180194 }
181195 if (
182196 this . options . beforeCheckUpdate &&
183197 ( await this . options . beforeCheckUpdate ( ) ) === false
184198 ) {
185- log ( 'beforeCheckUpdate 返回 false, 忽略检查 ' ) ;
199+ log ( 'beforeCheckUpdate returned false, skipping check ' ) ;
186200 return ;
187201 }
188202 const now = Date . now ( ) ;
@@ -310,7 +324,7 @@ export class Pushy {
310324 this . options . beforeDownloadUpdate &&
311325 ( await this . options . beforeDownloadUpdate ( info ) ) === false
312326 ) {
313- log ( 'beforeDownloadUpdate 返回 false, 忽略下载 ' ) ;
327+ log ( 'beforeDownloadUpdate returned false, skipping download ' ) ;
314328 return ;
315329 }
316330 if ( ! info . update || ! hash ) {
@@ -489,3 +503,11 @@ export class Pushy {
489503 }
490504 } ;
491505}
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