sindresorhus/update-notifier

Notification is only displayed at most once per interval

開放

#209 建立於 2021年7月1日

 (3 則留言) (0 個反應) (0 位負責人)JavaScript (164 個分叉)user submission
enhancementhelp wanted

倉庫指標

星標
 (1,800 顆星)
PR 合併指標
 (30 天內沒有已合併 PR)

描述

As of 5.1.0, notifications are displayed at most once per interval period, because the fetched update is deleted once "emitted" (ie set to this.update)

		this.update = this.config.get('update');

		if (this.update) {
			// Use the real latest version instead of the cached one
			this.update.current = this.packageVersion;

			// Clear cached information
			this.config.delete('update');
		}

This is a bit weird to me, wouldn't it be better if the update message was displayed consistently as long as there is an update? Some users might miss that there is an available update quite easily.

Some workarounds I'm using to ensure that once an update gets fetched, it remains visible, and trying to fetch it before the first interval:

// Hacky way to ensure we check for updates on first run
// Note: the notification will only happen in the 2nd run anyway
if (
  !notifier.disabled &&
  Date.now() - notifier.config.get('lastUpdateCheck') < 50
) {
  notifier.config.set('lastUpdateCheck', 0);
  notifier.check();
}

if (notifier.update && notifier.update.current !== notifier.update.latest) {
  // Because notifier clears cached data after reading it, leading to notifier not consistently displaying the update
  notifier.config.set('update', notifier.update);

  // Display notification
}

Having a more convenient way to achieve all this could be useful

貢獻者指南