Tauri 等待网页

2024-01-29 16:19 更新
如果你正在等待你的 Web 代码,你需要创建一个命令。close_splashscreen


use tauri::Manager;
// Create the command:
// This command must be async so that it doesn't run on the main thread.
#[tauri::command]
async fn close_splashscreen(window: tauri::Window) {
  // Close splashscreen
  if let Some(splashscreen) = window.get_window("splashscreen") {
    splashscreen.close().unwrap();
  }
  // Show main window
  window.get_window("main").unwrap().show().unwrap();
}

// Register the command:
fn main() {
  tauri::Builder::default()
    // Add this line
    .invoke_handler(tauri::generate_handler![close_splashscreen])
    .run(tauri::generate_context!())
    .expect("failed to run app");
}

然后,您可以通过以下两种方式之一将其导入到您的项目中:

// With the Tauri API npm package:
import { invoke } from '@tauri-apps/api/tauri'

// With the Tauri global script:
const invoke = window.__TAURI__.invoke

最后,添加一个事件侦听器(或者随时调用):invoke()

document.addEventListener('DOMContentLoaded', () => {
  // This will wait for the window to load, but you could
  // run this function on whatever trigger you want
  invoke('close_splashscreen')
})


以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号