@@ -21,8 +21,6 @@ import { delay } from './util/promise';
21
21
import { initMetrics } from './metrics' ;
22
22
import { appHistory } from './routing' ;
23
23
24
- import registerUpdateWorker , { ServiceWorkerNoSupportError } from 'service-worker-loader!./services/update-worker' ;
25
-
26
24
import { HttpExchange } from './types' ;
27
25
28
26
import { UiStore } from './model/ui/ui-store' ;
@@ -34,8 +32,11 @@ import { InterceptorStore } from './model/interception/interceptor-store';
34
32
import { ApiStore } from './model/api/api-store' ;
35
33
import { SendStore } from './model/send/send-store' ;
36
34
37
- import { triggerServerUpdate } from './services/server-api' ;
38
35
import { serverVersion , lastServerVersion , UI_VERSION } from './services/service-versions' ;
36
+ import {
37
+ attemptServerUpdate ,
38
+ runBackgroundUpdates
39
+ } from './services/update-management' ;
39
40
40
41
import { App } from './components/app' ;
41
42
import { StorePoweredThemeProvider } from './components/store-powered-theme-provider' ;
@@ -47,31 +48,10 @@ const APP_ELEMENT_SELECTOR = '#app';
47
48
48
49
mobx . configure ( { enforceActions : 'observed' } ) ;
49
50
50
- // Set up a SW in the background to add offline support & instant startup.
51
- // This also checks for new versions after the first SW is already live.
52
- // Slightly delayed to avoid competing for bandwidth with startup on slow connections.
53
- delay ( 5000 ) . then ( ( ) => {
54
- // Try to trigger a server update. Can't guarantee it'll work, and we also trigger
55
- // after successful startup, but this tries to ensure that even if startup is broken,
56
- // we still update the server (and hopefully thereby unbreak app startup).
57
- triggerServerUpdate ( ) ;
58
- return registerUpdateWorker ( { scope : '/' } ) ;
59
- } ) . then ( ( registration ) => {
60
- console . log ( 'Service worker loaded' ) ;
61
- registration . update ( ) . catch ( console . log ) ;
62
-
63
- // Check for SW updates every 5 minutes.
64
- setInterval ( ( ) => {
65
- triggerServerUpdate ( ) ;
66
- registration . update ( ) . catch ( console . log ) ;
67
- } , 1000 * 60 * 5 ) ;
68
- } )
69
- . catch ( ( e ) => {
70
- if ( e instanceof ServiceWorkerNoSupportError ) {
71
- console . log ( 'Service worker not supported, oh well, no autoupdating for you.' ) ;
72
- }
73
- throw e ;
74
- } ) ;
51
+ // Begin checking for updates and pre-caching UI components we might need, to support
52
+ // background updates & instant offline startup. We slightly delay this to avoid
53
+ // competing for bandwidth/CPU/etc with startup on slow connections.
54
+ delay ( 5000 ) . then ( runBackgroundUpdates ) ;
75
55
76
56
const accountStore = new AccountStore (
77
57
( ) => appHistory . navigate ( '/settings' )
@@ -121,7 +101,7 @@ initMetrics();
121
101
// Once the app is loaded, show the app
122
102
appStartupPromise . then ( ( ) => {
123
103
// We now know that the server is running - tell it to check for updates
124
- triggerServerUpdate ( ) ;
104
+ attemptServerUpdate ( ) ;
125
105
126
106
console . log ( 'App started, rendering' ) ;
127
107
0 commit comments