mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-07-10 16:27:05 +02:00
chore(store): add AppSettings example (#573)
* basic example foundation * add examples to workspace * cleanup and load fix * fmt * reset lockfile --------- Co-authored-by: FabianLars <fabianlars@fabianlars.de>
This commit is contained in:
@@ -0,0 +1 @@
|
||||
pub mod settings;
|
||||
@@ -0,0 +1,29 @@
|
||||
use tauri_plugin_store::Store;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct AppSettings {
|
||||
pub launch_at_login: bool,
|
||||
pub theme: String,
|
||||
}
|
||||
|
||||
impl AppSettings {
|
||||
pub fn load_from_store<R: tauri::Runtime>(
|
||||
store: &Store<R>,
|
||||
) -> Result<Self, Box<dyn std::error::Error>> {
|
||||
let launch_at_login = store
|
||||
.get("appSettings.launchAtLogin")
|
||||
.and_then(|v| v.as_bool())
|
||||
.unwrap_or(false);
|
||||
|
||||
let theme = store
|
||||
.get("appSettings.theme")
|
||||
.and_then(|v| v.as_str())
|
||||
.map(|s| s.to_string())
|
||||
.unwrap_or_else(|| "dark".to_string());
|
||||
|
||||
Ok(AppSettings {
|
||||
launch_at_login,
|
||||
theme,
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user