W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
這是基于上面的示例。在Rust方面,您需要一個?PathResolver
?的實例,您可以從?App
?和?AppHandle
?中獲取:
tauri::Builder::default()
.setup(|app| {
let resource_path = app.path_resolver()
.resolve_resource("lang/de.json")
.expect("failed to resolve resource");
let file = std::fs::File::open(&resource_path).unwrap();
let lang_de: serde_json::Value = serde_json::from_reader(file).unwrap();
println!("{}", lang_de.get("hello").unwrap()); // This will print 'Guten Tag!' to the terminal
Ok(())
})
#[tauri::command]
fn hello(handle: tauri::AppHandle) -> String {
let resource_path = handle.path_resolver()
.resolve_resource("lang/de.json")
.expect("failed to resolve resource");
let file = std::fs::File::open(&resource_path).unwrap();
let lang_de: serde_json::Value = serde_json::from_reader(file).unwrap();
lang_de.get("hello").unwrap()
}
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: