Showing the changes to assets/javascripts (1 of 2 files). Show all
Unified · Split
| @@ -6,7 +6,6 @@ class app.ServiceWorker · 5 unmodified lines | |||
| 6 | 6 | ||
| 7 | constructor: -> | 7 | constructor: -> |
| 8 | @registration = null | 8 | @registration = null |
| 9 | @installingRegistration = null | ||
| 10 | @notifyUpdate = true | 9 | @notifyUpdate = true |
| 11 | 10 | ||
| 12 | navigator.serviceWorker.register(app.config.service_worker_path, {scope: '/'}) | 11 | navigator.serviceWorker.register(app.config.service_worker_path, {scope: '/'}) |
| @@ -16,37 +15,30 @@ class app.ServiceWorker · 3 unmodified lines | |||
| 16 | update: -> | 15 | update: -> |
| 17 | return unless @registration | 16 | return unless @registration |
| 18 | @notifyUpdate = true | 17 | @notifyUpdate = true |
| 19 | return @doUpdate() | 18 | return @registration.update().catch(->) |
| 20 | 19 | ||
| 21 | updateInBackground: -> | 20 | updateInBackground: -> |
| 22 | return unless @registration | 21 | return unless @registration |
| 23 | @notifyUpdate = false | 22 | @notifyUpdate = false |
| 24 | return @doUpdate() | 23 | return @registration.update().catch(->) |
| 25 | 24 | ||
| 26 | reload: -> | 25 | reload: -> |
| 27 | return @updateInBackground().then(() -> app.reboot()) | 26 | return @updateInBackground().then(() -> app.reboot()) |
| 28 | 27 | ||
| 29 | doUpdate: -> | ||
| 30 | return @registration.update().catch(->) | ||
| 31 | |||
| 32 | updateRegistration: (registration) -> | 28 | updateRegistration: (registration) -> |
| 33 | $.off @registration, 'updatefound', @onUpdateFound if @registration | ||
| 34 | $.off @installingRegistration, 'statechange', @onStateChange if @installingRegistration | ||
| 35 | |||
| 36 | @registration = registration | 29 | @registration = registration |
| 37 | @installingRegistration = null | ||
| 38 | |||
| 39 | $.on @registration, 'updatefound', @onUpdateFound | 30 | $.on @registration, 'updatefound', @onUpdateFound |
| 40 | return | 31 | return |
| 41 | 32 | ||
| 42 | onUpdateFound: () => | 33 | onUpdateFound: () => |
| 34 | $.off @installingRegistration, 'statechange', @onStateChange() if @installingRegistration | ||
| 43 | @installingRegistration = @registration.installing | 35 | @installingRegistration = @registration.installing |
| 44 | $.on @installingRegistration, 'statechange', @onStateChange | 36 | $.on @installingRegistration, 'statechange', @onStateChange |
| 45 | return | 37 | return |
| 46 | 38 | ||
| 47 | onStateChange: () => | 39 | onStateChange: () => |
| 48 | if @installingRegistration.state == 'installed' and navigator.serviceWorker.controller | 40 | if @installingRegistration and @installingRegistration.state == 'installed' and navigator.serviceWorker.controller |
| 49 | @updateRegistration(@installingRegistration) | 41 | @installingRegistration = null |
| 50 | @onUpdateReady() | 42 | @onUpdateReady() |
| 51 | return | 43 | return |
| 52 | 44 | ||