mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 03:25:12 +01:00
add badge icon to notifs
This commit is contained in:
parent
0b3f2a7fa0
commit
165532be30
@ -278,6 +278,13 @@ async function buildServiceWorker(swSource, version, globalHash, assets) {
|
|||||||
}
|
}
|
||||||
return newSource;
|
return newSource;
|
||||||
};
|
};
|
||||||
|
const replaceStringInSource = (name, value) => {
|
||||||
|
const newSource = swSource.replace(new RegExp(`${name}\\s=\\s"[^"]*"`), `${name} = ${JSON.stringify(value)}`);
|
||||||
|
if (newSource === swSource) {
|
||||||
|
throw new Error(`${name} was not found in the service worker source`);
|
||||||
|
}
|
||||||
|
return newSource;
|
||||||
|
};
|
||||||
|
|
||||||
// write service worker
|
// write service worker
|
||||||
swSource = swSource.replace(`"%%VERSION%%"`, `"${version}"`);
|
swSource = swSource.replace(`"%%VERSION%%"`, `"${version}"`);
|
||||||
@ -285,6 +292,8 @@ async function buildServiceWorker(swSource, version, globalHash, assets) {
|
|||||||
swSource = replaceArrayInSource("UNHASHED_PRECACHED_ASSETS", unhashedPreCachedAssets);
|
swSource = replaceArrayInSource("UNHASHED_PRECACHED_ASSETS", unhashedPreCachedAssets);
|
||||||
swSource = replaceArrayInSource("HASHED_PRECACHED_ASSETS", hashedPreCachedAssets);
|
swSource = replaceArrayInSource("HASHED_PRECACHED_ASSETS", hashedPreCachedAssets);
|
||||||
swSource = replaceArrayInSource("HASHED_CACHED_ON_REQUEST_ASSETS", hashedCachedOnRequestAssets);
|
swSource = replaceArrayInSource("HASHED_CACHED_ON_REQUEST_ASSETS", hashedCachedOnRequestAssets);
|
||||||
|
swSource = replaceStringInSource("NOTIFICATION_BADGE_ICON", assets.resolve("icon.png"));
|
||||||
|
|
||||||
// service worker should not have a hashed name as it is polled by the browser for updates
|
// service worker should not have a hashed name as it is polled by the browser for updates
|
||||||
await assets.writeUnhashed("sw.js", swSource);
|
await assets.writeUnhashed("sw.js", swSource);
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ const GLOBAL_HASH = "%%GLOBAL_HASH%%";
|
|||||||
const UNHASHED_PRECACHED_ASSETS = [];
|
const UNHASHED_PRECACHED_ASSETS = [];
|
||||||
const HASHED_PRECACHED_ASSETS = [];
|
const HASHED_PRECACHED_ASSETS = [];
|
||||||
const HASHED_CACHED_ON_REQUEST_ASSETS = [];
|
const HASHED_CACHED_ON_REQUEST_ASSETS = [];
|
||||||
|
const NOTIFICATION_BADGE_ICON = "assets/icon.png";
|
||||||
const unhashedCacheName = `hydrogen-assets-${GLOBAL_HASH}`;
|
const unhashedCacheName = `hydrogen-assets-${GLOBAL_HASH}`;
|
||||||
const hashedCacheName = `hydrogen-assets`;
|
const hashedCacheName = `hydrogen-assets`;
|
||||||
const mediaThumbnailCacheName = `hydrogen-media-thumbnails-v2`;
|
const mediaThumbnailCacheName = `hydrogen-media-thumbnails-v2`;
|
||||||
@ -261,6 +262,7 @@ async function handlePushNotification(n) {
|
|||||||
body,
|
body,
|
||||||
data: {sessionId, roomId},
|
data: {sessionId, roomId},
|
||||||
tag: NOTIF_TAG_NEW_MESSAGE
|
tag: NOTIF_TAG_NEW_MESSAGE
|
||||||
|
badge: NOTIFICATION_BADGE_ICON
|
||||||
});
|
});
|
||||||
} else if (n.unread === 0) {
|
} else if (n.unread === 0) {
|
||||||
// hide the notifs
|
// hide the notifs
|
||||||
|
Loading…
Reference in New Issue
Block a user