import { CheckForUpdateEvent } from "./CheckForUpdateEvent"; /** * 版本更新管理器。 */ export interface UpdateManager { /** * 强制小程序重启并使用新版本。 * * @example * ```javascript * const updateManager = ks.getUpdateManager(); * * updateManager.onUpdateReady(async () => { * const { confirm } = await ks.showModal({ * title: '更新提示', * content: '新版本已经准备好,是否重启应用?', * }); * * if (confirm) { * updateManager.applyUpdate(); * } * }); * * ``` * */ applyUpdate(): void; /** * 监听检查小程序更新事件。小程序冷启动时会自动检查更新,不需要开发者手动触发。 * @param callback 检查小程序更新事件的回调函数 * * @example * ```javascript * const updateManager = ks.getUpdateManager(); * * updateManager.onCheckForUpdate((res) => { * if (!res.hasUpdate) { * ks.showModal({ * title: '小程序已经是最新版本', * }); * } * }); * * ``` * */ onCheckForUpdate(callback: (event: CheckForUpdateEvent) => void): void; /** * 监听小程序新版本下载失败事件。小程序会自动开始下载新版本,不需要开发者手动触发。 * @param callback 小程序新版本下载失败事件的回调函数 * * @example * ```javascript * const updateManager = ks.getUpdateManager(); * * updateManager.onUpdateFailed(() => { * ks.showModal({ * title: '更新失败', * }); * }); * * ``` * */ onUpdateFailed(callback: () => void): void; /** * 监听小程序新版本下载成功事件。小程序会自动开始下载新版本,不需要开发者手动触发。 * @param callback 小程序新版本下载成功事件的回调函数 * * @example * ```javascript * const updateManager = ks.getUpdateManager(); * * updateManager.onUpdateReady(async () => { * const { confirm } = await ks.showModal({ * title: '更新提示', * content: '新版本已经准备好,是否重启应用?', * }); * * if (confirm) { * updateManager.applyUpdate(); * } * }); * * ``` * */ onUpdateReady(callback: () => void): void; }