@@ -22,6 +22,7 @@ import {
2222 ClientOptions ,
2323 EventType ,
2424 ProgressData ,
25+ UpdateCheckState ,
2526 UpdateServerConfig ,
2627} from './type' ;
2728import {
@@ -207,6 +208,16 @@ export class Pushy {
207208 throw e ;
208209 }
209210 } ;
211+ notifyAfterCheckUpdate = ( state : UpdateCheckState ) => {
212+ const { afterCheckUpdate } = this . options ;
213+ if ( ! afterCheckUpdate ) {
214+ return ;
215+ }
216+ // 这里仅做状态通知,不阻塞原有检查流程
217+ Promise . resolve ( afterCheckUpdate ( state ) ) . catch ( ( error : any ) => {
218+ log ( 'afterCheckUpdate failed:' , error ?. message || error ) ;
219+ } ) ;
220+ } ;
210221 getCheckUrl = ( endpoint : string ) => {
211222 return `${ endpoint } /checkUpdate/${ this . options . appKey } ` ;
212223 } ;
@@ -329,16 +340,19 @@ export class Pushy {
329340 } ;
330341 checkUpdate = async ( extra ?: Record < string , any > ) => {
331342 if ( ! this . assertDebug ( 'checkUpdate()' ) ) {
343+ this . notifyAfterCheckUpdate ( { status : 'skipped' } ) ;
332344 return ;
333345 }
334346 if ( ! assertWeb ( ) ) {
347+ this . notifyAfterCheckUpdate ( { status : 'skipped' } ) ;
335348 return ;
336349 }
337350 if (
338351 this . options . beforeCheckUpdate &&
339352 ( await this . options . beforeCheckUpdate ( ) ) === false
340353 ) {
341354 log ( 'beforeCheckUpdate returned false, skipping check' ) ;
355+ this . notifyAfterCheckUpdate ( { status : 'skipped' } ) ;
342356 return ;
343357 }
344358 const now = Date . now ( ) ;
@@ -347,7 +361,9 @@ export class Pushy {
347361 this . lastChecking &&
348362 now - this . lastChecking < 1000 * 5
349363 ) {
350- return await this . lastRespJson ;
364+ const result = await this . lastRespJson ;
365+ this . notifyAfterCheckUpdate ( { status : 'completed' , result } ) ;
366+ return result ;
351367 }
352368 this . lastChecking = now ;
353369 const fetchBody = {
@@ -387,6 +403,7 @@ export class Pushy {
387403
388404 log ( 'checking result:' , result ) ;
389405
406+ this . notifyAfterCheckUpdate ( { status : 'completed' , result } ) ;
390407 return result ;
391408 } catch ( e : any ) {
392409 this . lastRespJson = previousRespJson ;
@@ -396,6 +413,7 @@ export class Pushy {
396413 type : 'errorChecking' ,
397414 message : errorMessage ,
398415 } ) ;
416+ this . notifyAfterCheckUpdate ( { status : 'error' , error : e } ) ;
399417 this . throwIfEnabled ( e ) ;
400418 return previousRespJson ? await previousRespJson : emptyObj ;
401419 }
0 commit comments