35 lines
1.0 KiB
Rust
35 lines
1.0 KiB
Rust
|
|
use kordophone_db::settings::Settings as DbSettings;
|
||
|
|
use anyhow::Result;
|
||
|
|
|
||
|
|
mod keys {
|
||
|
|
pub static SERVER_URL: &str = "ServerURL";
|
||
|
|
pub static USERNAME: &str = "Username";
|
||
|
|
pub static CREDENTIAL_ITEM: &str = "CredentialItem";
|
||
|
|
}
|
||
|
|
|
||
|
|
pub struct Settings {
|
||
|
|
pub server_url: Option<String>,
|
||
|
|
pub username: Option<String>,
|
||
|
|
pub credential_item: Option<String>,
|
||
|
|
}
|
||
|
|
|
||
|
|
impl Settings {
|
||
|
|
pub fn from_db(db_settings: &mut DbSettings) -> Result<Self> {
|
||
|
|
let server_url = db_settings.get(keys::SERVER_URL)?;
|
||
|
|
let username = db_settings.get(keys::USERNAME)?;
|
||
|
|
let credential_item = db_settings.get(keys::CREDENTIAL_ITEM)?;
|
||
|
|
|
||
|
|
Ok(Self {
|
||
|
|
server_url,
|
||
|
|
username,
|
||
|
|
credential_item,
|
||
|
|
})
|
||
|
|
}
|
||
|
|
|
||
|
|
pub fn save(&self, db_settings: &mut DbSettings) -> Result<()> {
|
||
|
|
db_settings.put(keys::SERVER_URL, &self.server_url)?;
|
||
|
|
db_settings.put(keys::USERNAME, &self.username)?;
|
||
|
|
db_settings.put(keys::CREDENTIAL_ITEM, &self.credential_item)?;
|
||
|
|
Ok(())
|
||
|
|
}
|
||
|
|
}
|