W3Cschool
恭喜您成為首批注冊(cè)用戶(hù)
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
tauri::plugin::Builder
use tauri::{
plugin::{Builder, TauriPlugin},
Runtime,
};
// the plugin custom command handlers if you choose to extend the API:
#[tauri::command]
// this will be accessible with `invoke('plugin:awesome|initialize')`.
// where `awesome` is the plugin name.
fn initialize() {}
#[tauri::command]
// this will be accessible with `invoke('plugin:awesome|do_something')`.
fn do_something() {}
pub fn init<R: Runtime>() -> TauriPlugin<R> {
Builder::new("awesome")
.invoke_handler(tauri::generate_handler![initialize, do_something])
.build()
}
插件可以設(shè)置和維護(hù)狀態(tài),就像您的應(yīng)用可以:
use tauri::{
plugin::{Builder, TauriPlugin},
AppHandle, Manager, Runtime, State,
};
#[derive(Default)]
struct MyState {}
#[tauri::command]
// this will be accessible with `invoke('plugin:awesome|do_something')`.
fn do_something<R: Runtime>(_app: AppHandle<R>, state: State<'_, MyState>) {
// you can access `MyState` here!
}
pub fn init<R: Runtime>() -> TauriPlugin<R> {
Builder::new("awesome")
.invoke_handler(tauri::generate_handler![do_something])
.setup(|app_handle| {
// setup plugin specific state here
app_handle.manage(MyState::default());
Ok(())
})
.build()
}
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話(huà):173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: