From 267f4445aeb1dfcacc526200c218f37dbb76b526 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Tue, 20 Apr 2021 08:31:54 +0200 Subject: [PATCH] MOBILE-3641 core: Register site info cron handler --- src/app/app.module.ts | 12 +++++++++++- src/core/services/handlers/site-info-cron.ts | 7 +++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/app/app.module.ts b/src/app/app.module.ts index fed9d6f73..238f24992 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { COMPILER_OPTIONS, NgModule } from '@angular/core'; +import { APP_INITIALIZER, COMPILER_OPTIONS, NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { RouteReuseStrategy } from '@angular/router'; @@ -29,6 +29,8 @@ import { AddonsModule } from '@/addons/addons.module'; import { AppComponent } from './app.component'; import { AppRoutingModule } from './app-routing.module'; import { JitCompilerFactory } from '@angular/platform-browser-dynamic'; +import { CoreCronDelegate } from '@services/cron'; +import { CoreSiteInfoCronHandler } from '@services/handlers/site-info-cron'; // For translate loader. AoT requires an exported function for factories. export function createTranslateLoader(http: HttpClient): TranslateHttpLoader { @@ -57,6 +59,14 @@ export function createTranslateLoader(http: HttpClient): TranslateHttpLoader { { provide: RouteReuseStrategy, useClass: IonicRouteStrategy }, { provide: COMPILER_OPTIONS, useValue: {}, multi: true }, { provide: JitCompilerFactory, useClass: JitCompilerFactory, deps: [COMPILER_OPTIONS] }, + { + provide: APP_INITIALIZER, + multi: true, + deps: [], + useFactory: () => () => { + CoreCronDelegate.register(CoreSiteInfoCronHandler.instance); + }, + }, ], bootstrap: [AppComponent], }) diff --git a/src/core/services/handlers/site-info-cron.ts b/src/core/services/handlers/site-info-cron.ts index 6a066f30c..9e55a85a6 100644 --- a/src/core/services/handlers/site-info-cron.ts +++ b/src/core/services/handlers/site-info-cron.ts @@ -15,12 +15,13 @@ import { Injectable } from '@angular/core'; import { CoreCronHandler } from '@services/cron'; import { CoreSites } from '@services/sites'; +import { makeSingleton } from '@singletons'; /** * Cron handler to update site info every certain time. */ -@Injectable() -export class CoreSiteInfoCronHandler implements CoreCronHandler { +@Injectable({ providedIn: 'root' }) +export class CoreSiteInfoCronHandlerService implements CoreCronHandler { name = 'CoreSiteInfoCronHandler'; @@ -60,3 +61,5 @@ export class CoreSiteInfoCronHandler implements CoreCronHandler { } } + +export const CoreSiteInfoCronHandler = makeSingleton(CoreSiteInfoCronHandlerService);