fix: Added serviceWorker env and fixed #19
This commit is contained in:
24
angular.json
24
angular.json
@@ -70,6 +70,30 @@
|
|||||||
"with": "src/environments/environment.development.ts"
|
"with": "src/environments/environment.development.ts"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"swDevelopment": {
|
||||||
|
"buildOptimizer": false,
|
||||||
|
"optimization": false,
|
||||||
|
"vendorChunk": true,
|
||||||
|
"extractLicenses": false,
|
||||||
|
"sourceMap": true,
|
||||||
|
"namedChunks": true,
|
||||||
|
"outputHashing": "all",
|
||||||
|
"fileReplacements": [
|
||||||
|
{
|
||||||
|
"replace": "src/environments/environment.ts",
|
||||||
|
"with": "src/environments/environment.swdev.ts"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"assets": [
|
||||||
|
{
|
||||||
|
"glob": "ngsw-worker.js",
|
||||||
|
"input": "node_modules/@angular/servce-worker",
|
||||||
|
"output": "."
|
||||||
|
},
|
||||||
|
"src/ngsw.json",
|
||||||
|
"src/manifest.webmanifest"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"defaultConfiguration": "production"
|
"defaultConfiguration": "production"
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
{
|
{
|
||||||
"$schema": "./node_modules/@angular/service-worker/config/schema.json",
|
"$schema": "./node_modules/@angular/service-worker/config/schema.json",
|
||||||
"index": "./index.html",
|
"index": "/ipwa/index.html",
|
||||||
"assetGroups": [
|
"assetGroups": [
|
||||||
{
|
{
|
||||||
"name": "app",
|
"name": "app",
|
||||||
"installMode": "prefetch",
|
"installMode": "prefetch",
|
||||||
"resources": {
|
"resources": {
|
||||||
"files": [
|
"files": [
|
||||||
"/favicon.ico",
|
"/ipwa/favicon.ico",
|
||||||
"/manifest.webmanifest",
|
"/ipwa/manifest.webmanifest",
|
||||||
"/*.css",
|
"/ipwa/*.css",
|
||||||
"/*.js"
|
"/ipwa/*.js"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -20,8 +20,8 @@
|
|||||||
"updateMode": "prefetch",
|
"updateMode": "prefetch",
|
||||||
"resources": {
|
"resources": {
|
||||||
"files": [
|
"files": [
|
||||||
"./assets/**",
|
"/ipwa/assets/**",
|
||||||
"/**/*.(svg|cur|jpg|jpeg|png|apng|webp|avif|gif|otf|ttf|woff|woff2)"
|
"/ipwa/**/*.(svg|cur|jpg|jpeg|png|apng|webp|avif|gif|otf|ttf|woff|woff2)"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ import { AttendenceComponent } from './admin-view/grades/attendence/attendence.c
|
|||||||
import { AttendenceSummaryComponent } from './admin-view/grades/attendence-summary/attendence-summary.component';
|
import { AttendenceSummaryComponent } from './admin-view/grades/attendence-summary/attendence-summary.component';
|
||||||
import { HourDisplayComponent } from './admin-view/grades/attendence-summary/hour-display/hour-display.component';
|
import { HourDisplayComponent } from './admin-view/grades/attendence-summary/hour-display/hour-display.component';
|
||||||
import { AboutComponent } from './app-view/personal/about/about.component';
|
import { AboutComponent } from './app-view/personal/about/about.component';
|
||||||
|
import { environment } from 'src/environments/environment';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [
|
declarations: [
|
||||||
@@ -160,7 +161,7 @@ import { AboutComponent } from './app-view/personal/about/about.component';
|
|||||||
A11yModule,
|
A11yModule,
|
||||||
MatAutocompleteModule,
|
MatAutocompleteModule,
|
||||||
ServiceWorkerModule.register('ngsw-worker.js', {
|
ServiceWorkerModule.register('ngsw-worker.js', {
|
||||||
enabled: !isDevMode(),
|
enabled: environment.production,
|
||||||
// Register the ServiceWorker as soon as the application is stable
|
// Register the ServiceWorker as soon as the application is stable
|
||||||
// or after 30 seconds (whichever comes first).
|
// or after 30 seconds (whichever comes first).
|
||||||
registrationStrategy: 'registerWhenStable:30000'
|
registrationStrategy: 'registerWhenStable:30000'
|
||||||
|
|||||||
@@ -8,7 +8,21 @@ import { catchError, concat, first, from, interval, tap, throwError } from 'rxjs
|
|||||||
})
|
})
|
||||||
export class AppUpdateService implements OnInit {
|
export class AppUpdateService implements OnInit {
|
||||||
|
|
||||||
constructor(readonly appRef: ApplicationRef, readonly update: SwUpdate, readonly sb: MatSnackBar) { }
|
constructor(readonly appRef: ApplicationRef, readonly update: SwUpdate, readonly sb: MatSnackBar) {
|
||||||
|
this.update.versionUpdates.subscribe((evt) => {
|
||||||
|
switch (evt.type) {
|
||||||
|
case 'VERSION_DETECTED':
|
||||||
|
console.log(`Downloading ${evt.version.hash}`);
|
||||||
|
break;
|
||||||
|
case 'VERSION_READY':
|
||||||
|
console.log(`Current: ${evt.currentVersion.hash}, new: ${evt.latestVersion.hash}`);
|
||||||
|
break;
|
||||||
|
case 'VERSION_INSTALLATION_FAILED':
|
||||||
|
console.error(`Failed to install ${evt.version.hash}: ${evt.error}`);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
const appIsStable = this.appRef.isStable.pipe(first(isStable => isStable === true))
|
const appIsStable = this.appRef.isStable.pipe(first(isStable => isStable === true))
|
||||||
|
|||||||
5
src/environments/environment.swdev.ts
Normal file
5
src/environments/environment.swdev.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
export const environment = {
|
||||||
|
apiEndpoint: `http://localhost:12230`,
|
||||||
|
version: "testing (swDev)",
|
||||||
|
production: true
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user