|
@@ -3,6 +3,23 @@ import semver from 'semver'
|
|
|
import { COOKIE_ROOT_DOMAIN, COOKIE_APP_KEY, COOKIE_APP_EXTRA_KEY, COOKIE_ACCESS_TOKEN_KEY, MSG_REQUIRE_LOGIN, APP_INJECT_COOKIE_KEYS, DEF_SYNCED_COOKIE_EXP } from './constant'
|
|
|
import { Notifier, SyncCookiesOptions } from '../types/global'
|
|
|
|
|
|
+const setupWebViewJavascriptBridge = (callback) => {
|
|
|
+ if (window.WebViewJavascriptBridge) {
|
|
|
+ return callback(window.WebViewJavascriptBridge)
|
|
|
+ }
|
|
|
+ if (window.WVJBCallbacks) {
|
|
|
+ return window.WVJBCallbacks.push(callback)
|
|
|
+ }
|
|
|
+ window.WVJBCallbacks = [callback]
|
|
|
+ var WVJBIframe = document.createElement('iframe')
|
|
|
+ WVJBIframe.style.display = 'none'
|
|
|
+ WVJBIframe.src = 'https://__bridge_loaded__'
|
|
|
+ document.documentElement.appendChild(WVJBIframe)
|
|
|
+ setTimeout(function () {
|
|
|
+ document.documentElement.removeChild(WVJBIframe)
|
|
|
+ }, 0)
|
|
|
+}
|
|
|
+
|
|
|
const parseJWT = (token: string): any => {
|
|
|
const payloadStr = token.split('.')[1]
|
|
|
|
|
@@ -57,7 +74,6 @@ let cachedAppInfo: any
|
|
|
let cachedappExtra: any
|
|
|
|
|
|
class ProginnBridge {
|
|
|
- // @ts-ignore
|
|
|
root = window.app_event || window.appBridge
|
|
|
|
|
|
private notifier?: Notifier
|
|
@@ -120,7 +136,14 @@ class ProginnBridge {
|
|
|
window[root][name] = cb
|
|
|
}
|
|
|
|
|
|
- invoke(fn: string, payload?: any) {
|
|
|
+ invoke(fn: string, data: any = null, cb: Function = () => {}) {
|
|
|
+ if (this.isIos && this.compareAppVersion('gte', '4.22.0')) {
|
|
|
+ setupWebViewJavascriptBridge((bridge) => {
|
|
|
+ bridge.callHandler(fn, data, cb)
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
if (!this.root) {
|
|
|
// tslint:disable-next-line
|
|
|
console.warn(`Bridge invoke ${fn} skipped.`)
|
|
@@ -129,12 +152,12 @@ class ProginnBridge {
|
|
|
|
|
|
if (this.isAndroid) {
|
|
|
if (typeof this.root[fn] === 'function') {
|
|
|
- return payload ? this.root[fn](payload) : this.root[fn]()
|
|
|
+ return data ? this.root[fn](data) : this.root[fn]()
|
|
|
} else {
|
|
|
return null
|
|
|
}
|
|
|
} else {
|
|
|
- return this.root(fn, payload)
|
|
|
+ return this.root(fn, data)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -142,7 +165,12 @@ class ProginnBridge {
|
|
|
if (!this.isInApp) {
|
|
|
window.history.back()
|
|
|
} else {
|
|
|
- this.invoke('back_page')
|
|
|
+ if (this.isIos && this.compareAppVersion('gte', '4.22.0')) {
|
|
|
+ this.invoke('back')
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this.invoke('back_page')
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -226,23 +254,35 @@ class ProginnBridge {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- userLoad(userInfo: any) {
|
|
|
- this.invoke('user_load', this.isAndroid ? userInfo : {
|
|
|
- userInfo
|
|
|
- })
|
|
|
+ loadUserData(data: any) {
|
|
|
+ if (this.isAndroid) {
|
|
|
+ this.invoke('user_load', data)
|
|
|
+ }
|
|
|
+ else if (this.compareAppVersion('lt', '4.22.0')) {
|
|
|
+ this.invoke('user_load', {
|
|
|
+ userInfo: data,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this.invoke('loadUserData', data)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- topicLoad(id: string, data: {
|
|
|
+ loadTopicData(data: {
|
|
|
topic_id: string
|
|
|
user_id: string
|
|
|
share_content: any
|
|
|
topics: any[]
|
|
|
}) {
|
|
|
- this.invoke('topic_load', this.isAndroid ? id : data)
|
|
|
- }
|
|
|
-
|
|
|
- setNavigationBarTitle(title: string) {
|
|
|
- this.invoke('setNavigationBarTitle', title)
|
|
|
+ if (this.isAndroid) {
|
|
|
+ this.invoke('topic_load', data.topic_id)
|
|
|
+ }
|
|
|
+ else if (this.compareAppVersion('lt', '4.22.0')) {
|
|
|
+ this.invoke('topic_load', data)
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this.invoke('loadTopicData', data)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|