This repository has been archived by the owner on Nov 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
81 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
import { Component } from '@angular/core'; | ||
import { AuthService } from './services/auth.service'; | ||
import { PWAUpdateService } from './services/pwa/pwa-update.service'; | ||
|
||
@Component({ | ||
selector: 'app-root', | ||
templateUrl: 'app.component.html', | ||
styleUrls: ['app.component.scss'], | ||
}) | ||
export class AppComponent { | ||
constructor(private authService: AuthService) { | ||
constructor( | ||
private authService: AuthService, | ||
private pwaUpdateService: PWAUpdateService, | ||
) { | ||
this.pwaUpdateService.checkForUpdates(); | ||
this.authService.verify(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { HttpClientTestingModule } from '@angular/common/http/testing'; | ||
import { TestBed } from '@angular/core/testing'; | ||
import { ServiceWorkerModule } from '@angular/service-worker'; | ||
|
||
import { PWAUpdateService } from './pwa-update.service'; | ||
|
||
describe('PWAUpdateService', () => { | ||
let service: PWAUpdateService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
ServiceWorkerModule.register('ngsw-worker.js', { enabled: false }), | ||
], | ||
}); | ||
service = TestBed.inject(PWAUpdateService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { SwUpdate } from '@angular/service-worker'; | ||
import { AlertController } from '@ionic/angular'; | ||
import { interval } from 'rxjs'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class PWAUpdateService { | ||
constructor( | ||
private swUpdate: SwUpdate, | ||
private alertController: AlertController, | ||
) {} | ||
|
||
public checkForUpdates(): void { | ||
if (this.swUpdate.isEnabled) { | ||
this.swUpdate.available.subscribe((event) => this.promptUser()); | ||
|
||
interval(60 * 60 * 1000).subscribe(async () => { | ||
await this.swUpdate.checkForUpdate(); | ||
}); | ||
} | ||
} | ||
|
||
private promptUser(): void { | ||
this.swUpdate.activateUpdate().then(async () => { | ||
await this.alertController.create({ | ||
header: 'May panibagong update ang app', | ||
subHeader: '', | ||
backdropDismiss: false, | ||
message: | ||
'Kailangan i-refresh ang app para makuha ang panibagong updates', | ||
buttons: [ | ||
{ | ||
text: 'Update', | ||
handler: () => { | ||
this.installUpdate(); | ||
}, | ||
}, | ||
], | ||
}); | ||
}); | ||
} | ||
|
||
private installUpdate(): void { | ||
window.location.reload(); | ||
} | ||
} |