mirror of
https://github.com/SableClient/Sable.git
synced 2026-12-03 07:12:34 -08:00
fix: use resolved push transport state
This commit is contained in:
1 parent
9d1e7abef0
commit
ab1eb0efc4
5 files changed
+11
-46
No files matched your search
@@ -37,7 +37,6 @@ import {
|
||||
} from './PushNotifications';
|
||||
import { DeregisterAllPushersSetting } from './DeregisterPushNotifications';
|
||||
import {
|
||||
deriveLegacyPushFlags,
|
||||
disableNativePush,
|
||||
enableNativePush,
|
||||
getSupportedNotificationTransportModes,
|
||||
@@ -76,13 +75,6 @@ function getBackgroundPushPlatform(isTauriRuntime: boolean): BackgroundPushPlatf
|
||||
return 'desktop';
|
||||
}
|
||||
|
||||
function deriveLegacyPushSync(input: { enabled: boolean; provider: BackgroundPushKind | null }): {
|
||||
usePushNotifications: boolean;
|
||||
useUnifiedPush: boolean;
|
||||
} {
|
||||
return deriveLegacyPushFlags(input.enabled, input.provider);
|
||||
}
|
||||
|
||||
export async function switchBackgroundPushTransport(params: {
|
||||
previousKind: BackgroundPushKind | null;
|
||||
activate: () => Promise<BackgroundPushKind | null>;
|
||||
@@ -352,11 +344,6 @@ function BackgroundPushNotificationSetting() {
|
||||
);
|
||||
const [useRichPushPayloads] = useSetting(settingsAtom, 'useRichPushPayloads');
|
||||
const [pushNotifyUrlOverride] = useSetting(settingsAtom, 'pushNotifyUrlOverride');
|
||||
const [legacyPushNotifications, setLegacyPushNotifications] = useSetting(
|
||||
settingsAtom,
|
||||
'usePushNotifications'
|
||||
);
|
||||
const [legacyUnifiedPush, setLegacyUnifiedPush] = useSetting(settingsAtom, 'useUnifiedPush');
|
||||
const pushSubAtom = useAtom(pushSubscriptionAtom);
|
||||
const [upEndpoint, setUpEndpoint] = useAtom(unifiedPushEndpointAtom);
|
||||
const unifiedPushStateRef = useRef<UnifiedPushState>(upEndpoint);
|
||||
@@ -407,28 +394,6 @@ function BackgroundPushNotificationSetting() {
|
||||
unifiedPushStateRef.current = upEndpoint;
|
||||
}, [upEndpoint]);
|
||||
|
||||
useEffect(() => {
|
||||
const sync = deriveLegacyPushSync({
|
||||
enabled: backgroundPushEnabled,
|
||||
provider: backgroundPushEnabled ? (backgroundPushProvider ?? preferredKind) : null,
|
||||
});
|
||||
|
||||
if (legacyPushNotifications !== sync.usePushNotifications) {
|
||||
setLegacyPushNotifications(sync.usePushNotifications);
|
||||
}
|
||||
if (legacyUnifiedPush !== sync.useUnifiedPush) {
|
||||
setLegacyUnifiedPush(sync.useUnifiedPush);
|
||||
}
|
||||
}, [
|
||||
backgroundPushEnabled,
|
||||
backgroundPushProvider,
|
||||
preferredKind,
|
||||
legacyPushNotifications,
|
||||
legacyUnifiedPush,
|
||||
setLegacyPushNotifications,
|
||||
setLegacyUnifiedPush,
|
||||
]);
|
||||
|
||||
useEffect(() => {
|
||||
if (runtimePlatform !== 'android') {
|
||||
setAvailableDistributors([]);
|
||||
|
||||
@@ -14,7 +14,7 @@ const debugLog = createDebugLogger('AppVisibility');
|
||||
|
||||
export function useAppVisibility(mx: MatrixClient | undefined) {
|
||||
const clientConfig = useClientConfig();
|
||||
const [usePushNotifications] = useSetting(settingsAtom, 'usePushNotifications');
|
||||
const [backgroundPushEnabled] = useSetting(settingsAtom, 'backgroundPushEnabled');
|
||||
const pushSubAtom = useAtom(pushSubscriptionAtom);
|
||||
const isMobile = isMobileOrTablet();
|
||||
|
||||
@@ -43,12 +43,12 @@ export function useAppVisibility(mx: MatrixClient | undefined) {
|
||||
if (!mx) return undefined;
|
||||
|
||||
const handleVisibilityForNotifications = (isVisible: boolean) => {
|
||||
togglePusher(mx, clientConfig, isVisible, usePushNotifications, pushSubAtom, isMobile);
|
||||
togglePusher(mx, clientConfig, isVisible, backgroundPushEnabled, pushSubAtom, isMobile);
|
||||
};
|
||||
|
||||
appEvents.onVisibilityChange = handleVisibilityForNotifications;
|
||||
return () => {
|
||||
appEvents.onVisibilityChange = null;
|
||||
};
|
||||
}, [mx, clientConfig, usePushNotifications, pushSubAtom, isMobile]);
|
||||
}, [mx, clientConfig, backgroundPushEnabled, pushSubAtom, isMobile]);
|
||||
}
|
||||
@@ -141,14 +141,14 @@ export function BackgroundNotifications() {
|
||||
const sessions = useAtomValue(sessionsAtom);
|
||||
const [activeSessionId, setActiveSessionId] = useAtom(activeSessionIdAtom);
|
||||
const [showNotifications] = useSetting(settingsAtom, 'useInAppNotifications');
|
||||
const [usePushNotifications] = useSetting(settingsAtom, 'usePushNotifications');
|
||||
const [backgroundPushEnabled] = useSetting(settingsAtom, 'backgroundPushEnabled');
|
||||
const [notificationSound] = useSetting(settingsAtom, 'isNotificationSounds');
|
||||
const [showMessageContent] = useSetting(settingsAtom, 'showMessageContentInNotifications');
|
||||
const [showEncryptedMessageContent] = useSetting(
|
||||
settingsAtom,
|
||||
'showMessageContentInEncryptedNotifications'
|
||||
);
|
||||
const shouldRunBackgroundNotifications = showNotifications || usePushNotifications;
|
||||
const shouldRunBackgroundNotifications = showNotifications || backgroundPushEnabled;
|
||||
const nicknames = useAtomValue(nicknamesAtom);
|
||||
const nicknamesRef = useRef(nicknames);
|
||||
nicknamesRef.current = nicknames;
|
||||
|
||||
@@ -51,7 +51,7 @@ export function PageTitleUpdater() {
|
||||
|
||||
export function FaviconUpdater() {
|
||||
const roomToUnread = useAtomValue(roomToUnreadAtom);
|
||||
const [usePushNotifications] = useSetting(settingsAtom, 'usePushNotifications');
|
||||
const [backgroundPushEnabled] = useSetting(settingsAtom, 'backgroundPushEnabled');
|
||||
const [faviconForMentionsOnly] = useSetting(settingsAtom, 'faviconForMentionsOnly');
|
||||
const registration = useAtomValue(registrationAtom);
|
||||
|
||||
@@ -83,7 +83,7 @@ export function FaviconUpdater() {
|
||||
} else {
|
||||
navigator.clearAppBadge();
|
||||
}
|
||||
if (usePushNotifications && registration) {
|
||||
if (backgroundPushEnabled && registration) {
|
||||
if (total === 0) {
|
||||
// All rooms read — clear every notification.
|
||||
registration.getNotifications().then((notifs) => notifs.forEach((n) => n.close()));
|
||||
@@ -104,7 +104,7 @@ export function FaviconUpdater() {
|
||||
} catch {
|
||||
// Likely Firefox/Gecko-based and doesn't support badging API
|
||||
}
|
||||
}, [roomToUnread, usePushNotifications, registration, faviconForMentionsOnly]);
|
||||
}, [roomToUnread, backgroundPushEnabled, registration, faviconForMentionsOnly]);
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -80,7 +80,7 @@ export function InviteNotifications() {
|
||||
|
||||
const navigate = useNavigate();
|
||||
const [showSystemNotifications] = useSetting(settingsAtom, 'useSystemNotifications');
|
||||
const [usePushNotifications] = useSetting(settingsAtom, 'usePushNotifications');
|
||||
const [backgroundPushEnabled] = useSetting(settingsAtom, 'backgroundPushEnabled');
|
||||
const [notificationSound] = useSetting(settingsAtom, 'isNotificationSounds');
|
||||
const [backgroundNotificationSounds] = useSetting(settingsAtom, 'backgroundNotificationSounds');
|
||||
|
||||
@@ -128,7 +128,7 @@ export function InviteNotifications() {
|
||||
if (invites.length <= perviousInviteLen || mx.getSyncState() !== SyncState.Syncing) return;
|
||||
|
||||
// SW push (via Sygnal) handles invite notifications when the app is backgrounded.
|
||||
if (!isPageVisible() && usePushNotifications) return;
|
||||
if (!isPageVisible() && backgroundPushEnabled) return;
|
||||
|
||||
const withSound = notificationSound && (isWindowFocused() || backgroundNotificationSounds);
|
||||
let soundOnNotification = false;
|
||||
@@ -154,7 +154,7 @@ export function InviteNotifications() {
|
||||
invites,
|
||||
perviousInviteLen,
|
||||
showSystemNotifications,
|
||||
usePushNotifications,
|
||||
backgroundPushEnabled,
|
||||
notificationSound,
|
||||
backgroundNotificationSounds,
|
||||
notify,
|
||||
|
||||
Reference in new issue
Block a user