SuperAPI AI 工具集

tauri-impl-multi-window

通用与其它

查看项目

更新于 10-15 22:18

技能介绍

用途:面向 Tauri 2 的多窗口开发,覆盖创建次级窗口、启动画面(splashscreen)流程与窗口间通信。

主要能力:Rust 侧用 WebviewWindowBuilder::new() 创建窗口,TypeScript 侧用 new Window(),也可在 tauri.conf.json 的 windows 数组中配置;通过 app.get_webview_window("label")、app.webview_windows()、getCurrentWindow()、Window.getByLabel()、getAllWindows() 访问窗口;用 app.emit / app.emit_to / emit / emitTo 与 listen 实现广播或定向事件通信;支持显示/隐藏、关闭拦截、窗口事件(resize、focus、theme 等)处理。

必要用法与限制:窗口标签必须全局唯一,重复标签会触发运行时错误;创建窗口须用 WebviewWindowBuilder(v1 的 WindowBuilder 不适用);本地页面用 WebviewUrl::App(),外部 URL 用 WebviewUrl::External();访问窗口前先检查是否存在并处理 None;listen() 返回 Promise<UnlistenFn>,需 await 后再调用取消函数;在 React、Vue、Svelte 等组件框架中要清理事件监听以防内存泄漏。onThemeChanged 在 Linux 上不受支持。

适用场景:设置窗口、启动画面切换、主窗口与子窗口间配置同步等。具体 API 签名与更多示例见其 references 目录及官方文档。