tauri2中创建新的窗口方式,和tauri1不一样了哦

861 阅读1分钟

看官方javascript的api文档:window | Tauri 

tauri中的rust文档:docs.rs/tauri/lates…

tauri.config.json定义文档:Configuration | Tauri

tauri可用插件:tauri-apps repositories · GitHub

在前端页面创建窗口示例:

import { Window } from "@tauri-apps/api/window"

const appWindow = new Window('theUniqueLabel');

appWindow.once('tauri://created', function () {
 // window successfully created
});
appWindow.once('tauri://error', function (e) {
 // an error happened creating the window
});

// emit an event to the backend
await appWindow.emit("some-event", "data");
// listen to an event from the backend
const unlisten = await appWindow.listen("event-name", e => {});
unlisten();

在tauri后端rust创建窗口文档:WebviewWindowBuilder in tauri::webview - Rust

示例代码:

#[tauri::command]
async fn create_window(app: tauri::AppHandle) {
  let webview_window = tauri::WebviewWindowBuilder::new(&app, "label", tauri::WebviewUrl::App("index.html".into()))
    .build()
    .unwrap();
}