mirror of
https://github.com/4gray/iptvnator.git
synced 2026-10-10 18:36:15 -08:00
refactor: update service worker update method
This commit is contained in:
1 parent
1db1c991d9
commit
a5c805cd98
2 files changed
+15
-27
No files matched your search
@@ -2,14 +2,12 @@ import { HttpClient } from '@angular/common/http';
|
||||
import { ApplicationRef, inject, Injectable } from '@angular/core';
|
||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||
import { SwUpdate } from '@angular/service-worker';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { parse } from 'iptv-playlist-parser';
|
||||
import { NgxIndexedDBService } from 'ngx-indexed-db';
|
||||
import {
|
||||
catchError,
|
||||
combineLatest,
|
||||
concat,
|
||||
first,
|
||||
interval,
|
||||
map,
|
||||
of,
|
||||
switchMap,
|
||||
@@ -57,6 +55,7 @@ export class PwaService extends DataService {
|
||||
appRef = inject(ApplicationRef);
|
||||
snackBar = inject(MatSnackBar);
|
||||
swUpdate = inject(SwUpdate);
|
||||
translateService = inject(TranslateService);
|
||||
|
||||
/**
|
||||
* Creates an instance of PwaService.
|
||||
@@ -75,30 +74,17 @@ export class PwaService extends DataService {
|
||||
* Uses service worker mechanism to check for available application updates
|
||||
*/
|
||||
checkUpdates() {
|
||||
if (this.swUpdate.isEnabled) {
|
||||
const appIsStable$ = this.appRef.isStable.pipe(
|
||||
first((isStable) => isStable === true)
|
||||
);
|
||||
const everySixHours$ = interval(6 * 60 * 60 * 1000);
|
||||
const everySixHoursOnceAppIsStable$ = concat(
|
||||
appIsStable$,
|
||||
everySixHours$
|
||||
);
|
||||
|
||||
everySixHoursOnceAppIsStable$.subscribe(() => {
|
||||
this.swUpdate.checkForUpdate();
|
||||
});
|
||||
|
||||
this.swUpdate.versionUpdates.subscribe(() => {
|
||||
const snackBarRef = this.snackBar.open(
|
||||
'Update available',
|
||||
'Refresh'
|
||||
);
|
||||
snackBarRef.onAction().subscribe(() => {
|
||||
document.location.reload();
|
||||
this.swUpdate.versionUpdates.subscribe(() => {
|
||||
this.snackBar
|
||||
.open(
|
||||
this.translateService.instant('UPDATE_AVAILABLE'),
|
||||
this.translateService.instant('REFRESH')
|
||||
)
|
||||
.onAction()
|
||||
.subscribe(() => {
|
||||
window.location.reload();
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -149,5 +149,7 @@
|
||||
"TITLE": "About IPTVnator",
|
||||
"DESCRIPTION": "Cross-platform IPTV player application with multiple features, such as support of m3u and m3u8 playlists, favorites, TV guide, TV archive/catchup and more.",
|
||||
"VERSION": "Version"
|
||||
}
|
||||
},
|
||||
"UPDATE_AVAILABLE": "Update available",
|
||||
"REFRESH": "Refresh"
|
||||
}
|
||||
Reference in new issue
Block a user