diff --git a/angular.json b/angular.json index b12491a..a835638 100644 --- a/angular.json +++ b/angular.json @@ -1,6 +1,6 @@ { "$schema": "./node_modules/@angular/cli/lib/config/schema.json", - "version": 1, + "version": 2.0, "newProjectRoot": "projects", "projects": { "lms-app-new": { diff --git a/src/app/app.component.ts b/src/app/app.component.ts index c910cbb..094676c 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,5 +1,5 @@ import { Component } from '@angular/core'; - +import { UpdateService } from './services/update.service'; @Component({ selector: 'app-root', @@ -7,9 +7,11 @@ import { Component } from '@angular/core'; styleUrls: ['./app.component.scss'] }) export class AppComponent { - constructor() { + constructor( + private updateService: UpdateService, + ) { if (!localStorage.demoType) { - localStorage.demoType = 'Teacher'; + localStorage.demoType = 'Student'; } } } diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 727adbf..d6be746 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -11,6 +11,7 @@ import { DragDropModule } from '@angular/cdk/drag-drop'; // Import services import { DemoService } from './services/demo.service'; +import { UpdateService } from './services/update.service'; // Component imports import { AppComponent } from './app.component'; @@ -85,7 +86,8 @@ import { QuestionComponent } from './tabs/courses/test/question-sheet/question/q ServiceWorkerModule.register('ngsw-worker.js', { enabled: environment.production }) ], providers: [ - DemoService + DemoService, + UpdateService ], bootstrap: [AppComponent] }) diff --git a/src/app/services/update.service.spec.ts b/src/app/services/update.service.spec.ts new file mode 100644 index 0000000..b51fcc8 --- /dev/null +++ b/src/app/services/update.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { UpdateService } from './update.service'; + +describe('UpdateService', () => { + let service: UpdateService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(UpdateService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/services/update.service.ts b/src/app/services/update.service.ts new file mode 100644 index 0000000..b76747b --- /dev/null +++ b/src/app/services/update.service.ts @@ -0,0 +1,29 @@ +import { Injectable } from '@angular/core'; +import { SwUpdate } from '@angular/service-worker'; + +@Injectable({ + providedIn: 'root' +}) +export class UpdateService { + + constructor(private swUpdate: SwUpdate) { + if (!this.swUpdate.isEnabled) { + console.log('Nope SW'); + } else { + this.swUpdate.checkForUpdate().then((ev) => { + console.log(ev); + }, (err) => { + console.log(err); + }); + } + + this.swUpdate.available.subscribe((evt: any) => { + this.presentToastWithOptions('Update Available'); + }); + } + + public async presentToastWithOptions(message: string) { + alert('New Update'); + location.reload(); + } +} diff --git a/src/app/welcome/welcome.component.ts b/src/app/welcome/welcome.component.ts index 5df0a3f..f458ce7 100644 --- a/src/app/welcome/welcome.component.ts +++ b/src/app/welcome/welcome.component.ts @@ -14,7 +14,7 @@ export class WelcomeComponent implements OnInit { private demoService: DemoService ) { } - ngOnInit(): void { + ngOnInit(): void { this.demoType = localStorage.demoType; if (this.demoType === 'Student') { this.classList = this.demoService.studentClassList;