feat: add tauri-plugin-store for session persistence

This commit is contained in:
2026-04-18 00:48:46 -04:00
parent e817e81619
commit d9590987a5
4 changed files with 26 additions and 9 deletions

17
src-tauri/Cargo.lock generated
View File

@@ -3834,6 +3834,7 @@ dependencies = [
"tauri", "tauri",
"tauri-build", "tauri-build",
"tauri-plugin-opener", "tauri-plugin-opener",
"tauri-plugin-store",
"thiserror 2.0.18", "thiserror 2.0.18",
"tokio", "tokio",
"uuid", "uuid",
@@ -6341,6 +6342,22 @@ dependencies = [
"zbus", "zbus",
] ]
[[package]]
name = "tauri-plugin-store"
version = "2.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ca1a8ff83c269b115e98726ffc13f9e548a10161544a92ad121d6d0a96e16ea"
dependencies = [
"dunce",
"serde",
"serde_json",
"tauri",
"tauri-plugin",
"thiserror 2.0.18",
"tokio",
"tracing",
]
[[package]] [[package]]
name = "tauri-runtime" name = "tauri-runtime"
version = "2.10.1" version = "2.10.1"

View File

@@ -20,6 +20,7 @@ tauri-build = { version = "2", features = [] }
[dependencies] [dependencies]
tauri = { version = "2", features = [] } tauri = { version = "2", features = [] }
tauri-plugin-opener = "2" tauri-plugin-opener = "2"
tauri-plugin-store = "2"
serde = { version = "1", features = ["derive"] } serde = { version = "1", features = ["derive"] }
serde_json = "1" serde_json = "1"
surrealdb = { version = "3.0.5", features = ["native-tls"] } surrealdb = { version = "3.0.5", features = ["native-tls"] }

View File

@@ -1,6 +1,6 @@
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::{Arc, Mutex, LazyLock};
use std::env; use std::env;
use std::sync::{Arc, LazyLock, Mutex};
use surrealdb::engine::remote::ws::{Client, Ws, Wss}; use surrealdb::engine::remote::ws::{Client, Ws, Wss};
use surrealdb::Surreal; use surrealdb::Surreal;
@@ -13,26 +13,24 @@ use crate::error::AppError;
pub static SURREAL_URL: LazyLock<String> = LazyLock::new(|| { pub static SURREAL_URL: LazyLock<String> = LazyLock::new(|| {
option_env!("SURREAL_URL") option_env!("SURREAL_URL")
.map(str::to_string) .map(str::to_string)
.unwrap_or_else(|| env::var("SURREAL_URL") .unwrap_or_else(|| {
.unwrap_or_else(|_| "ws://localhost:8000".to_string())) env::var("SURREAL_URL").unwrap_or_else(|_| "ws://localhost:8000".to_string())
})
}); });
pub static SURREAL_NS: LazyLock<String> = LazyLock::new(|| { pub static SURREAL_NS: LazyLock<String> = LazyLock::new(|| {
option_env!("SURREAL_NS") option_env!("SURREAL_NS")
.map(str::to_string) .map(str::to_string)
.unwrap_or_else(|| env::var("SURREAL_NS") .unwrap_or_else(|| env::var("SURREAL_NS").unwrap_or_else(|_| "dev".to_string()))
.unwrap_or_else(|_| "dev".to_string()))
}); });
pub static SURREAL_DB: LazyLock<String> = LazyLock::new(|| { pub static SURREAL_DB: LazyLock<String> = LazyLock::new(|| {
option_env!("SURREAL_DB") option_env!("SURREAL_DB")
.map(str::to_string) .map(str::to_string)
.unwrap_or_else(|| env::var("SURREAL_DB") .unwrap_or_else(|| env::var("SURREAL_DB").unwrap_or_else(|_| "oxyde".to_string()))
.unwrap_or_else(|_| "oxyde".to_string()))
}); });
pub static SURREAL_ACCESS: LazyLock<String> = LazyLock::new(|| { pub static SURREAL_ACCESS: LazyLock<String> = LazyLock::new(|| {
option_env!("SURREAL_ACCESS") option_env!("SURREAL_ACCESS")
.map(str::to_string) .map(str::to_string)
.unwrap_or_else(|| env::var("SURREAL_ACCESS") .unwrap_or_else(|| env::var("SURREAL_ACCESS").unwrap_or_else(|_| "account".to_string()))
.unwrap_or_else(|_| "account".to_string()))
}); });
pub struct AppState { pub struct AppState {

View File

@@ -14,6 +14,7 @@ use db::{init_db, AppState, SURREAL_DB, SURREAL_NS, SURREAL_URL};
pub fn run() { pub fn run() {
tauri::Builder::default() tauri::Builder::default()
.plugin(tauri_plugin_opener::init()) .plugin(tauri_plugin_opener::init())
.plugin(tauri_plugin_store::Builder::default().build())
.setup(|app| { .setup(|app| {
let app_handle = app.handle().clone(); let app_handle = app.handle().clone();
tauri::async_runtime::block_on(async move { tauri::async_runtime::block_on(async move {