@cloudbase/oauth 2.5.41-beta.0 → 2.5.43-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,53 @@
1
+ export function isMp() {
2
+ const { wx } = globalThis as any
3
+ if (typeof wx === 'undefined') {
4
+ return false
5
+ }
6
+ if ((globalThis as any).Page === undefined) {
7
+ return false
8
+ }
9
+ if (!wx.getSystemInfoSync) {
10
+ return false
11
+ }
12
+ if (!wx.getStorageSync) {
13
+ return false
14
+ }
15
+ if (!wx.setStorageSync) {
16
+ return false
17
+ }
18
+ if (!wx.connectSocket) {
19
+ return false
20
+ }
21
+ if (!wx.request) {
22
+ return false
23
+ }
24
+
25
+ try {
26
+ if (!wx.getSystemInfoSync()) {
27
+ return false
28
+ }
29
+
30
+ if (wx.getSystemInfoSync().AppPlatform === 'qq') {
31
+ return false
32
+ }
33
+ } catch (e) {
34
+ return false
35
+ }
36
+
37
+ return true
38
+ }
39
+
40
+ let IS_IN_MP_WEBVIEW = !!navigator.userAgent.match(/miniprogram/i) || (window as any).__wxjs_environment === 'miniprogram'
41
+ function ready() {
42
+ IS_IN_MP_WEBVIEW = IS_IN_MP_WEBVIEW || (typeof window !== undefined && (window as any).__wxjs_environment === 'miniprogram')
43
+ }
44
+ if (!isMp()) {
45
+ if ((window as any)?.WeixinJSBridge?.invoke) {
46
+ ready()
47
+ } else if (typeof document !== 'undefined') {
48
+ document.addEventListener?.('WeixinJSBridgeReady', ready, false)
49
+ }
50
+ }
51
+ export function isInMpWebView() {
52
+ return IS_IN_MP_WEBVIEW
53
+ }