Merge pull request #1107 from Retrospring/fix/pwa-installability
Fix PWA installability
|
@ -1,10 +1,12 @@
|
||||||
import '@hotwired/turbo-rails';
|
import '@hotwired/turbo-rails';
|
||||||
import initializeBootstrap from './initializers/bootstrap';
|
import initializeBootstrap from './initializers/bootstrap';
|
||||||
|
import initializeServiceWorker from './initializers/serviceWorker';
|
||||||
import initializeStimulus from './initializers/stimulus';
|
import initializeStimulus from './initializers/stimulus';
|
||||||
|
|
||||||
export default function start(): void {
|
export default function start(): void {
|
||||||
try {
|
try {
|
||||||
initializeBootstrap();
|
initializeBootstrap();
|
||||||
|
initializeServiceWorker();
|
||||||
initializeStimulus();
|
initializeStimulus();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// initialization errors
|
// initialization errors
|
||||||
|
|
|
@ -8,7 +8,7 @@ export function enableHandler (event: Event): void {
|
||||||
const sender = event.target as HTMLButtonElement;
|
const sender = event.target as HTMLButtonElement;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
installServiceWorker()
|
getServiceWorker()
|
||||||
.then(subscribe)
|
.then(subscribe)
|
||||||
.then(async subscription => {
|
.then(async subscription => {
|
||||||
return Notification.requestPermission().then(permission => {
|
return Notification.requestPermission().then(permission => {
|
||||||
|
@ -51,8 +51,8 @@ export function enableHandler (event: Event): void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function installServiceWorker(): Promise<ServiceWorkerRegistration> {
|
async function getServiceWorker(): Promise<ServiceWorkerRegistration> {
|
||||||
return navigator.serviceWorker.register("/service_worker.js", { scope: "/" });
|
return navigator.serviceWorker.getRegistration("/");
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getServerKey(): Promise<Buffer> {
|
async function getServerKey(): Promise<Buffer> {
|
||||||
|
|
3
app/javascript/retrospring/initializers/serviceWorker.ts
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
export default function (): void {
|
||||||
|
navigator.serviceWorker.register("/service_worker.js", { scope: "/" });
|
||||||
|
}
|
Before ![]() (image error) Size: 0 B After ![]() (image error) Size: 13 KiB ![]() ![]() |
Before ![]() (image error) Size: 0 B After ![]() (image error) Size: 1.3 KiB ![]() ![]() |
Before ![]() (image error) Size: 4.7 KiB After ![]() (image error) Size: 1.4 KiB ![]() ![]() |
Before ![]() (image error) Size: 0 B After ![]() (image error) Size: 2 KiB ![]() ![]() |
Before ![]() (image error) Size: 0 B After ![]() (image error) Size: 4.3 KiB ![]() ![]() |
Before ![]() (image error) Size: 0 B After ![]() (image error) Size: 470 B ![]() ![]() |
Before ![]() (image error) Size: 0 B After ![]() (image error) Size: 6 KiB ![]() ![]() |
Before ![]() (image error) Size: 0 B After ![]() (image error) Size: 698 B ![]() ![]() |
Before ![]() (image error) Size: 0 B After ![]() (image error) Size: 928 B ![]() ![]() |