diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 9e8e8372a..446c2fd4e 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -11,6 +11,7 @@ import { NGX_MAT_DATE_FORMATS } from '@angular-material-components/datetime-pick import { SqliteService } from 'src/app/services/sqlite.service'; import { BackgroundService } from 'src/app/services/background.service'; import { ScreenOrientation } from '@ionic-native/screen-orientation/ngx'; +import { StorageService } from 'src/app/services/storage.service'; const CUSTOM_DATE_FORMATS: NgxMatDateFormats = { @@ -41,7 +42,8 @@ export class AppComponent { private statusBar: StatusBar, private screenOrientation: ScreenOrientation, private sqliteservice: SqliteService, - private backgroundservice: BackgroundService + private backgroundservice: BackgroundService, + private storageservice: StorageService ) { this.initializeApp(); } @@ -68,17 +70,15 @@ export class AppComponent { } } - window.addEventListener('online', () => { - console.log('Became online') - this.backgroundservice.online() - if (this.platform.is('desktop') || this.platform.is('mobileweb')) { + this.storageservice.get('networkCheckStore').then((network) => { + if(network === 'online') { + console.log('Network app componente check', network) + this.backgroundservice.online() } else { + console.log('Network app componente check', network) + this.backgroundservice.offline(); } - }); - window.addEventListener('offline', () => { - console.log('Became offline') - this.backgroundservice.offline() - }); + }) }); } diff --git a/src/app/services/background.service.ts b/src/app/services/background.service.ts index e1670c200..acd6153ec 100644 --- a/src/app/services/background.service.ts +++ b/src/app/services/background.service.ts @@ -1,5 +1,6 @@ import { Injectable } from '@angular/core'; import { ThemeService } from 'src/app/services/theme.service'; +import { StorageService} from 'src/app/services/storage.service'; @Injectable({ providedIn: 'root' @@ -13,7 +14,8 @@ export class BackgroundService { }[] = [] constructor( - private themeservice: ThemeService + private themeservice: ThemeService, + private storageservice: StorageService ) { } online() { @@ -24,6 +26,7 @@ export class BackgroundService { document.body.style.setProperty(`--color3`, "#d9d9d9"); document.body.style.setProperty(`--color4`, "#d9d9d9ee"); document.body.style.setProperty(`--color5`, "#ececec"); + this.storageservice.store('networkCheckStore','online'); } else { document.body.style.setProperty(`--color`, "#0782C9"); @@ -31,6 +34,7 @@ export class BackgroundService { document.body.style.setProperty(`--color3`, "#0782C9"); document.body.style.setProperty(`--color4`, "#0782c9f0"); document.body.style.setProperty(`--color5`, "#45BAFF"); + this.storageservice.store('networkCheckStore','online'); } this.callBacks.forEach((e) => { @@ -46,6 +50,7 @@ export class BackgroundService { document.body.style.setProperty(`--color3`, "#ffb703"); document.body.style.setProperty(`--color4`, "#ffb703"); document.body.style.setProperty(`--color5`, "#ffb703"); + this.storageservice.store('networkCheckStore','offline'); this.callBacks.forEach((e) => { if (e.type == 'Offline') { e.funx()