Move session info file to cache dir
This commit is contained in:
parent
94b5c82353
commit
b2df4ff0ef
|
@ -1,26 +1,30 @@
|
|||
use directories::ProjectDirs;
|
||||
use matrix_sdk::{Client, ClientConfig, Session};
|
||||
use serde_lexpr;
|
||||
use std::fs::File;
|
||||
use directories::ProjectDirs;
|
||||
use std::fs::{create_dir_all, File};
|
||||
|
||||
static SESSION_FILE: &str = "session_info";
|
||||
lazy_static! {
|
||||
static ref PROJECT_DIRS: ProjectDirs = ProjectDirs::from("me", "petrichor", "mxadm").unwrap();
|
||||
static ref PROJECT_DIRS: ProjectDirs = ProjectDirs::from("me", "petrichor", "mxadm")
|
||||
.expect("Project directories should be available on all platforms");
|
||||
}
|
||||
static SESSION_FILE: &str = "session_info";
|
||||
|
||||
pub fn build_client_config() -> ClientConfig {
|
||||
ClientConfig::new()
|
||||
.store_path(PROJECT_DIRS.cache_dir().join("store"))
|
||||
ClientConfig::new().store_path(PROJECT_DIRS.cache_dir().join("store"))
|
||||
}
|
||||
|
||||
pub fn save_session(session: Session) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let mut session_file = File::create(SESSION_FILE)?;
|
||||
let cache_dir = PROJECT_DIRS.cache_dir();
|
||||
if !cache_dir.exists() {
|
||||
create_dir_all(cache_dir)?;
|
||||
}
|
||||
let mut session_file = File::create(cache_dir.join(SESSION_FILE))?;
|
||||
serde_lexpr::to_writer(&mut session_file, &session)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn restore_session() -> Result<Client, Box<dyn std::error::Error>> {
|
||||
let session_file = File::open(SESSION_FILE)?;
|
||||
let session_file = File::open(PROJECT_DIRS.cache_dir().join(SESSION_FILE))?;
|
||||
let session_info: Session = serde_lexpr::from_reader(session_file)?;
|
||||
|
||||
let client =
|
||||
|
|
Loading…
Reference in New Issue