diff --git a/lib/index.js b/lib/index.js index 336d8d2..a3f61d6 100644 --- a/lib/index.js +++ b/lib/index.js @@ -165,6 +165,10 @@ export async function downloadUpdate(options, eventListeners) { logger(`duplicated downloaded hash ${downloadedHash}, ignored`); return; } + if (readyHash) { + logger(`hash ${readyHash} applied. reboot first`); + return; + } if (downloadingThrottling) { logger('repeated downloading, ignored'); return; @@ -215,21 +219,34 @@ export async function downloadUpdate(options, eventListeners) { return options.hash; } -export function switchVersion(hash) { - assertRelease(); - logger('switchVersion'); - Pushy.reloadUpdate({ hash }); -} - let readyHash; -export function switchVersionLater(hash) { - assertRelease(); +function assertHash(hash) { + if (!downloadedHash) { + logger(`no downloaded hash`); + return; + } + if (hash !== downloadedHash) { + logger(`use downloaded hash ${downloadedHash} first`); + return; + } if (readyHash === hash) { - logger(`duplicated ready hash ${readyHash}, ignored`); + logger(`hash ${readyHash} already applied. reboot first.`); return; } readyHash = hash; - logger('switchVersionLater'); +} + +export function switchVersion(hash) { + assertRelease(); + assertHash(hash); + logger('switchVersion: ' + hash); + Pushy.reloadUpdate({ hash }); +} + +export function switchVersionLater(hash) { + assertRelease(); + assertHash(hash); + logger('switchVersionLater: ' + hash); Pushy.setNeedUpdate({ hash }); }