You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Tauri中设置macOS的`isDocumentEdited`状态遇编译错误

解决Tauri中set_is_document_edited方法找不到的问题

这个问题的核心是set_is_document_edited是macOS专属API,默认不包含在Tauri的通用Window接口中,需要手动启用特性并导入对应的扩展trait。

解决步骤:

  1. 启用Tauri的macos特性
    修改项目根目录下的Cargo.toml,在tauri依赖中添加macos特性:

    [dependencies]
    tauri = { version = "1.5", features = ["macos"] }
    

    注意替换成你当前使用的Tauri版本号。

  2. 导入macOS专属扩展trait
    在你的Rust代码顶部导入WindowExtMacOS trait,这样Window结构体就会拥有macOS专属方法:

    use tauri::WindowExtMacOS;
    
  3. 调用方法并添加条件编译(可选但推荐)
    因为这个方法仅在macOS平台有效,为了避免跨平台编译错误,建议加上条件编译宏:

    let window = app.get_window("main").unwrap();
    #[cfg(target_os = "macos")]
    window.set_is_document_edited(true);
    

补充说明:

  • 该方法定义在tauri::platform::macos::WindowExtMacOS中,只有启用macos特性后才会被编译进项目。
  • 确保你的Tauri版本不低于1.0,这个API是在1.x版本后正式加入的。

内容的提问来源于stack exchange,提问作者hellothisisaus

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 12:02:36