@@ -21,8 +21,6 @@ import { delay } from './util/promise';
2121import { initMetrics } from './metrics' ;
2222import { appHistory } from './routing' ;
2323
24- import registerUpdateWorker , { ServiceWorkerNoSupportError } from 'service-worker-loader!./services/update-worker' ;
25-
2624import { HttpExchange } from './types' ;
2725
2826import { UiStore } from './model/ui/ui-store' ;
@@ -34,8 +32,11 @@ import { InterceptorStore } from './model/interception/interceptor-store';
3432import { ApiStore } from './model/api/api-store' ;
3533import { SendStore } from './model/send/send-store' ;
3634
37- import { triggerServerUpdate } from './services/server-api' ;
3835import { serverVersion , lastServerVersion , UI_VERSION } from './services/service-versions' ;
36+ import {
37+ attemptServerUpdate ,
38+ runBackgroundUpdates
39+ } from './services/update-management' ;
3940
4041import { App } from './components/app' ;
4142import { StorePoweredThemeProvider } from './components/store-powered-theme-provider' ;
@@ -47,31 +48,10 @@ const APP_ELEMENT_SELECTOR = '#app';
4748
4849mobx . configure ( { enforceActions : 'observed' } ) ;
4950
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 ) ;
7555
7656const accountStore = new AccountStore (
7757 ( ) => appHistory . navigate ( '/settings' )
@@ -121,7 +101,7 @@ initMetrics();
121101// Once the app is loaded, show the app
122102appStartupPromise . then ( ( ) => {
123103 // We now know that the server is running - tell it to check for updates
124- triggerServerUpdate ( ) ;
104+ attemptServerUpdate ( ) ;
125105
126106 console . log ( 'App started, rendering' ) ;
127107
0 commit comments