Skip to content

Commit

Permalink
Merge pull request #569 from handsomeliuyang/test-osChannel
Browse files Browse the repository at this point in the history
将osChannelApi移到taro-mpharmony
  • Loading branch information
qican777 authored Mar 27, 2024
2 parents 0737c1d + 4f6b846 commit 03e47f4
Show file tree
Hide file tree
Showing 2 changed files with 405 additions and 25 deletions.
41 changes: 16 additions & 25 deletions packages/taro-mpharmony/src/api/NativeApi.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import osChannelApi from './osChannelApi'


class NativeApi {
Expand Down Expand Up @@ -876,35 +877,25 @@ class AsyncToSyncProxy {
}
}

class HybridApi extends NativeApi {
class OsChannelProxy {
private readonly useOsChannel: boolean
private readonly cacheProxy: any

hideKeyboard (): any {
// @ts-ignore
return window.isOsChannel ? osChannel.hideKeyboard() : super.hideKeyboard()
constructor (useOsChannel: boolean) {
this.useOsChannel = useOsChannel
this.cacheProxy = new Proxy(nativeApi, new CacheStorageProxy(nativeApi))

Check warning on line 886 in packages/taro-mpharmony/src/api/NativeApi.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

'nativeApi' was used before it was defined

Check warning on line 886 in packages/taro-mpharmony/src/api/NativeApi.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

'nativeApi' was used before it was defined
}

makePhoneCall (_option: any): any {
// @ts-ignore
return window.isOsChannel ? osChannel.makePhoneCall(_option) : super.makePhoneCall(_option)
}

request (_option: any): any {
// @ts-ignore
return window.isOsChannel ? osChannel.request(_option) : super.request(_option)
}

getAppAuthorizeSetting (): any {
// @ts-ignore
return window.isOsChannel ? osChannel.getAppAuthorizeSetting() : super.getAppAuthorizeSetting()
}

getSystemSetting (): any {
// @ts-ignore
return window.isOsChannel ? osChannel.getSystemSetting() : super.getSystemSetting()
get (_target:any, prop:string) {
return (...args: any) => {
if (this.useOsChannel && osChannelApi.hasOwnProperty(prop)) {
return osChannelApi[prop](...args)
}
return this.cacheProxy[prop](...args)
}
}
}

const nativeApi = new HybridApi()
const native = new Proxy(nativeApi, new CacheStorageProxy(nativeApi))

const nativeApi = new NativeApi()
const native = new Proxy(nativeApi, new OsChannelProxy(false))
export default native
Loading

0 comments on commit 03e47f4

Please sign in to comment.