Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cold-push-observability.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
default: patch
---

Make notifications more reliable when the app is closed on Android: the push is decrypted inside a short-lived foreground service instead of being cut short by battery saving.
2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ windows = { version = "0.62", features = [
tauri-plugin-single-instance = { version = "2.4.3", features = ["deep-link"] }

[target.'cfg(any(windows, target_os = "linux"))'.dependencies]
tauri-plugin-notifications = { git = "https://github.com/SableClient/tauri-plugin-notifications.git", rev = "302944f44e0a876b39a37e4f08741379202bbdd4" }
tauri-plugin-notifications = { git = "https://github.com/SableClient/tauri-plugin-notifications.git", rev = "d06bc72dae599174ffa6d57c72c3a0d652346507" }

# default-features = false drops notify-rust so macOS uses the native
# UNUserNotificationCenter backend (needs a signed .app to deliver).
[target.'cfg(target_os = "macos")'.dependencies]
tauri-plugin-notifications = { git = "https://github.com/SableClient/tauri-plugin-notifications.git", rev = "302944f44e0a876b39a37e4f08741379202bbdd4", default-features = false }
tauri-plugin-notifications = { git = "https://github.com/SableClient/tauri-plugin-notifications.git", rev = "d06bc72dae599174ffa6d57c72c3a0d652346507", default-features = false }

[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
tauri-plugin-updater = { version = "2", optional = true }
Expand All @@ -138,7 +138,7 @@ libloading = "0.9"
zbus = "5"

[target.'cfg(any(target_os = "android", target_os = "ios"))'.dependencies]
tauri-plugin-notifications = { git = "https://github.com/SableClient/tauri-plugin-notifications.git", rev = "302944f44e0a876b39a37e4f08741379202bbdd4", features = [
tauri-plugin-notifications = { git = "https://github.com/SableClient/tauri-plugin-notifications.git", rev = "d06bc72dae599174ffa6d57c72c3a0d652346507", features = [
"push-notifications",
] }
tauri-plugin-edge-to-edge = { git = "https://github.com/SableClient/tauri-plugin-edge-to-edge.git", rev = "33c6116c27be28c06df5a9d02231ecc5fdeb93c5" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,23 @@ export async function setEncryptedContentAllowed(allowed: boolean): Promise<void
}
}

const TAKE_PUSH_DIAGNOSTICS = 'plugin:notifications|take_push_diagnostics';

export type PushDiagnostics = {
counts: Record<string, number>;
lastOutcome?: string;
lastAt: number;
};

export async function takePushDiagnostics(): Promise<PushDiagnostics | undefined> {
if (!isTauri()) return undefined;
try {
return await invoke<PushDiagnostics>(TAKE_PUSH_DIAGNOSTICS);
} catch {
return undefined;
}
}

export async function listenForUnifiedPushMessages(getSettings: () => NotificationSettings) {
const dispatch = createUnifiedPushMessageListener(
(notification) => handleUnifiedPushPayload(notification, getSettings),
Expand Down
39 changes: 39 additions & 0 deletions src/app/hooks/usePushDiagnosticsReport.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { useEffect } from 'react';
import * as Sentry from '@sentry/react';
import { takePushDiagnostics } from '$features/settings/notifications/UnifiedPushNotifications';
import { isMobileTauri } from '$utils/platform';

const report = async (): Promise<void> => {
const diagnostics = await takePushDiagnostics();
if (!diagnostics) return;

const entries = Object.entries(diagnostics.counts);
if (entries.length === 0) return;

entries.forEach(([outcome, occurrences]) => {
Sentry.metrics.count('sable.push.cold_outcome', occurrences, { attributes: { outcome } });
});

Sentry.addBreadcrumb({
category: 'notification',
message: 'Cold push outcomes since last report',
level: 'info',
data: { ...diagnostics.counts, lastOutcome: diagnostics.lastOutcome },
});
};

export const usePushDiagnosticsReport = (): void => {
useEffect(() => {
if (!isMobileTauri()) return undefined;

const drain = () => {
if (document.visibilityState === 'hidden') return;
void report();
};

document.addEventListener('visibilitychange', drain);
drain();

return () => document.removeEventListener('visibilitychange', drain);
}, []);
};
2 changes: 2 additions & 0 deletions src/app/pages/client/ClientRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { useAppVisibility } from '$hooks/useAppVisibility';
import { useNetworkRecovery } from '$hooks/useNetworkRecovery';
import { useLoopbackMediaRecovery } from '$hooks/useLoopbackMediaRecovery';
import { useSyncOrchestrator } from '$hooks/useSyncOrchestrator';
import { usePushDiagnosticsReport } from '$hooks/usePushDiagnosticsReport';
import { composerIcon, DotsThreeOutlineVerticalIcon } from '$components/icons/phosphor';
import { getHomePath } from '$pages/pathUtils';
import { DIRECT_ROOM_PATH, HOME_ROOM_PATH, SPACE_ROOM_PATH } from '$pages/paths';
Expand Down Expand Up @@ -374,6 +375,7 @@ export function ClientRoot({ children }: ClientRootProps) {
useAppVisibility(mx);
useNetworkRecovery(mx);
useSyncOrchestrator(startState.status === AsyncStatus.Success ? mx : undefined);
usePushDiagnosticsReport();
useLoopbackMediaRecovery();
useCrossSigningResetDetect(mx);

Expand Down
Loading