Tauri 等待網(wǎng)頁

2024-01-29 16:19 更新
如果你正在等待你的 Web 代碼,你需要創(chuàng)建一個命令。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");
}

然后,您可以通過以下兩種方式之一將其導(dǎo)入到您的項目中:

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

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

最后,添加一個事件偵聽器(或者隨時調(diào)用):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')
})


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號