This repository has been archived by the owner on Aug 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
app.js
153 lines (114 loc) · 3.79 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import regeneratorRuntime from './utils/libs/regenerator-runtime'
import config from './config';
import './utils/init'
let appParams = {}
appParams.onLaunch = async function (options) {
if (options.query && options.query.dev) {
console.log('真机预览模式')
wx.ooCache.dev = true
}
for (const key of wx.getStorageInfoSync().keys) {
const data = wx.getStorageSync(key)
wx.ooCache[key] = !wx.ooUtil.isObject(data) ? data : Object.assign({}, wx.ooCache[key] || {}, data)
}
console.info('缓存', wx.ooCache)
// 先检查更新 有新特性就弹窗
await this.checkUpdate()
// 然后再判断是否需要引导
wx.ooTip.guide()
// 最后再做其他事
this.checkSoter()
this.getNotice()
this.wechatLogin()
wx.ooCache.launched = true
}
appParams.onError = function (error) {
if (wx.ooCache.systemInfo.platform === 'devtools') {
return
}
// 过滤奇怪的错误
if (error.indexOf('webview') !== -1 || error.indexOf('appServiceSDKScriptError') !== -1) {
return
}
let content = [
`用户:${wx.ooCache.user && wx.ooCache.user.id} / ${wx.ooCache.openID}`,
`版本:${wx.ooCache.version}`,
`系统信息:${JSON.stringify(wx.ooCache.systemInfo)}`,
`错误堆栈:${error}`,
]
if (error.indexOf('schedule') !== -1) {
content.push(`课程信息:${JSON.stringify(wx.ooCache.schedule)}`)
}
if (error.indexOf('split') !== -1) {
content.push(`教务数据:${JSON.stringify(wx.ooCache.edu)}`)
}
wx.ooRequest.triggerAlarm(content.join('\n\n'))
}
appParams.checkUpdate = async function () {
// 基础库 1.9.90 开始支持
if (wx.getUpdateManager) {
const updateManager = wx.getUpdateManager()
updateManager.onUpdateReady(async function () {
const modalRes = await wx.ooShowModal({ content: wx.ooString.global.updateManager })
if (modalRes.confirm) {
updateManager.applyUpdate()
}
})
}
if (wx.ooCache.version === config.version) {
return
}
console.log('已更新到新版', config.version)
// 新用户不显示新版特性 因此先判断缓存里是否存在版本项
if (wx.ooCache.version && wx.ooString.feature) {
await wx.ooShowModal({
title: wx.ooString.global.new_feature,
content: wx.ooString.feature,
}, false)
}
wx.ooCache.updateSucceed = true
wx.ooSaveData({ version: config.version })
}
appParams.checkSoter = async function () {
const now = (new Date()).getTime()
if (wx.ooCache.supportSoter !== undefined && wx.ooCache.supportSoterUpdatedAt && wx.ooCache.supportSoterUpdatedAt + 86400000 > now) {
return
}
const isSupportSoter = async () => {
let flag = false
const is_iOS = wx.ooCache.systemInfo.system.toLowerCase().indexOf('ios') !== -1,
isVersionSeven = wx.ooCache.systemInfo.version.startsWith('7.'),
hasFaceIdOfIphone = wx.ooCache.systemInfo.model.toLowerCase().indexOf('iphone x') !== -1
if (is_iOS) {
// http://t.cn/EJ4o0kR
if (isVersionSeven) {
const data = await wx.ooIsSoterEnrolled('facial').then(ret => ret)
if (data.isEnrolled || false) {
return true
}
}
if (hasFaceIdOfIphone) {
return false
}
}
const data = await wx.ooIsSoterEnrolled('fingerPrint').catch(ret => ret)
return data.isEnrolled || false
}
wx.ooSaveData({
supportSoter: await isSupportSoter(),
supportSoterUpdatedAt: now,
})
}
appParams.getNotice = async function () {
wx.ooCache.notice = await wx.ooRequest.getNotice()
}
appParams.wechatLogin = async function () {
const user = wx.ooService.user.getAccount()
if (!user.id || wx.ooCache.openID) {
return
}
const loginRet = await wx.ooPro.login()
const openID = await wx.ooRequest.wechatLogin([loginRet.code, user.id])
wx.ooSaveData({ openID })
}
App(appParams)