diff --git a/src/client.ts b/src/client.ts index 9f25fd5..c311de7 100644 --- a/src/client.ts +++ b/src/client.ts @@ -126,7 +126,7 @@ export class Pushy { PushyModule.markSuccess(); this.report({ type: 'markSuccess' }); }; - switchVersion = (hash: string) => { + switchVersion = async (hash: string) => { if (__DEV__) { console.warn( '您调用了switchVersion方法,但是当前是开发环境,不会进行任何操作。', @@ -136,11 +136,11 @@ export class Pushy { if (this.assertHash(hash) && !this.applyingUpdate) { log('switchVersion: ' + hash); this.applyingUpdate = true; - PushyModule.reloadUpdate({ hash }); + return PushyModule.reloadUpdate({ hash }); } }; - switchVersionLater = (hash: string) => { + switchVersionLater = async (hash: string) => { if (__DEV__) { console.warn( '您调用了switchVersionLater方法,但是当前是开发环境,不会进行任何操作。', @@ -149,7 +149,7 @@ export class Pushy { } if (this.assertHash(hash)) { log('switchVersionLater: ' + hash); - PushyModule.setNeedUpdate({ hash }); + return PushyModule.setNeedUpdate({ hash }); } }; checkUpdate = async (extra?: Record) => { diff --git a/src/context.ts b/src/context.ts index 1714d18..bea33b8 100644 --- a/src/context.ts +++ b/src/context.ts @@ -7,8 +7,8 @@ const asyncNoop = () => Promise.resolve(); export const defaultContext = { checkUpdate: asyncNoop, - switchVersion: noop, - switchVersionLater: noop, + switchVersion: asyncNoop, + switchVersionLater: asyncNoop, markSuccess: noop, dismissError: noop, downloadUpdate: asyncNoop, @@ -21,8 +21,8 @@ export const defaultContext = { export const PushyContext = createContext<{ checkUpdate: () => Promise; - switchVersion: () => void; - switchVersionLater: () => void; + switchVersion: () => Promise; + switchVersionLater: () => Promise; markSuccess: () => void; dismissError: () => void; downloadUpdate: () => Promise; diff --git a/src/provider.tsx b/src/provider.tsx index f106aa7..eff89cf 100644 --- a/src/provider.tsx +++ b/src/provider.tsx @@ -73,18 +73,18 @@ export const PushyProvider = ({ ); const switchVersion = useCallback( - (info: CheckResult | undefined = updateInfoRef.current) => { + async (info: CheckResult | undefined = updateInfoRef.current) => { if (info && info.hash) { - client.switchVersion(info.hash); + return client.switchVersion(info.hash); } }, [client], ); const switchVersionLater = useCallback( - (info: CheckResult | undefined = updateInfoRef.current) => { + async (info: CheckResult | undefined = updateInfoRef.current) => { if (info && info.hash) { - client.switchVersionLater(info.hash); + return client.switchVersionLater(info.hash); } }, [client],