fix(cross-platform): set_topmost/sample 改属性 cfg 分派,修复非 Windows 编译
cfg!() 只是运行时常量,其分支永远参与类型检查 —— 非 Windows 下 sample_windows / set_topmost_windows 被属性 cfg 移除后调用点报 E0599 方法不存在(Linux CI Test job 第二跑暴露)。改为 #[cfg] 属性块分派,两条路径各平台上只有一个参与编译。
This commit is contained in:
@@ -2,10 +2,17 @@
|
|||||||
|
|
||||||
/// 窗口置顶 / 取消置顶。返回是否成功(非 Windows 或句柄不可得为 false)。
|
/// 窗口置顶 / 取消置顶。返回是否成功(非 Windows 或句柄不可得为 false)。
|
||||||
pub fn set_topmost(window: &gpui_kit::Window, topmost: bool) -> bool {
|
pub fn set_topmost(window: &gpui_kit::Window, topmost: bool) -> bool {
|
||||||
if !cfg!(target_os = "windows") {
|
// 属性 cfg 分派而非 cfg!() 运行时判断:非 Windows 下 set_topmost_windows
|
||||||
return false;
|
// 被 cfg 移除,cfg! 分支仍参与编译会报方法不存在(CI Test job 实测暴露)
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
{
|
||||||
|
set_topmost_windows(window, topmost)
|
||||||
|
}
|
||||||
|
#[cfg(not(target_os = "windows"))]
|
||||||
|
{
|
||||||
|
let _ = (window, topmost);
|
||||||
|
false
|
||||||
}
|
}
|
||||||
set_topmost_windows(window, topmost)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
|
|||||||
@@ -42,10 +42,16 @@ impl Sampler {
|
|||||||
|
|
||||||
/// 采样一次;CPU 占用首次采样为 0(无差分基准)。
|
/// 采样一次;CPU 占用首次采样为 0(无差分基准)。
|
||||||
pub fn sample(&mut self) -> Option<Sample> {
|
pub fn sample(&mut self) -> Option<Sample> {
|
||||||
if !cfg!(target_os = "windows") {
|
// 属性 cfg 分派而非 cfg!() 运行时判断:非 Windows 下 sample_windows
|
||||||
return Some(Sample::default());
|
// 被 cfg 移除,cfg! 分支仍参与编译会报方法不存在(CI Test job 实测暴露)
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
{
|
||||||
|
self.sample_windows()
|
||||||
|
}
|
||||||
|
#[cfg(not(target_os = "windows"))]
|
||||||
|
{
|
||||||
|
Some(Sample::default())
|
||||||
}
|
}
|
||||||
self.sample_windows()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
|
|||||||
Reference in New Issue
Block a user