-
Notifications
You must be signed in to change notification settings - Fork 3
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
1 parent
069639d
commit ea3c29b
Showing
12 changed files
with
473 additions
and
229 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"$schema": "../../node_modules/@angular/service-worker/config/schema.json", | ||
"index": "/index.html", | ||
"assetGroups": [ | ||
{ | ||
"name": "app", | ||
"installMode": "prefetch", | ||
"resources": { | ||
"files": [ | ||
"/favicon.ico", | ||
"/index.html", | ||
"/manifest.webmanifest", | ||
"/*.css", | ||
"/*.js" | ||
] | ||
} | ||
}, | ||
{ | ||
"name": "assets", | ||
"installMode": "lazy", | ||
"updateMode": "prefetch", | ||
"resources": { | ||
"files": [ | ||
"/assets/**", | ||
"/*.(svg|cur|jpg|jpeg|png|apng|webp|avif|gif|otf|ttf|woff|woff2)" | ||
] | ||
} | ||
} | ||
] | ||
} |
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
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,59 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { SwUpdate } from '@angular/service-worker'; | ||
import { DeepMocked, createMock } from '@golevelup/ts-jest'; | ||
import { Subject } from 'rxjs'; | ||
|
||
import { UpdateService } from './update.service'; | ||
|
||
describe('UpdateService', () => { | ||
let swUpdateMock: DeepMocked<SwUpdate>; | ||
let windowSpy: jest.SpyInstance; | ||
const versionUpdateSubject$ = new Subject(); | ||
|
||
beforeEach(() => { | ||
windowSpy = jest.spyOn(window, 'confirm'); | ||
swUpdateMock = createMock<SwUpdate>({ | ||
// eslint-disable-next-line rxjs/finnish | ||
versionUpdates: versionUpdateSubject$.asObservable(), | ||
}); | ||
TestBed.configureTestingModule({ | ||
providers: [ | ||
{ | ||
provide: SwUpdate, | ||
useValue: swUpdateMock, | ||
}, | ||
], | ||
}); | ||
TestBed.inject(UpdateService); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should ask for update permission when a new version is ready', () => | ||
new Promise<void>((done) => { | ||
swUpdateMock.versionUpdates.subscribe(() => { | ||
console.log('hi'); | ||
expect(windowSpy).toHaveBeenCalled(); | ||
done(); | ||
}); | ||
versionUpdateSubject$.next({ | ||
type: 'VERSION_READY', | ||
}); | ||
})); | ||
|
||
it('should reload page if permission given', () => { | ||
Object.defineProperty(window, 'location', { | ||
value: { reload: jest.fn(), hash: {} }, | ||
}); | ||
windowSpy.mockReturnValue(true); | ||
const reloadSpy = jest.spyOn(window.location, 'reload'); | ||
|
||
versionUpdateSubject$.next({ | ||
type: 'VERSION_READY', | ||
}); | ||
|
||
expect(reloadSpy).toHaveBeenCalled(); | ||
}); | ||
}); |
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,25 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { SwUpdate, type VersionReadyEvent } from '@angular/service-worker'; | ||
import { filter } from 'rxjs'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class UpdateService { | ||
constructor(swUpdate: SwUpdate) { | ||
// todo: create an interval to check for updates | ||
swUpdate.versionUpdates | ||
.pipe( | ||
filter((evt): evt is VersionReadyEvent => evt.type === 'VERSION_READY'), | ||
filter(() => this.askForUpdatePermission()), | ||
) | ||
.subscribe(() => window.location.reload()); | ||
} | ||
|
||
askForUpdatePermission(): boolean { | ||
// todo: this should be a non-blocking toast notification | ||
return confirm( | ||
'Eine neue Version von Kordis ist verfügbar. Möchten Sie die Seite neu laden?', | ||
); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
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 |
---|---|---|
|
@@ -6,6 +6,13 @@ | |
<base href="/" /> | ||
<meta content="width=device-width, initial-scale=1" name="viewport" /> | ||
<link href="favicon.ico" rel="icon" type="image/x-icon" /> | ||
<link href="manifest.webmanifest" rel="manifest" /> | ||
<meta content="#1976d2" name="theme-color" /> | ||
<meta content="noindex" name="robots" /> | ||
<meta | ||
content="Kordis Contributors, [email protected]" | ||
name="author" | ||
/> | ||
<script nonce="csp_nonce"> | ||
if (navigator.userAgent.indexOf('Chrome') < 0) { | ||
alert( | ||
|
@@ -15,6 +22,7 @@ | |
</script> | ||
</head> | ||
<body> | ||
<noscript>Bitte aktivieren Sie JavaScript um Kordis zu nutzen.</noscript> | ||
<kordis-root ngCspNonce="csp_nonce"></kordis-root> | ||
</body> | ||
</html> |
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,23 @@ | ||
{ | ||
"name": "Kordis - Koordinierungssoftware für Einsatzleitstellen", | ||
"short_name": "Kordis", | ||
"theme_color": "#1890ff", | ||
"background_color": "#fafafa", | ||
"display": "standalone", | ||
"scope": "./", | ||
"start_url": "./", | ||
"icons": [ | ||
{ | ||
"src": "assets/icons/icon-192x192.png", | ||
"sizes": "192x192", | ||
"type": "image/png", | ||
"purpose": "maskable any" | ||
}, | ||
{ | ||
"src": "assets/icons/icon-512x512.png", | ||
"sizes": "512x512", | ||
"type": "image/png", | ||
"purpose": "maskable any" | ||
} | ||
] | ||
} |
Oops, something went wrong.