merge master and improvements

This commit is contained in:
10G Meow 2024-03-09 11:15:48 +02:00
commit 7444891b6d
21 changed files with 748 additions and 208 deletions

View file

@ -1,17 +1,13 @@
import { isMobileOrTabletBrowser } from './utils'
// Installing your PWA is required for periodic syncs to work
const registerPeriodicBackgroundSync = async (registration) => {
// Check if periodicSync is supported
if ('periodicSync' in registration) {
// Request permission
const status = await navigator.permissions.query({
name: 'periodic-background-sync',
});
if (status.state === 'granted') {
console.log('PBS registered and granted')
console.log('Periodic background sync registered and granted')
try {
// Register the periodic background sync.
await registration.periodicSync.register('check-new-messages', {
// minInterval is one day
minInterval: 24 * 60 * 60 * 1000,
@ -19,11 +15,10 @@ const registerPeriodicBackgroundSync = async (registration) => {
console.log('Periodic background sync registered!');
console.log(registration.periodicSync.getTags())
// List registered periodic background sync tags.
const tags = await registration.periodicSync.getTags();
if (tags.length) {
tags.forEach((tag) => {
console.log('tag')
console.log('tag name')
console.log(tag)
});
}
@ -39,15 +34,15 @@ const registerPeriodicBackgroundSync = async (registration) => {
}
export function registerServiceWorker() {
if ('serviceWorker' in navigator) {
window.addEventListener('load', async () => {
const registration = await navigator.serviceWorker.register("/sw.js");
console.log('Service worker registered for scope', registration.scope);
if(isMobileOrTabletBrowser) {
if("serviceWorker" in navigator) {
navigator.serviceWorker.register("./sw.js")
.then(async registration => {
console.log('Service Worker registered with scope:', registration.scope);
await registerPeriodicBackgroundSync(registration);
}
});
})
.catch(error => {
console.error('Service Worker registration failed:', error);
});
} else {
console.log("No Service Worker support!");
}

View file

@ -924,17 +924,6 @@ class Util {
});
}
isMobileOrTabletBrowser() {
// Regular expression to match common mobile and tablet browser user agent strings
const mobileTabletPattern = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini|Tablet|Mobile|CriOS/i;
// Get the user agent string
const userAgent = navigator.userAgent;
// Check if the user agent matches the pattern for mobile or tablet browsers
return mobileTabletPattern.test(userAgent);
}
getMatrixBaseUrl(user, config) {
if (user) {
const domain = User.domainPart(user.user_id);