File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -31,6 +31,12 @@ declare global {
3131 // https://developer.mozilla.org/en-US/docs/Web/API/InstallTrigger
3232 InstallTrigger : any ;
3333 }
34+
35+ interface Navigator {
36+ // PWA badging extensions https://w3c.github.io/badging/
37+ setAppBadge ?( count : number ) : Promise < void > ;
38+ clearAppBadge ?( ) : Promise < void > ;
39+ }
3440}
3541
3642// add method which is missing from the node typing
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ import * as React from "react";
2626import * as languageHandler from "matrix-react-sdk/src/languageHandler" ;
2727import SettingsStore from "matrix-react-sdk/src/settings/SettingsStore" ;
2828import ElectronPlatform from "./platform/ElectronPlatform" ;
29+ import PWAPlatform from "./platform/PWAPlatform" ;
2930import WebPlatform from "./platform/WebPlatform" ;
3031import PlatformPeg from "matrix-react-sdk/src/PlatformPeg" ;
3132import SdkConfig from "matrix-react-sdk/src/SdkConfig" ;
@@ -39,8 +40,10 @@ export const rageshakePromise = initRageshake();
3940export function preparePlatform ( ) {
4041 if ( window . ipcRenderer ) {
4142 console . log ( "Using Electron platform" ) ;
42- const plaf = new ElectronPlatform ( ) ;
43- PlatformPeg . set ( plaf ) ;
43+ PlatformPeg . set ( new ElectronPlatform ( ) ) ;
44+ } else if ( window . matchMedia ( '(display-mode: standalone)' ) . matches ) {
45+ console . log ( "Using PWA platform" ) ;
46+ PlatformPeg . set ( new PWAPlatform ( ) ) ;
4447 } else {
4548 console . log ( "Using Web platform" ) ;
4649 PlatformPeg . set ( new WebPlatform ( ) ) ;
Original file line number Diff line number Diff line change 1+ /*
2+ Copyright 2020 New Vector Ltd
3+
4+ Licensed under the Apache License, Version 2.0 (the "License");
5+ you may not use this file except in compliance with the License.
6+ You may obtain a copy of the License at
7+
8+ http://www.apache.org/licenses/LICENSE-2.0
9+
10+ Unless required by applicable law or agreed to in writing, software
11+ distributed under the License is distributed on an "AS IS" BASIS,
12+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ See the License for the specific language governing permissions and
14+ limitations under the License.
15+ */
16+
17+ import WebPlatform from "./WebPlatform" ;
18+
19+ export default class PWAPlatform extends WebPlatform {
20+ setNotificationCount ( count : number ) {
21+ if ( ! navigator . setAppBadge ) return super . setNotificationCount ( count ) ;
22+ if ( this . notificationCount === count ) return ;
23+ this . notificationCount = count ;
24+
25+ navigator . setAppBadge ( count ) . catch ( e => {
26+ console . error ( "Failed to update PWA app badge" , e ) ;
27+ } ) ;
28+ }
29+ }
You can’t perform that action at this time.
0 commit comments