Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library trydart.cache; | 5 library trydart.cache; |
| 6 | 6 |
| 7 import 'dart:async' show | 7 import 'dart:async' show |
| 8 Timer; | 8 Timer; |
| 9 | 9 |
| 10 import 'dart:html' show | 10 import 'dart:html' show |
| 11 AnchorElement, | 11 AnchorElement, |
| 12 ApplicationCache, | 12 ApplicationCache, |
| 13 Event, | 13 Event, |
| 14 MeterElement, | 14 MeterElement, |
| 15 ProgressEvent, | 15 ProgressEvent, |
| 16 window; | 16 window; |
| 17 | 17 |
| 18 import 'ui.dart' show | 18 import 'ui.dart' show |
| 19 cacheStatusElement; | 19 cacheStatusElement; |
| 20 | 20 |
| 21 /// Called when the window has finished loading. | 21 /// Called when the window has finished loading. |
| 22 void onLoad(Event event) { | 22 void onLoad(Event event) { |
| 23 if (!ApplicationCache.supported) return; | |
| 23 window.applicationCache.onUpdateReady.listen((_) => updateCacheStatus()); | 24 window.applicationCache.onUpdateReady.listen((_) => updateCacheStatus()); |
|
kasperl
2014/05/06 04:42:22
Consider having a local helper function for the (_
ahe
2014/05/06 08:10:16
I've changed updateCacheStatus to take an argument
| |
| 24 window.applicationCache.onCached.listen((_) => updateCacheStatus()); | 25 window.applicationCache.onCached.listen((_) => updateCacheStatus()); |
| 25 window.applicationCache.onChecking.listen((_) => updateCacheStatus()); | 26 window.applicationCache.onChecking.listen((_) => updateCacheStatus()); |
| 26 window.applicationCache.onDownloading.listen((_) => updateCacheStatus()); | 27 window.applicationCache.onDownloading.listen((_) => updateCacheStatus()); |
| 27 window.applicationCache.onError.listen((_) => updateCacheStatus()); | 28 window.applicationCache.onError.listen((_) => updateCacheStatus()); |
| 28 window.applicationCache.onNoUpdate.listen((_) => updateCacheStatus()); | 29 window.applicationCache.onNoUpdate.listen((_) => updateCacheStatus()); |
| 29 window.applicationCache.onObsolete.listen((_) => updateCacheStatus()); | 30 window.applicationCache.onObsolete.listen((_) => updateCacheStatus()); |
| 30 window.applicationCache.onProgress.listen(onCacheProgress); | 31 window.applicationCache.onProgress.listen(onCacheProgress); |
| 31 } | 32 } |
| 32 | 33 |
| 33 onCacheProgress(ProgressEvent event) { | 34 onCacheProgress(Event event) { |
|
kasperl
2014/05/06 04:42:22
I'd add a void here -- if nothing else then for co
ahe
2014/05/06 08:10:16
Done.
| |
| 34 if (!event.lengthComputable) { | 35 if (event is ProgressEvent) { |
| 35 updateCacheStatus(); | 36 // Firefox doesn't fire a ProgressEvent on cache progress. Just a plain |
| 36 return; | 37 // Event with type == "progress". |
| 38 if (event.lengthComputable) { | |
| 39 updateCacheStatusFromEvent(event); | |
| 40 return; | |
| 41 } | |
| 37 } | 42 } |
| 43 updateCacheStatus(); | |
| 44 } | |
| 45 | |
| 46 void updateCacheStatusFromEvent(ProgressEvent event) { | |
| 38 cacheStatusElement.nodes.clear(); | 47 cacheStatusElement.nodes.clear(); |
| 39 cacheStatusElement.appendText('Downloading SDK '); | 48 cacheStatusElement.appendText('Downloading SDK '); |
| 40 var progress = '${event.loaded} of ${event.total}'; | 49 var progress = '${event.loaded} of ${event.total}'; |
| 41 if (MeterElement.supported) { | 50 if (MeterElement.supported) { |
| 42 cacheStatusElement.append( | 51 cacheStatusElement.append( |
| 43 new MeterElement() | 52 new MeterElement() |
| 44 ..appendText(progress) | 53 ..appendText(progress) |
| 45 ..min = 0 | 54 ..min = 0 |
| 46 ..max = event.total | 55 ..max = event.total |
| 47 ..value = event.loaded); | 56 ..value = event.loaded); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 78 } else if (status == ApplicationCache.IDLE) { | 87 } else if (status == ApplicationCache.IDLE) { |
| 79 cacheStatusElement.appendText(cacheStatus()); | 88 cacheStatusElement.appendText(cacheStatus()); |
| 80 cacheStatusElement.classes.add('offlineyay'); | 89 cacheStatusElement.classes.add('offlineyay'); |
| 81 new Timer(const Duration(seconds: 10), () { | 90 new Timer(const Duration(seconds: 10), () { |
| 82 cacheStatusElement.style.display = 'none'; | 91 cacheStatusElement.style.display = 'none'; |
| 83 }); | 92 }); |
| 84 } else { | 93 } else { |
| 85 cacheStatusElement.appendText(cacheStatus()); | 94 cacheStatusElement.appendText(cacheStatus()); |
| 86 } | 95 } |
| 87 } | 96 } |
| OLD | NEW |