W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
這是基于上面的示例。在Rust方面,您需要一個(gè)?PathResolver
?的實(shí)例,您可以從?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號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: