Skip to content

Commit

Permalink
Merge pull request #217 from drackp2m/dev
Browse files Browse the repository at this point in the history
✨ feat(app): add ServiceWorker on development environment
  • Loading branch information
drackp2m authored Nov 20, 2024
2 parents 4fbe29f + 5314017 commit 3d6368f
Show file tree
Hide file tree
Showing 9 changed files with 420 additions and 230 deletions.
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ JWT_ID=uuidgen
JWT_ALGORITHM=HS512
JWT_ISSUER=playsetonline
JWT_AUDIENCE=playsetonline
JWT_ACCESS_TOKEN_EXPIRES_IN=15m
JWT_REFRESH_TOKEN_EXPIRES_IN=30d
JWT_ACCESS_TOKEN_EXPIRES_IN=1d
JWT_REFRESH_TOKEN_EXPIRES_IN=15d
JWT_SECRET=secret
3 changes: 2 additions & 1 deletion apps/app/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
"replace": "apps/app/src/environments/environment.ts",
"with": "apps/app/src/environments/environment.development.ts"
}
]
],
"serviceWorker": "apps/app/src/ngsw-config.json"
}
},
"defaultConfiguration": "production"
Expand Down
6 changes: 3 additions & 3 deletions apps/app/src/app/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
ApplicationConfig,
computed,
inject,
isDevMode,
provideExperimentalCheckNoChangesForDebug,
provideExperimentalZonelessChangeDetection,
signal,
Expand Down Expand Up @@ -109,8 +108,9 @@ export const appConfig: ApplicationConfig = {
provideHttpClient(withInterceptorsFromDi()),
provideRouter(APP_ROUTES, withHashLocation()),
provideServiceWorker('ngsw-worker.js', {
enabled: !isDevMode(),
registrationStrategy: 'registerWhenStable:30000',
enabled: true, // !isDevMode(),
registrationStrategy: 'registerWhenStable:5000',
scope: '/',
}),
provideExperimentalZonelessChangeDetection(),
provideExperimentalCheckNoChangesForDebug({
Expand Down
2 changes: 1 addition & 1 deletion apps/app/src/app/layout/main/main.layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
class="round-sm p-xs px-sm"
[class]="active.isActive ? 'weight-xxl surface-serene' : 'surface-' + (surface || 'vivid')"
[routerLink]="link"
(click)="click ? click() : null"
(click)="click && click()"
>{{ text }}
</a>
</ng-template>
Expand Down
7 changes: 5 additions & 2 deletions apps/app/src/app/layout/main/main.layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ export default class MainLayout implements OnInit {
if (this.swUpdate.isEnabled) {
this.swUpdate.versionUpdates.subscribe({
next: (version) => {
console.log({ version });

switch (version.type) {
case 'VERSION_DETECTED':
alert('New version detected');
Expand All @@ -97,9 +99,10 @@ export default class MainLayout implements OnInit {
}
},
});
const haveUpdates = await this.swUpdate.checkForUpdate();

console.log({ haveUpdates });
// const haveUpdates = await this.swUpdate.checkForUpdate();

// console.log({ haveUpdates });
}
}
}
6 changes: 3 additions & 3 deletions apps/app/src/ngsw-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"installMode": "prefetch",
"updateMode": "lazy",
"resources": {
"files": ["/assets/**/*.(svg|png|woff2)"]
"files": ["/assets/**"]
}
}
],
Expand All @@ -31,10 +31,10 @@
"name": "api-call",
"urls": ["https://api.playsetonline.com"],
"cacheConfig": {
"maxAge": "12h",
"maxAge": "5m",
"maxSize": 10,
"strategy": "freshness",
"timeout": "5s"
"timeout": "1s"
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import nx from '@nx/eslint-plugin';
import tsParser from '@typescript-eslint/parser';
import eslintPluginImport from 'eslint-plugin-import';
import prettier from 'eslint-plugin-prettier';
import rxjs from 'eslint-plugin-rxjs-updated';
import unusedImports from 'eslint-plugin-unused-imports';
import globals from 'globals';
import rxjs from 'eslint-plugin-rxjs-updated';

export default [
...nx.configs['flat/base'],
Expand Down
Loading

0 comments on commit 3d6368f

Please sign in to comment.