mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-30 05:42:44 -08:00
fix: harden mobile push delivery (#1488)
<!-- Please read https://github.com/SableClient/Sable/blob/dev/CONTRIBUTING.md before submitting your pull request --> ### Description improve reliability of notifications #### Type of change - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update ### Checklist: - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings ### AI disclosure: - [ ] Partially AI assisted (clarify which code was AI assisted and briefly explain what it does). - [ ] Fully AI generated (explain what all the generated code does in moderate detail). <!-- Write any explanation required here, but do not generate the explanation using AI!! You must prove you understand what the code in this PR does. -->
This commit is contained in:
4 files changed
+97
-30
No files matched your search
Generated
+22
-22
@@ -168,7 +168,7 @@ version = "1.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc"
|
||||
dependencies = [
|
||||
"windows-sys 0.60.2",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -179,7 +179,7 @@ checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"once_cell_polyfill",
|
||||
"windows-sys 0.60.2",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1011,7 +1011,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "117725a109d387c937a1533ce01b450cbde6b88abceea8473c4d7a85853cda3c"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"windows-sys 0.48.0",
|
||||
"windows-sys 0.59.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1553,7 +1553,7 @@ dependencies = [
|
||||
"libc",
|
||||
"option-ext",
|
||||
"redox_users",
|
||||
"windows-sys 0.60.2",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1585,7 +1585,7 @@ version = "0.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ab8ecd87370524b461f8557c119c405552c396ed91fc0a8eec68679eab26f94a"
|
||||
dependencies = [
|
||||
"libloading 0.7.4",
|
||||
"libloading 0.8.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1855,7 +1855,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"windows-sys 0.60.2",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2823,7 +2823,7 @@ dependencies = [
|
||||
"libc",
|
||||
"percent-encoding",
|
||||
"pin-project-lite",
|
||||
"socket2 0.6.5",
|
||||
"socket2 0.5.10",
|
||||
"system-configuration",
|
||||
"tokio",
|
||||
"tower-service",
|
||||
@@ -3653,7 +3653,7 @@ dependencies = [
|
||||
"png 0.18.1",
|
||||
"serde",
|
||||
"thiserror 2.0.19",
|
||||
"windows-sys 0.60.2",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -3777,7 +3777,7 @@ version = "0.50.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5"
|
||||
dependencies = [
|
||||
"windows-sys 0.60.2",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -4181,7 +4181,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7d8fae84b431384b68627d0f9b3b1245fcf9f46f6c0e3dc902e9dce64edd1967"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"windows-sys 0.48.0",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -4799,7 +4799,7 @@ dependencies = [
|
||||
"quinn-udp",
|
||||
"rustc-hash",
|
||||
"rustls",
|
||||
"socket2 0.6.5",
|
||||
"socket2 0.5.10",
|
||||
"thiserror 2.0.19",
|
||||
"tokio",
|
||||
"tracing",
|
||||
@@ -4837,9 +4837,9 @@ dependencies = [
|
||||
"cfg_aliases",
|
||||
"libc",
|
||||
"once_cell",
|
||||
"socket2 0.6.5",
|
||||
"socket2 0.5.10",
|
||||
"tracing",
|
||||
"windows-sys 0.60.2",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -5258,7 +5258,7 @@ dependencies = [
|
||||
"errno",
|
||||
"libc",
|
||||
"linux-raw-sys",
|
||||
"windows-sys 0.60.2",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -5316,7 +5316,7 @@ dependencies = [
|
||||
"security-framework",
|
||||
"security-framework-sys",
|
||||
"webpki-root-certs",
|
||||
"windows-sys 0.60.2",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -6011,7 +6011,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"windows-sys 0.60.2",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -6714,7 +6714,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "tauri-plugin-notifications"
|
||||
version = "0.5.0-rc.11"
|
||||
source = "git+https://github.com/SableClient/tauri-plugin-notifications.git?rev=87e452fab17711a82422a97ab9541ebf647fa28a#87e452fab17711a82422a97ab9541ebf647fa28a"
|
||||
source = "git+https://github.com/SableClient/tauri-plugin-notifications.git?rev=0175b5ec58a31ab15397e981a67f47fa32254620#0175b5ec58a31ab15397e981a67f47fa32254620"
|
||||
dependencies = [
|
||||
"log",
|
||||
"notify-rust",
|
||||
@@ -7030,7 +7030,7 @@ dependencies = [
|
||||
"serde_with",
|
||||
"swift-rs",
|
||||
"thiserror 2.0.19",
|
||||
"toml 0.9.12+spec-1.1.0",
|
||||
"toml 1.1.3+spec-1.1.0",
|
||||
"url",
|
||||
"urlpattern",
|
||||
"uuid",
|
||||
@@ -7069,7 +7069,7 @@ dependencies = [
|
||||
"getrandom 0.4.3",
|
||||
"once_cell",
|
||||
"rustix",
|
||||
"windows-sys 0.60.2",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -7694,7 +7694,7 @@ dependencies = [
|
||||
"png 0.18.1",
|
||||
"serde",
|
||||
"thiserror 2.0.19",
|
||||
"windows-sys 0.60.2",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -7768,7 +7768,7 @@ checksum = "f2f6fb2847f6742cd76af783a2a2c49e9375d0a111c7bef6f71cd9e738c72d6e"
|
||||
dependencies = [
|
||||
"memoffset",
|
||||
"tempfile",
|
||||
"windows-sys 0.60.2",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -8398,7 +8398,7 @@ version = "0.1.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
|
||||
dependencies = [
|
||||
"windows-sys 0.48.0",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@@ -89,12 +89,12 @@ windows = { version = "0.61", 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 = "87e452fab17711a82422a97ab9541ebf647fa28a" }
|
||||
tauri-plugin-notifications = { git = "https://github.com/SableClient/tauri-plugin-notifications.git", rev = "0175b5ec58a31ab15397e981a67f47fa32254620" }
|
||||
|
||||
# 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 = "87e452fab17711a82422a97ab9541ebf647fa28a", default-features = false }
|
||||
tauri-plugin-notifications = { git = "https://github.com/SableClient/tauri-plugin-notifications.git", rev = "0175b5ec58a31ab15397e981a67f47fa32254620", default-features = false }
|
||||
|
||||
[target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies]
|
||||
tauri-plugin-updater = { version = "2", optional = true }
|
||||
@@ -119,7 +119,7 @@ cef = { version = "=150.2.1", optional = true }
|
||||
libloading = "0.8"
|
||||
|
||||
[target.'cfg(any(target_os = "android", target_os = "ios"))'.dependencies]
|
||||
tauri-plugin-notifications = { git = "https://github.com/SableClient/tauri-plugin-notifications.git", rev = "87e452fab17711a82422a97ab9541ebf647fa28a", features = [
|
||||
tauri-plugin-notifications = { git = "https://github.com/SableClient/tauri-plugin-notifications.git", rev = "0175b5ec58a31ab15397e981a67f47fa32254620", features = [
|
||||
"push-notifications",
|
||||
] }
|
||||
tauri-plugin-edge-to-edge = { git = "https://github.com/SableClient/tauri-plugin-edge-to-edge.git", rev = "33c6116c27be28c06df5a9d02231ecc5fdeb93c5" }
|
||||
|
||||
@@ -47,8 +47,18 @@ const matrixClient = vi.hoisted(() => ({
|
||||
fetchRoomEvent: vi.fn<() => Promise<unknown>>(),
|
||||
}));
|
||||
|
||||
const invoke = vi.hoisted(() =>
|
||||
vi.fn<(cmd: string, args?: Record<string, unknown>) => Promise<unknown>>()
|
||||
);
|
||||
|
||||
const addPluginListener = vi.hoisted(() =>
|
||||
vi.fn<(plugin: string, event: string, handler: PluginListenerHandler) => Promise<() => void>>()
|
||||
vi.fn<
|
||||
(
|
||||
plugin: string,
|
||||
event: string,
|
||||
handler: PluginListenerHandler
|
||||
) => Promise<{ unregister: () => Promise<void> }>
|
||||
>()
|
||||
);
|
||||
|
||||
vi.mock('./UnifiedPushTransport', () => unifiedPushTransport);
|
||||
@@ -60,6 +70,7 @@ vi.mock('./TauriNotificationsApiClient', () => ({
|
||||
|
||||
vi.mock('@tauri-apps/api/core', () => ({
|
||||
addPluginListener,
|
||||
invoke,
|
||||
}));
|
||||
|
||||
vi.mock('$utils/fetch', () => ({
|
||||
@@ -102,10 +113,11 @@ describe('UnifiedPushNotifications', () => {
|
||||
matrixClient.getPushers.mockResolvedValue({ pushers: [] });
|
||||
matrixClient.getCrypto.mockReturnValue(undefined);
|
||||
matrixClient.getRoom.mockReturnValue(undefined);
|
||||
invoke.mockResolvedValue(undefined);
|
||||
addPluginListener.mockImplementation(
|
||||
async (_plugin: string, _event: string, handler: (data: unknown) => void) => {
|
||||
pushHandler = handler;
|
||||
return vi.fn<() => void>();
|
||||
return { unregister: vi.fn<() => Promise<void>>().mockResolvedValue(undefined) };
|
||||
}
|
||||
);
|
||||
vi.stubGlobal(
|
||||
@@ -531,6 +543,42 @@ describe('UnifiedPushNotifications', () => {
|
||||
expect(notificationsApi.sendNotification).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it('activates the native listener only after registration resolves', async () => {
|
||||
const order: string[] = [];
|
||||
addPluginListener.mockImplementation(async () => {
|
||||
order.push('register');
|
||||
return { unregister: vi.fn<() => Promise<void>>().mockResolvedValue(undefined) };
|
||||
});
|
||||
invoke.mockImplementation(async () => {
|
||||
order.push('activate');
|
||||
});
|
||||
|
||||
await listenForUnifiedPushMessages(() => makeSettings() as never);
|
||||
|
||||
expect(order).toEqual(['register', 'activate']);
|
||||
expect(invoke).toHaveBeenCalledWith('plugin:notifications|set_push_message_listener_active', {
|
||||
active: true,
|
||||
});
|
||||
});
|
||||
|
||||
it('deactivates before unregistering even when deactivation fails', async () => {
|
||||
const order: string[] = [];
|
||||
const unregister = vi.fn<() => Promise<void>>(async () => {
|
||||
order.push('unregister');
|
||||
});
|
||||
addPluginListener.mockImplementation(async () => ({ unregister }));
|
||||
|
||||
const handle = await listenForUnifiedPushMessages(() => makeSettings() as never);
|
||||
invoke.mockImplementation(async () => {
|
||||
order.push('deactivate');
|
||||
throw new Error('deactivation failed');
|
||||
});
|
||||
|
||||
await expect(handle.unregister()).rejects.toThrow('deactivation failed');
|
||||
|
||||
expect(order).toEqual(['deactivate', 'unregister']);
|
||||
});
|
||||
|
||||
it('registers the Matrix pusher with the resolved UnifiedPush overrides', async () => {
|
||||
await expect(
|
||||
tryEnableUnifiedPush(matrixClient as never, {
|
||||
|
||||
@@ -22,7 +22,7 @@ import {
|
||||
createUnifiedPushMessageListener,
|
||||
parseUnifiedPushMessage,
|
||||
} from './UnifiedPushMessageListener';
|
||||
import { addPluginListener } from '@tauri-apps/api/core';
|
||||
import { addPluginListener, invoke } from '@tauri-apps/api/core';
|
||||
import type { PushTransportConfig } from './NotificationTransport';
|
||||
import { getTauriNotificationsApi, isMobileTauri } from './TauriNotificationsApiClient';
|
||||
import {
|
||||
@@ -1107,7 +1107,9 @@ async function handleUnifiedPushPayload(
|
||||
}
|
||||
}
|
||||
|
||||
export function listenForUnifiedPushMessages(getSettings: () => NotificationSettings) {
|
||||
const SET_PUSH_MESSAGE_LISTENER_ACTIVE = 'plugin:notifications|set_push_message_listener_active';
|
||||
|
||||
export async function listenForUnifiedPushMessages(getSettings: () => NotificationSettings) {
|
||||
const dispatch = createUnifiedPushMessageListener(
|
||||
(notification) => handleUnifiedPushPayload(notification, getSettings),
|
||||
(error) => {
|
||||
@@ -1119,8 +1121,25 @@ export function listenForUnifiedPushMessages(getSettings: () => NotificationSett
|
||||
}
|
||||
);
|
||||
|
||||
return addPluginListener('notifications', 'push-message', (data: unknown) => {
|
||||
const listener = await addPluginListener('notifications', 'push-message', (data: unknown) => {
|
||||
const notification = parseUnifiedPushMessage(data);
|
||||
if (notification) dispatch(notification);
|
||||
});
|
||||
|
||||
try {
|
||||
await invoke(SET_PUSH_MESSAGE_LISTENER_ACTIVE, { active: true });
|
||||
} catch (error) {
|
||||
await listener.unregister().catch(() => {});
|
||||
throw error;
|
||||
}
|
||||
|
||||
return {
|
||||
unregister: async () => {
|
||||
try {
|
||||
await invoke(SET_PUSH_MESSAGE_LISTENER_ACTIVE, { active: false });
|
||||
} finally {
|
||||
await listener.unregister();
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user