daemon: setting foundation for client creation
This commit is contained in:
35
kordophoned/src/daemon/settings.rs
Normal file
35
kordophoned/src/daemon/settings.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
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(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user