锁定桌面标题不可用响应

桌面标题主窗口缺失转为稳定 host_error

桌面标题设置失败转为稳定不可用响应

桌面标题单测覆盖不可用响应 code 和 message

桌面壳配置检查禁止暴露标题原生窗口错误
This commit is contained in:
2026-06-20 12:45:44 +08:00
parent 56011330c3
commit c55beb62d9
2 changed files with 25 additions and 2 deletions
@@ -2511,16 +2511,25 @@ for (const snippet of [
'WINDOW_TITLE_MAX_LENGTH',
'normalize_window_title',
'window_title_from_request',
'window_title_unavailable_response',
'required_string_payload(request, "title")',
'window.set_title(&title)',
'"title is required"',
'"window title unavailable"',
'window_title_request_rejects_missing_or_invalid_payload',
'window_title_request_trims_and_truncates_shared_boundary',
'window_title_unavailable_response_is_stable',
]) {
if (!desktopHostBridgeTitleSource.includes(snippet)) {
throw new Error(`desktop shell title module is missing ${snippet}`);
}
}
if (
desktopHostBridgeTitleSource.includes('error.to_string()') ||
desktopHostBridgeTitleSource.includes('"main window not found"')
) {
throw new Error('desktop shell title module must hide native window errors');
}
if (
!desktopHostBridgeDispatchSource.includes(
'show_desktop_local_notification(&app, &request)',
@@ -36,12 +36,16 @@ pub(crate) fn set_desktop_host_bridge_window_title(
match app.get_webview_window("main") {
Some(window) => match window.set_title(&title) {
Ok(()) => ok(request.id.clone(), json!(true)),
Err(error) => failed(request.id.clone(), "host_error", error.to_string()),
Err(_) => window_title_unavailable_response(request),
},
None => failed(request.id.clone(), "host_error", "main window not found"),
None => window_title_unavailable_response(request),
}
}
fn window_title_unavailable_response(request: &HostBridgeRequest) -> HostBridgeResponse {
failed(request.id.clone(), "host_error", "window title unavailable")
}
#[cfg(test)]
mod tests {
use super::*;
@@ -98,4 +102,14 @@ mod tests {
assert_eq!(title.chars().count(), WINDOW_TITLE_MAX_LENGTH);
assert!(title.chars().all(|character| character == '甲'));
}
#[test]
fn window_title_unavailable_response_is_stable() {
let response = window_title_unavailable_response(&request("app.setTitle"));
assert!(!response.ok);
let error = response.error.expect("window title error");
assert_eq!(error.code, "host_error");
assert_eq!(error.message, "window title unavailable");
}
}