import { useHotUpdate } from '@/composables/useHotUpdate' /** * 自动更新检查工具 * 用于在应用运行期间定期检查更新 */ class AutoUpdateChecker { constructor() { this.checkInterval = 4 * 60 * 60 * 1000 // 默认4小时检查一次更新 this.timer = null this.hotUpdate = useHotUpdate() } /** * 启动定时检查 * @param {Number} interval 可选,检查间隔时间(毫秒) */ startAutoCheck(interval) { // 先清除可能存在的定时器 this.stopAutoCheck() // 设置检查间隔时间 if (interval && typeof interval === 'number') { this.checkInterval = interval } // #ifdef APP-PLUS // 启动定时器 this.timer = setInterval(() => { this.hotUpdate.checkUpdate() }, this.checkInterval) // #endif return this } /** * 停止定时检查 */ stopAutoCheck() { if (this.timer) { clearInterval(this.timer) this.timer = null } return this } /** * 立即执行一次检查 */ checkNow() { // #ifdef APP-PLUS this.hotUpdate.checkUpdate() // #endif return this } } // 创建单例 const autoUpdateChecker = new AutoUpdateChecker() export default autoUpdateChecker