2023-02-25 06:44:51 -08:00
|
|
|
import { Controller } from '@hotwired/stimulus';
|
|
|
|
|
|
|
|
export default class extends Controller<HTMLElement> {
|
|
|
|
isPwa: boolean;
|
|
|
|
badgeCapable: boolean;
|
|
|
|
|
|
|
|
initialize(): void {
|
|
|
|
this.isPwa = window.matchMedia('(display-mode: standalone)').matches;
|
|
|
|
this.badgeCapable = "setAppBadge" in navigator;
|
|
|
|
}
|
|
|
|
|
|
|
|
connect(): void {
|
|
|
|
if (this.isPwa && this.badgeCapable) {
|
2023-05-30 13:04:39 -07:00
|
|
|
const count = Number.parseInt(this.element.innerText) || 0;
|
2023-02-25 06:44:51 -08:00
|
|
|
navigator.setAppBadge(count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|