锁定桌面通知权限不可用边界
桌面通知桥接把权限状态读取失败转为稳定 host_error 桌面通知桥接把权限请求失败转为稳定 host_error 桌面通知单测覆盖权限不可用错误载荷 桌面壳配置检查反查通知权限不可用边界
This commit is contained in:
@@ -2497,14 +2497,17 @@ for (const snippet of [
|
||||
'HOST_BRIDGE_LOCAL_NOTIFICATION_BODY_MAX_LENGTH',
|
||||
'DesktopNotificationPermissionAction',
|
||||
'desktop_notification_permission_action',
|
||||
'notification_permission_unavailable_response',
|
||||
'PermissionState::Granted',
|
||||
'PermissionState::Denied',
|
||||
'PermissionState::Prompt | PermissionState::PromptWithRationale',
|
||||
'desktop_notification_delivered_to_system_result',
|
||||
'json!({"action": HOST_BRIDGE_LOCAL_NOTIFICATION_DELIVERED_TO_SYSTEM_ACTION})',
|
||||
'local_notification_payload_truncates_to_shared_contract_limits',
|
||||
'notification_permission_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 permission denied"',
|
||||
'app.notification().builder()',
|
||||
]) {
|
||||
|
||||
@@ -89,6 +89,14 @@ fn desktop_notification_delivered_to_system_result() -> serde_json::Value {
|
||||
json!({"action": HOST_BRIDGE_LOCAL_NOTIFICATION_DELIVERED_TO_SYSTEM_ACTION})
|
||||
}
|
||||
|
||||
fn notification_permission_unavailable_response(request: &HostBridgeRequest) -> HostBridgeResponse {
|
||||
failed(
|
||||
request.id.clone(),
|
||||
"host_error",
|
||||
"notification permission unavailable",
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn show_desktop_local_notification(
|
||||
app: &tauri::AppHandle,
|
||||
request: &HostBridgeRequest,
|
||||
@@ -100,7 +108,7 @@ pub(crate) fn show_desktop_local_notification(
|
||||
let notification_manager = app.notification();
|
||||
let permission_state = notification_manager
|
||||
.permission_state()
|
||||
.map_err(|error| failed(request.id.clone(), "host_error", error.to_string()));
|
||||
.map_err(|_| notification_permission_unavailable_response(request));
|
||||
let permission_state = match permission_state {
|
||||
Ok(permission_state) => permission_state,
|
||||
Err(response) => return response,
|
||||
@@ -109,7 +117,7 @@ pub(crate) fn show_desktop_local_notification(
|
||||
if permission_action == DesktopNotificationPermissionAction::Request {
|
||||
let requested_state = notification_manager
|
||||
.request_permission()
|
||||
.map_err(|error| failed(request.id.clone(), "host_error", error.to_string()));
|
||||
.map_err(|_| notification_permission_unavailable_response(request));
|
||||
let requested_state = match requested_state {
|
||||
Ok(requested_state) => requested_state,
|
||||
Err(response) => return response,
|
||||
@@ -181,6 +189,17 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn notification_permission_unavailable_response_is_stable() {
|
||||
let request = request("notification.showLocal");
|
||||
|
||||
let response = notification_permission_unavailable_response(&request);
|
||||
let error = response.error.expect("error");
|
||||
|
||||
assert_eq!(error.code, "host_error");
|
||||
assert_eq!(error.message, "notification permission unavailable");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn local_notification_payload_rejects_empty_and_control_text() {
|
||||
let mut empty = request("notification.showLocal");
|
||||
|
||||
Reference in New Issue
Block a user