(
info: UpdateInfo,
options: { now?: number; stateFile?: string; cooldownMs?: number } = {}
)
| 259 | } |
| 260 | |
| 261 | export async function shouldShowUpdateNotification( |
| 262 | info: UpdateInfo, |
| 263 | options: { now?: number; stateFile?: string; cooldownMs?: number } = {} |
| 264 | ): Promise<boolean> { |
| 265 | if (!info.updateAvailable) return false; |
| 266 | |
| 267 | const now = options.now ?? Date.now(); |
| 268 | const cooldownMs = options.cooldownMs ?? DEFAULT_CACHE_TTL_MS; |
| 269 | const state = await readUpdateState(options.stateFile); |
| 270 | |
| 271 | if ( |
| 272 | state.notifiedVersion === info.latestVersion && |
| 273 | state.lastNotifiedAt && |
| 274 | now - state.lastNotifiedAt < cooldownMs |
| 275 | ) { |
| 276 | return false; |
| 277 | } |
| 278 | |
| 279 | return true; |
| 280 | } |
| 281 | |
| 282 | export async function markUpdateNotificationShown( |
| 283 | latestVersion: string, |
no test coverage detected