From 1f4d6620543b59c24925ded4a07911fe4e6334a7 Mon Sep 17 00:00:00 2001 From: kdletters Date: Sat, 20 Jun 2026 13:05:21 +0800 Subject: [PATCH] =?UTF-8?q?=E9=94=81=E5=AE=9A=E6=A1=8C=E9=9D=A2=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E6=8A=95=E9=80=92=E4=B8=8D=E5=8F=AF=E7=94=A8=E5=93=8D?= =?UTF-8?q?=E5=BA=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 桌面通知投递失败转为稳定 host_error 桌面通知单测覆盖投递不可用 code 和 message 桌面壳配置检查反查通知投递不可用边界 --- apps/desktop-shell/scripts/check-config.mjs | 3 +++ .../src/host_bridge/notifications.rs | 21 ++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/apps/desktop-shell/scripts/check-config.mjs b/apps/desktop-shell/scripts/check-config.mjs index 8fa76db41..575f89921 100644 --- a/apps/desktop-shell/scripts/check-config.mjs +++ b/apps/desktop-shell/scripts/check-config.mjs @@ -2563,6 +2563,7 @@ for (const snippet of [ 'DesktopNotificationPermissionAction', 'desktop_notification_permission_action', 'notification_permission_unavailable_response', + 'notification_delivery_unavailable_response', 'PermissionState::Granted', 'PermissionState::Denied', 'PermissionState::Prompt | PermissionState::PromptWithRationale', @@ -2570,9 +2571,11 @@ for (const snippet of [ 'json!({"action": HOST_BRIDGE_LOCAL_NOTIFICATION_DELIVERED_TO_SYSTEM_ACTION})', 'local_notification_payload_truncates_to_shared_contract_limits', 'notification_permission_unavailable_response_is_stable', + 'notification_delivery_unavailable_response_is_stable', '"a".repeat(HOST_BRIDGE_LOCAL_NOTIFICATION_TITLE_MAX_LENGTH)', '"b".repeat(HOST_BRIDGE_LOCAL_NOTIFICATION_BODY_MAX_LENGTH)', '"notification permission unavailable"', + '"notification delivery unavailable"', '"notification permission denied"', 'app.notification().builder()', ]) { diff --git a/apps/desktop-shell/src-tauri/src/host_bridge/notifications.rs b/apps/desktop-shell/src-tauri/src/host_bridge/notifications.rs index 7cd288738..a4abfb8b1 100644 --- a/apps/desktop-shell/src-tauri/src/host_bridge/notifications.rs +++ b/apps/desktop-shell/src-tauri/src/host_bridge/notifications.rs @@ -97,6 +97,14 @@ fn notification_permission_unavailable_response(request: &HostBridgeRequest) -> ) } +fn notification_delivery_unavailable_response(request: &HostBridgeRequest) -> HostBridgeResponse { + failed( + request.id.clone(), + "host_error", + "notification delivery unavailable", + ) +} + pub(crate) fn show_desktop_local_notification( app: &tauri::AppHandle, request: &HostBridgeRequest, @@ -142,7 +150,7 @@ pub(crate) fn show_desktop_local_notification( request.id.clone(), desktop_notification_delivered_to_system_result(), ), - Err(error) => failed(request.id.clone(), "host_error", error.to_string()), + Err(_) => notification_delivery_unavailable_response(request), } } @@ -200,6 +208,17 @@ mod tests { assert_eq!(error.message, "notification permission unavailable"); } + #[test] + fn notification_delivery_unavailable_response_is_stable() { + let request = request("notification.showLocal"); + + let response = notification_delivery_unavailable_response(&request); + let error = response.error.expect("error"); + + assert_eq!(error.code, "host_error"); + assert_eq!(error.message, "notification delivery unavailable"); + } + #[test] fn local_notification_payload_rejects_empty_and_control_text() { let mut empty = request("notification.showLocal");