-
-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
288 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
exports.install = function() {}; | ||
exports.install = function() {}; | ||
exports.applyUpdate = function() {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
<script> | ||
(function() { | ||
// ################################ | ||
var updateReadyInterval; | ||
var updatingFired; | ||
var downloadingInterval; | ||
var obsoleteInterval; | ||
var cleanUpTimer; | ||
applicationCache.addEventListener('updateready', onUpdateReadyEvent); | ||
applicationCache.addEventListener('cached', onInstalledEvent); | ||
applicationCache.addEventListener('obsolete', onObsoleteEvent); | ||
applicationCache.addEventListener('downloading', onDownloadingEvent); | ||
applicationCache.addEventListener('progress', onDownloadingEvent); | ||
switch (applicationCache.status) { | ||
case applicationCache.DOWNLOADING: { | ||
setTimeout(onDownloadingEvent, 1); | ||
} break; | ||
case applicationCache.OBSOLETE: { | ||
setTimeout(onObsoleteEvent, 1); | ||
} break; | ||
case applicationCache.UPDATEREADY: { | ||
setTimeout(onUpdateReadyEvent, 1); | ||
} break; | ||
default: { | ||
downloadingInterval = setInterval(function() { | ||
if (applicationCache.status === applicationCache.DOWNLOADING) { | ||
onDownloadingEvent(); | ||
} | ||
}, 50); | ||
obsoleteInterval = setInterval(function() { | ||
if (applicationCache.status === applicationCache.OBSOLETE) { | ||
onObsoleteEvent(); | ||
} | ||
}, 50); | ||
updateReadyInterval = setInterval(function() { | ||
if (applicationCache.status === applicationCache.UPDATEREADY) { | ||
onUpdateReadyEvent(); | ||
} | ||
}, 50); | ||
} | ||
} | ||
cleanUpTimer = setTimeout(function() { | ||
cleanUp(); | ||
}, 5000); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
// ############################### | ||
function onDownloadingEvent() { | ||
if (!updatingFired) { | ||
updatingFired = true; | ||
onUpdating(); | ||
} | ||
downloadingCleanUp(); | ||
} | ||
function onUpdateReadyEvent() { | ||
if (!updatingFired) { | ||
updatingFired = true; | ||
onUpdating(); | ||
setTimeout(onUpdateReady, 1); | ||
} else { | ||
onUpdateReady(); | ||
} | ||
cleanUp(); | ||
} | ||
function onInstalledEvent() { | ||
onInstalled(); | ||
cleanUp(); | ||
} | ||
function onObsoleteEvent() { | ||
onUpdateFailed(); | ||
setTimeout(onUninstalled, 1); | ||
cleanUp(); | ||
} | ||
function downloadingCleanUp() { | ||
if (downloadingInterval) { | ||
clearInterval(downloadingInterval); | ||
downloadingInterval = null; | ||
} | ||
applicationCache.removeEventListener('downloading', onDownloadingEvent); | ||
applicationCache.removeEventListener('progress', onDownloadingEvent); | ||
} | ||
function cleanUp() { | ||
if (cleanUpTimer) { | ||
clearTimeout(cleanUpTimer); | ||
cleanUpTimer = null; | ||
} | ||
downloadingCleanUp(); | ||
applicationCache.removeEventListener('updateready', onUpdateReadyEvent); | ||
applicationCache.removeEventListener('cached', onInstalledEvent); | ||
applicationCache.removeEventListener('obsolete', onObsoleteEvent); | ||
if (updateReadyInterval) { | ||
clearInterval(updateReadyInterval); | ||
updateReadyInterval = null; | ||
} | ||
if (obsoleteInterval) { | ||
clearInterval(obsoleteInterval); | ||
obsoleteInterval = null; | ||
} | ||
} | ||
// ################################ | ||
}()); | ||
function onUpdating() { | ||
sendEvent('onUpdating'); | ||
} | ||
function onUpdateReady() { | ||
sendEvent('onUpdateReady'); | ||
} | ||
function onUpdateFailed() { | ||
sendEvent('onUpdateFailed'); | ||
} | ||
function onUninstalled() { | ||
sendEvent('onUninstalled'); | ||
} | ||
function onInstalled() { | ||
sendEvent('onInstalled'); | ||
} | ||
function sendEvent(event) { | ||
window.parent.postMessage('__offline-plugin_AppCacheEvent:' + event, '*'); | ||
} | ||
</script> |
Oops, something went wrong.
@NekR Hi, my english if not good, so if my wording or tone offended you, excuse me.
Can you tell me why you call
cleanUp
here?If I understand the code correctly, the
cleanUp
function will be called after Runtime be installed and 5 seconds later, then the function will removeupdateready
event listener.So if I call
applicationCache.update
after Runtime installed and 5 seconds later, then the eventonUpdateReady
in Runtime option will never be called, right? Seems it's not what I expected, I hope theonUpdateReady
will be called in any time, so long asupdateready
event be fired.