Default web push to enabled on PWAs
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import db from "./db";
|
import db from "./db";
|
||||||
|
import { isLaunchedPWA } from "./utils";
|
||||||
|
|
||||||
class Prefs {
|
class Prefs {
|
||||||
constructor(dbImpl) {
|
constructor(dbImpl) {
|
||||||
@@ -34,7 +35,7 @@ class Prefs {
|
|||||||
|
|
||||||
async webPushEnabled() {
|
async webPushEnabled() {
|
||||||
const webPushEnabled = await this.db.prefs.get("webPushEnabled");
|
const webPushEnabled = await this.db.prefs.get("webPushEnabled");
|
||||||
return webPushEnabled?.value ?? false;
|
return webPushEnabled?.value ?? isLaunchedPWA();
|
||||||
}
|
}
|
||||||
|
|
||||||
async setWebPushEnabled(enabled) {
|
async setWebPushEnabled(enabled) {
|
||||||
|
|||||||
@@ -263,3 +263,16 @@ export const urlB64ToUint8Array = (base64String) => {
|
|||||||
}
|
}
|
||||||
return outputArray;
|
return outputArray;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const isLaunchedPWA = () => {
|
||||||
|
if (window.matchMedia("(display-mode: standalone)").matches) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// iOS
|
||||||
|
if (window.navigator.standalone === true) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ import { Info } from "@mui/icons-material";
|
|||||||
import { useOutletContext } from "react-router-dom";
|
import { useOutletContext } from "react-router-dom";
|
||||||
import theme from "./theme";
|
import theme from "./theme";
|
||||||
import userManager from "../app/UserManager";
|
import userManager from "../app/UserManager";
|
||||||
import { playSound, shuffle, sounds, validUrl } from "../app/utils";
|
import { isLaunchedPWA, playSound, shuffle, sounds, validUrl } from "../app/utils";
|
||||||
import session from "../app/Session";
|
import session from "../app/Session";
|
||||||
import routes from "./routes";
|
import routes from "./routes";
|
||||||
import accountApi, { Permission, Role } from "../app/AccountApi";
|
import accountApi, { Permission, Role } from "../app/AccountApi";
|
||||||
@@ -86,7 +86,7 @@ const Notifications = () => {
|
|||||||
<Sound />
|
<Sound />
|
||||||
<MinPriority />
|
<MinPriority />
|
||||||
<DeleteAfter />
|
<DeleteAfter />
|
||||||
{notifier.pushPossible() && <WebPushEnabled />}
|
{!isLaunchedPWA() && notifier.pushPossible() && <WebPushEnabled />}
|
||||||
</PrefGroup>
|
</PrefGroup>
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user