Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
yansongda committed Nov 10, 2023
2 parents 8e5152a + 40f5142 commit 1a50b6d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
## v1.1.4

### feat

- feat(frontend:core): 增加小程序升级提示功能(#25)

### optimized

- optimized(style): 消除 ts 的 any,增加 eslint 等检查 (#23)
- optimized(style): 消除 ts 的 any,增加 eslint 等检查(#23)

## v1.1.3

Expand Down
30 changes: 29 additions & 1 deletion miniprogram/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import { DEFAULT } from '@constant/user'
import logger from '@utils/logger'
import type { GlobalData } from './types/app'
import type { LoginResponse, UpdateResult, User } from './types/user'
import { AppOnUnhandledRejection } from './types/wechat'
import type {
AppOnUnhandledRejection,
WxGetUpdateManagerOnCheckForUpdateResult
} from './types/wechat'

App<GlobalData>({
globalData: {
Expand Down Expand Up @@ -48,6 +51,31 @@ App<GlobalData>({
fail: async () => Promise.reject(new WeixinError(CODE.WEIXIN_LOGIN))
})
},
onShow() {
const updateManager = wx.getUpdateManager()

updateManager.onCheckForUpdate((res: WxGetUpdateManagerOnCheckForUpdateResult) => {
if (res.hasUpdate) {
logger.info('小程序有最新版本,后续将自动更新')
}
})

updateManager.onUpdateReady(() => {
wx.showModal({
title: '更新提示',
content: '新版本已经准备好,是否重启应用?',
success(res) {
if (res.confirm) {
updateManager.applyUpdate()
}
}
})
})

updateManager.onUpdateFailed(() => {
logger.error('小程序更新下载异常')
})
},
onError(e: string) {
logger.error('小程序异常', e)

Expand Down
4 changes: 4 additions & 0 deletions miniprogram/types/wechat.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,7 @@ export interface ChooseAvatarButtonTap<T, D> extends Tap<T, D> {
export interface WxGetFileSystemManagerReadFileSuccess {
data: string | ArrayBuffer
}

export interface WxGetUpdateManagerOnCheckForUpdateResult {
hasUpdate: boolean
}

0 comments on commit 1a50b6d

Please sign in to comment.