Plugin Store StoreExt ctx doesnt exist
The below example seems to be no longer valid in V2. Please update V2 docs when a plugin has changed it's functionality. (See https://github.com/tauri-apps/tauri-plugin-store/tree/v2 for partially updated docs)
use tauri::Wry;
use tauri_plugin_store::StoreExt;
use serde_json::json;
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_store::Builder::default().build())
.setup(|app| {
let store = app.handle().store_builder("store.bin").build();
// Note that values must be serde_json::Value instances,
// otherwise, they will not be compatible with the JavaScript bindings.
store.insert("some-key", json!({ "value": 5 }))?;
// Get a value from the store.
let value = store.get("some-key").expect("Failed to get value from store");
println!("{}", value); // {"value":5}
// You can manually save the store after making changes.
// Otherwise, it will save upon graceful exit as described above.
store.save()?;
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
(Primary plugin docs here: https://v2.tauri.app/plugin/store/)
let mut defaults = std::collections::HashMap::new();
defaults.insert(DISPLAY_CONFIG.to_string(), json!(get_display_config()));
defaults.insert(SWIPER_CONFIG.to_string(), json!(get_swiper_config()));
let store = app
.store_builder("store.bin")
.defaults(defaults)
.auto_save(Duration::from_millis(100))
.build();
let _ = store.load().expect("file is not existed");
panic: file is not existed: Io(Os { code: 2, kind: NotFound, message: "没有那个文件或目录" }) i don't know how to fix it .
@nickheyer StoreExt does exist, the problem is that it should be a ? at the end of build() and insert is actually set
let store = app.handle().store_builder("store.bin").build()?;
// Note that values must be serde_json::Value instances,
// otherwise, they will not be compatible with the JavaScript bindings.
store.set("some-key", json!({ "value": 5 }));
@cleveng Don't call let _ = store.load().expect("file is not existed");, the store builder will load the store on build
I'm still working on a store plugin rework here at #1860, and we can improve the documentation after it's merged
@Legend-Master Is there currently a workaround for #1860 ? As last I checked, it was breaking my app. Also, am I understanding this right - there is no way to share a store between js and rust?
There're no way to share them easily, if you really need a workaround, you can put the store manually to webview's resource table and emit the resource id to js side and create the store with that resource id manually
Is this done? I saw pr was merged.
Yeah, we just need to release it and get the docs updated