function showUpdateReady(updatePlatform, manager) { if (!updatePlatform || typeof updatePlatform.showModal !== 'function') return updatePlatform.showModal({ title: '新版本已经准备好', content: '重新打开后即可使用新版本。现在更新吗?', confirmText: '现在更新', cancelText: '稍后再说', success(result) { if (result && result.confirm && typeof manager.applyUpdate === 'function') { manager.applyUpdate() } }, }) } function showUpdateFailed(updatePlatform) { if (!updatePlatform || typeof updatePlatform.showModal !== 'function') return updatePlatform.showModal({ title: '新版本暂时没有下载完成', content: '当前内容仍可继续使用。请检查网络后,完全退出微信再重新打开。', showCancel: false, confirmText: '知道了', }) } function setupUpdateManager(updatePlatform) { if (!updatePlatform || typeof updatePlatform.getUpdateManager !== 'function') return false try { const manager = updatePlatform.getUpdateManager() if (!manager) return false if (typeof manager.onUpdateReady === 'function') { manager.onUpdateReady(() => showUpdateReady(updatePlatform, manager)) } if (typeof manager.onUpdateFailed === 'function') { manager.onUpdateFailed(() => showUpdateFailed(updatePlatform)) } return true } catch (error) { return false } } module.exports = { setupUpdateManager, showUpdateFailed, showUpdateReady, }