Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Handle Brave notification setup failures

Anand Baburajan386bc9b5d86f
diff --git a/web/apps/space/src/components/SpaceNotificationPermissionInstructions.tsx b/web/apps/space/src/components/SpaceNotificationPermissionInstructions.tsx
index d743d52e42..0b4d88539a 100644
--- a/web/apps/space/src/components/SpaceNotificationPermissionInstructions.tsx
+++ b/web/apps/space/src/components/SpaceNotificationPermissionInstructions.tsx
@@ -4,28 +4,39 @@ import { isSpaceIOS } from "hooks/useSpacePWAInstallPrompt";
import React from "react";
const green = "#08C225";
+const textBase = "#000";
+const textSoft = "#777777";
interface SpaceNotificationPermissionInstructionsProps {
+ mode?: "brave-push" | "permission";
onClose: () => void;
open: boolean;
}
export const SpaceNotificationPermissionInstructions: React.FC<
SpaceNotificationPermissionInstructionsProps
-> = ({ onClose, open }) => {
+> = ({ mode = "permission", onClose, open }) => {
const titleID = React.useId();
const isBottomSheet = useMediaQuery("(max-width: 599px)");
- const steps = isSpaceIOS()
+ const isBravePush = mode == "brave-push";
+ const steps = isBravePush
? [
- "Open Settings",
- 'Tap "Notifications"',
- 'Tap "Ente Space" and turn on "Allow Notifications"',
+ "Open Brave Settings",
+ 'Open "Privacy and security"',
+ 'Turn on "Use Google services for push messaging"',
+ "Return to Space and try again",
]
- : [
- "Open your browser's site settings for Space",
- 'Find "Notifications"',
- 'Choose "Allow"',
- ];
+ : isSpaceIOS()
+ ? [
+ "Open Settings",
+ 'Tap "Notifications"',
+ 'Tap "Ente Space" and turn on "Allow Notifications"',
+ ]
+ : [
+ "Open your browser's site settings for Space",
+ 'Find "Notifications"',
+ 'Choose "Allow"',
+ ];
return (
<Dialog
@@ -42,74 +53,152 @@ export const SpaceNotificationPermissionInstructions: React.FC<
slotProps={{
paper: {
sx: {
+ bgcolor: "#FFFFFF",
borderRadius: "28px 28px 0 0",
bottom: 0,
+ boxShadow: "0 -18px 44px rgba(0, 0, 0, 0.18)",
+ boxSizing: "border-box",
+ left: 0,
m: 0,
+ maxWidth: "none",
p: "26px 20px calc(24px + env(safe-area-inset-bottom))",
position: "fixed",
width: "100vw",
"@media (min-width: 600px)": {
borderRadius: "20px",
bottom: "auto",
+ boxShadow: "0 18px 48px rgba(0, 0, 0, 0.18)",
left: "50%",
maxWidth: 342,
p: "24px 20px 20px",
top: "50%",
transform: "translate(-50%, -50%)",
+ width: 342,
},
},
},
}}
>
<Box
- component="h2"
- id={titleID}
sx={{
- fontFamily: '"Inter Variable", Inter, sans-serif',
- fontSize: 16,
- fontWeight: 650,
- m: 0,
- textAlign: "center",
- }}
- >
- Turn on notifications
- </Box>
- <Box
- component="ol"
- sx={{
- color: "#555",
- display: "grid",
- fontFamily: '"Inter Variable", Inter, sans-serif',
- fontSize: 14,
- gap: "12px",
- lineHeight: "20px",
- my: "22px",
- pl: "28px",
- }}
- >
- {steps.map((step) => (
- <li key={step}>{step}</li>
- ))}
- </Box>
- <Box
- className="green-bg"
- component="button"
- type="button"
- onClick={onClose}
- sx={{
- bgcolor: green,
- border: 0,
- borderRadius: "20px",
- color: "#FFFFFF",
- cursor: "pointer",
- fontFamily: '"Inter Variable", Inter, sans-serif',
- fontSize: 14,
- fontWeight: 650,
- height: 48,
+ maxWidth: 320,
+ mx: "auto",
width: "100%",
+ "@media (min-width: 600px)": { maxWidth: "none" },
}}
>
- Got it
+ <Box
+ component="h2"
+ id={titleID}
+ sx={{
+ color: textBase,
+ fontFamily: '"Inter Variable", Inter, sans-serif',
+ fontSize: 15,
+ fontWeight: 600,
+ lineHeight: "20px",
+ m: 0,
+ px: "20px",
+ textAlign: "center",
+ }}
+ >
+ {isBravePush
+ ? "Turn on notifications in Brave"
+ : "Turn on notifications"}
+ </Box>
+ <Box
+ component="ol"
+ sx={{
+ display: "grid",
+ gap: "12px",
+ listStyle: "none",
+ mb: 0,
+ mt: "22px",
+ p: 0,
+ }}
+ >
+ {steps.map((step, index) => (
+ <Box
+ component="li"
+ key={step}
+ sx={{
+ alignItems: "center",
+ bgcolor: "#FAFAFA",
+ borderRadius: "18px",
+ color: textSoft,
+ display: "flex",
+ gap: "12px",
+ minHeight: 52,
+ px: "14px",
+ py: "10px",
+ }}
+ >
+ <Box
+ sx={{
+ alignItems: "center",
+ bgcolor: "#E7F6E9",
+ borderRadius: "14px",
+ color: green,
+ display: "flex",
+ flexShrink: 0,
+ fontFamily:
+ '"Inter Variable", Inter, sans-serif',
+ fontSize: 13,
+ fontWeight: 700,
+ height: 32,
+ justifyContent: "center",
+ width: 32,
+ }}
+ >
+ {index + 1}
+ </Box>
+ <Box
+ sx={{
+ fontFamily:
+ '"Inter Variable", Inter, sans-serif',
+ fontSize: 14,
+ fontWeight: 600,
+ lineHeight: "20px",
+ minWidth: 0,
+ }}
+ >
+ {step}
+ </Box>
+ </Box>
+ ))}
+ </Box>
+ <Box
+ className="green-bg"
+ component="button"
+ type="button"
+ onClick={onClose}
+ sx={{
+ alignItems: "center",
+ bgcolor: green,
+ border: 0,
+ borderRadius: "20px",
+ color: "#FFFFFF",
+ cursor: "pointer",
+ display: "flex",
+ fontFamily: '"Inter Variable", Inter, sans-serif',
+ fontSize: 14,
+ fontWeight: 600,
+ height: 48,
+ justifyContent: "center",
+ lineHeight: "20px",
+ mt: "24px",
+ px: "24px",
+ transition: "filter 120ms ease",
+ width: "100%",
+ "&:active": { filter: "brightness(0.96)" },
+ "&:focus-visible": {
+ outline: "2px solid rgba(0 0 0 / 0.72)",
+ outlineOffset: 2,
+ },
+ "&:hover": { filter: "brightness(0.98)" },
+ }}
+ >
+ Got it
+ </Box>
</Box>
</Dialog>
);
diff --git a/web/apps/space/src/components/SpacePWAInstallPrompt.tsx b/web/apps/space/src/components/SpacePWAInstallPrompt.tsx
index 4dabd0fd64..47290d7523 100644
--- a/web/apps/space/src/components/SpacePWAInstallPrompt.tsx
+++ b/web/apps/space/src/components/SpacePWAInstallPrompt.tsx
@@ -11,6 +11,7 @@ import {
import { HugeiconsIcon } from "@hugeicons/react";
import { Box, Dialog, useMediaQuery } from "@mui/material";
import { SpaceBottomSheetTransition } from "components/SpaceBottomSheetTransition";
+import { SpaceNotificationPermissionInstructions } from "components/SpaceNotificationPermissionInstructions";
import { useSpacePWAInstallPrompt } from "hooks/useSpacePWAInstallPrompt";
import { useSpaceWebPushPrompt } from "hooks/useSpaceWebPushPrompt";
import React from "react";
@@ -87,16 +88,28 @@ export const SpacePWAInstallPrompt: React.FC<SpacePWAInstallPromptProps> = ({
webPushPrompt.shouldShow,
]);
- const showWebPushPrompt =
+ const hasWebPushPrompt =
enabled && claimedPrompt == "webPush" && webPushPrompt.shouldShow;
- const showInstallPrompt =
+ const hasInstallPrompt =
enabled && claimedPrompt == "install" && installPrompt.shouldShow;
+ const notificationInstructionsOpen = webPushPrompt.needsBravePushMessaging;
+ const showWebPushPrompt =
+ hasWebPushPrompt && !instructionsOpen && !notificationInstructionsOpen;
+ const showInstallPrompt =
+ hasInstallPrompt && !instructionsOpen && !notificationInstructionsOpen;
React.useEffect(() => {
- if (!showInstallPrompt) setInstructionsOpen(false);
- }, [showInstallPrompt]);
+ if (!hasInstallPrompt) setInstructionsOpen(false);
+ }, [hasInstallPrompt]);
- if (!showWebPushPrompt && !showInstallPrompt) return null;
+ if (
+ !showWebPushPrompt &&
+ !showInstallPrompt &&
+ !instructionsOpen &&
+ !notificationInstructionsOpen
+ ) {
+ return null;
+ }
const addToHomeScreen = () => {
if (installPrompt.mode == "native") {
@@ -129,7 +142,7 @@ export const SpacePWAInstallPrompt: React.FC<SpacePWAInstallPromptProps> = ({
onAction={() => void webPushPrompt.enable()}
onDismiss={webPushPrompt.dismiss}
/>
- ) : (
+ ) : showInstallPrompt ? (
<SpacePWAPromptBanner
actionLabel="Add"
dismissLabel="Close install prompt"
@@ -138,13 +151,18 @@ export const SpacePWAInstallPrompt: React.FC<SpacePWAInstallPromptProps> = ({
onAction={addToHomeScreen}
onDismiss={installPrompt.dismiss}
/>
- )}
+ ) : null}
<SpacePWAInstallInstructions
mode={installPrompt.mode}
open={instructionsOpen}
onClose={closeInstructions}
onDismiss={dismissInstructions}
/>
+ <SpaceNotificationPermissionInstructions
+ mode="brave-push"
+ open={notificationInstructionsOpen}
+ onClose={webPushPrompt.clearBravePushMessagingError}
+ />
</>
);
};
diff --git a/web/apps/space/src/components/SpacePublicProfileNotificationControl.tsx b/web/apps/space/src/components/SpacePublicProfileNotificationControl.tsx
index 1ed6da25e4..5322f9ecef 100644
--- a/web/apps/space/src/components/SpacePublicProfileNotificationControl.tsx
+++ b/web/apps/space/src/components/SpacePublicProfileNotificationControl.tsx
@@ -17,6 +17,7 @@ import {
import React from "react";
import type { PublicSpaceLinkSession } from "services/space";
import {
+ isBravePushServiceError,
isSpaceWebPushSupported,
reconcilePublicSpaceWebPush,
subscribeToPublicSpaceWebPush,
@@ -46,6 +47,8 @@ export const SpacePublicProfileNotificationControl: React.FC<
React.useState(false);
const [permissionInstructionsOpen, setPermissionInstructionsOpen] =
React.useState(false);
+ const [needsBravePushMessaging, setNeedsBravePushMessaging] =
+ React.useState(false);
const route =
typeof window == "undefined"
? ""
@@ -105,14 +108,19 @@ export const SpacePublicProfileNotificationControl: React.FC<
const canShowNotifications =
!requiresIOSInstall && isSpaceWebPushSupported();
- const showNotificationAction =
+ const hasNotificationAction =
canShowNotifications &&
(updating.current ||
(!busy && state != "subscribed" && state != "unavailable"));
- const showInstallPrompt = requiresIOSInstall && installPrompt.shouldShow;
+ const hasInstallPrompt = requiresIOSInstall && installPrompt.shouldShow;
+ const instructionsOpen =
+ installInstructionsOpen || permissionInstructionsOpen;
+ const showNotificationAction = hasNotificationAction && !instructionsOpen;
+ const showInstallPrompt = hasInstallPrompt && !instructionsOpen;
const enable = async () => {
if (Notification.permission == "denied") {
+ setNeedsBravePushMessaging(false);
setPermissionInstructionsOpen(true);
return;
}
@@ -121,6 +129,7 @@ export const SpacePublicProfileNotificationControl: React.FC<
successTimer.current = undefined;
}
setSuccessState("hidden");
+ setNeedsBravePushMessaging(false);
updating.current = true;
setBusy(true);
try {
@@ -143,7 +152,15 @@ export const SpacePublicProfileNotificationControl: React.FC<
setPermissionInstructionsOpen(true);
}
} catch (error) {
- console.warn("Failed to update public Space notifications", error);
+ if (await isBravePushServiceError(error)) {
+ setNeedsBravePushMessaging(true);
+ setPermissionInstructionsOpen(true);
+ } else {
+ console.warn(
+ "Failed to update public Space notifications",
+ error,
+ );
+ }
setState("recovery");
} finally {
updating.current = false;
@@ -191,8 +208,12 @@ export const SpacePublicProfileNotificationControl: React.FC<
}}
/>
<SpaceNotificationPermissionInstructions
+ mode={needsBravePushMessaging ? "brave-push" : "permission"}
open={permissionInstructionsOpen}
- onClose={() => setPermissionInstructionsOpen(false)}
+ onClose={() => {
+ setPermissionInstructionsOpen(false);
+ setNeedsBravePushMessaging(false);
+ }}
/>
</>
);
diff --git a/web/apps/space/src/hooks/useSpaceWebPushPrompt.ts b/web/apps/space/src/hooks/useSpaceWebPushPrompt.ts
index 193f7958ab..1a7c9b99e5 100644
--- a/web/apps/space/src/hooks/useSpaceWebPushPrompt.ts
+++ b/web/apps/space/src/hooks/useSpaceWebPushPrompt.ts
@@ -1,6 +1,7 @@
import { isSpaceIOS, isSpaceStandalone } from "hooks/useSpacePWAInstallPrompt";
import React from "react";
import {
+ isBravePushServiceError,
isSpaceWebPushSupported,
reconcileSpaceWebPush,
subscribeToSpaceWebPush,
@@ -52,6 +53,8 @@ export const useSpaceWebPushPrompt = () => {
null,
);
const [needsRecovery, setNeedsRecovery] = React.useState(false);
+ const [needsBravePushMessaging, setNeedsBravePushMessaging] =
+ React.useState(false);
const [permissionDenied, setPermissionDenied] = React.useState(false);
const [status, setStatus] = React.useState<PromptStatus>("loading");
@@ -118,6 +121,7 @@ export const useSpaceWebPushPrompt = () => {
const enable = React.useCallback(async () => {
updating.current = true;
+ setNeedsBravePushMessaging(false);
setStatus("enabling");
try {
const permission = await subscribeToSpaceWebPush();
@@ -134,7 +138,11 @@ export const useSpaceWebPushPrompt = () => {
setStatus("hidden");
}
} catch (error) {
- console.warn("Failed to enable Space notifications", error);
+ if (await isBravePushServiceError(error)) {
+ setNeedsBravePushMessaging(true);
+ } else {
+ console.warn("Failed to enable Space notifications", error);
+ }
setStatus("error");
} finally {
updating.current = false;
@@ -158,12 +166,14 @@ export const useSpaceWebPushPrompt = () => {
}, [dismiss]);
return {
+ clearBravePushMessagingError: () => setNeedsBravePushMessaging(false),
dismiss,
enable,
isAvailable,
isEnabling: status == "enabling",
isResolved: status != "loading",
isSubscribed,
+ needsBravePushMessaging,
needsRecovery,
permissionDenied,
shouldShow: status == "ready" || status == "error",
diff --git a/web/apps/space/src/screens/SettingsScreen.tsx b/web/apps/space/src/screens/SettingsScreen.tsx
index 2b52d86a02..96b6945e72 100644
--- a/web/apps/space/src/screens/SettingsScreen.tsx
+++ b/web/apps/space/src/screens/SettingsScreen.tsx
@@ -392,6 +392,12 @@ export const SettingsScreen: React.FC<SettingsScreenProps> = ({
}
};
+ React.useEffect(() => {
+ if (webPushPrompt.needsBravePushMessaging) {
+ setNotificationInstructionsOpen(true);
+ }
+ }, [webPushPrompt.needsBravePushMessaging]);
+
return (
<Box
component="main"
@@ -587,8 +593,16 @@ export const SettingsScreen: React.FC<SettingsScreenProps> = ({
onDismiss={() => setInstallInstructionsOpen(false)}
/>
<SpaceNotificationPermissionInstructions
+ mode={
+ webPushPrompt.needsBravePushMessaging
+ ? "brave-push"
+ : "permission"
+ }
open={notificationInstructionsOpen}
- onClose={() => setNotificationInstructionsOpen(false)}
+ onClose={() => {
+ setNotificationInstructionsOpen(false);
+ webPushPrompt.clearBravePushMessagingError();
+ }}
/>
</Box>
);
diff --git a/web/apps/space/src/services/spaceWebPush.ts b/web/apps/space/src/services/spaceWebPush.ts
index db1f4ae763..7f58d6f02f 100644
--- a/web/apps/space/src/services/spaceWebPush.ts
+++ b/web/apps/space/src/services/spaceWebPush.ts
@@ -54,6 +54,22 @@ export const isSpaceWebPushSupported = () =>
"PushManager" in window &&
"indexedDB" in window;
+interface BraveNavigator extends Navigator {
+ brave?: { isBrave: () => Promise<boolean> };
+}
+
+export const isBravePushServiceError = async (error: unknown) => {
+ if (
+ !(error instanceof DOMException) ||
+ error.name != "AbortError" ||
+ !error.message.includes("push service error")
+ ) {
+ return false;
+ }
+ const brave = (navigator as BraveNavigator).brave;
+ return brave ? brave.isBrave() : false;
+};
+
export const registerSpaceServiceWorker = async () => {
if (typeof navigator == "undefined" || !("serviceWorker" in navigator)) {
return undefined;