锁定桌面外观不可用响应
桌面外观主题读取失败转为稳定 host_error 桌面主窗口缺失时外观查询转为稳定不可用响应 桌面外观单测覆盖不可用响应 code 和 message 桌面壳配置检查禁止暴露原生窗口错误
This commit is contained in:
@@ -2446,14 +2446,23 @@ if (
|
||||
}
|
||||
for (const snippet of [
|
||||
'desktop_appearance_color_scheme',
|
||||
'appearance_unavailable_response',
|
||||
'color_scheme_from_theme(theme)',
|
||||
'window.theme()',
|
||||
'"colorScheme"',
|
||||
'"appearance unavailable"',
|
||||
'appearance_unavailable_response_is_stable',
|
||||
]) {
|
||||
if (!desktopHostBridgeAppearanceSource.includes(snippet)) {
|
||||
throw new Error(`desktop shell appearance module is missing ${snippet}`);
|
||||
}
|
||||
}
|
||||
if (
|
||||
desktopHostBridgeAppearanceSource.includes('error.to_string()') ||
|
||||
desktopHostBridgeAppearanceSource.includes('"main window not found"')
|
||||
) {
|
||||
throw new Error('desktop shell appearance module must hide native window errors');
|
||||
}
|
||||
if (
|
||||
!desktopHostBridgeDispatchSource.includes(
|
||||
'set_desktop_app_badge_count(&app, &request)',
|
||||
|
||||
@@ -10,9 +10,9 @@ pub(crate) fn desktop_appearance_color_scheme(
|
||||
match app.get_webview_window("main") {
|
||||
Some(window) => match window.theme() {
|
||||
Ok(theme) => ok_color_scheme(request, color_scheme_from_theme(theme)),
|
||||
Err(error) => failed(request.id.clone(), "host_error", error.to_string()),
|
||||
Err(_) => appearance_unavailable_response(request),
|
||||
},
|
||||
None => failed(request.id.clone(), "host_error", "main window not found"),
|
||||
None => appearance_unavailable_response(request),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,10 @@ fn ok_color_scheme(request: &HostBridgeRequest, color_scheme: &'static str) -> H
|
||||
)
|
||||
}
|
||||
|
||||
fn appearance_unavailable_response(request: &HostBridgeRequest) -> HostBridgeResponse {
|
||||
failed(request.id.clone(), "host_error", "appearance unavailable")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -42,4 +46,14 @@ mod tests {
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn appearance_unavailable_response_is_stable() {
|
||||
let response = appearance_unavailable_response(&request("appearance.getColorScheme"));
|
||||
|
||||
assert!(!response.ok);
|
||||
let error = response.error.expect("appearance error");
|
||||
assert_eq!(error.code, "host_error");
|
||||
assert_eq!(error.message, "appearance unavailable");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user