Implement clipboard and QR presentation
This commit is contained in:
@@ -6,11 +6,14 @@ use std::{
|
||||
error::Error,
|
||||
fmt, fs,
|
||||
path::{Component, Path, PathBuf},
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use serde::Deserialize;
|
||||
use url::Url;
|
||||
|
||||
use crate::presentation::{ClipboardTimeout, DEFAULT_CLIPBOARD_TIMEOUT};
|
||||
|
||||
const APPLICATION_DIRECTORY: &str = "ironstorage";
|
||||
const CONFIG_FILE: &str = "config.toml";
|
||||
const MAX_CONFIG_BYTES: u64 = 1024 * 1024;
|
||||
@@ -23,6 +26,7 @@ pub struct Config {
|
||||
default_key: KeyIdentity,
|
||||
key_material: PathBuf,
|
||||
editor: Option<EditorCommand>,
|
||||
clipboard_timeout: ClipboardTimeout,
|
||||
git_remotes: Vec<GitRemote>,
|
||||
}
|
||||
|
||||
@@ -52,6 +56,10 @@ impl Config {
|
||||
self.editor.as_ref()
|
||||
}
|
||||
|
||||
pub fn clipboard_timeout(&self) -> ClipboardTimeout {
|
||||
self.clipboard_timeout
|
||||
}
|
||||
|
||||
pub fn git_remotes(&self) -> &[GitRemote] {
|
||||
&self.git_remotes
|
||||
}
|
||||
@@ -400,6 +408,7 @@ struct RawConfig {
|
||||
default_key: Option<String>,
|
||||
key_material: Option<PathBuf>,
|
||||
editor: Option<RawEditor>,
|
||||
clipboard_timeout_seconds: Option<u64>,
|
||||
#[serde(default)]
|
||||
git: RawGit,
|
||||
}
|
||||
@@ -457,6 +466,13 @@ fn validate_config(source: PathBuf, raw: RawConfig) -> Result<Config, ConfigErro
|
||||
})
|
||||
.and_then(validate_key_identity)?;
|
||||
let editor = raw.editor.map(validate_editor).transpose()?;
|
||||
let clipboard_timeout = ClipboardTimeout::new(Duration::from_secs(
|
||||
raw.clipboard_timeout_seconds
|
||||
.unwrap_or(DEFAULT_CLIPBOARD_TIMEOUT.as_secs()),
|
||||
))
|
||||
.map_err(|_| ConfigError::InvalidField {
|
||||
field: "clipboard_timeout_seconds",
|
||||
})?;
|
||||
let git_remotes = validate_remotes(raw.git.remotes)?;
|
||||
|
||||
Ok(Config {
|
||||
@@ -465,6 +481,7 @@ fn validate_config(source: PathBuf, raw: RawConfig) -> Result<Config, ConfigErro
|
||||
default_key,
|
||||
key_material,
|
||||
editor,
|
||||
clipboard_timeout,
|
||||
git_remotes,
|
||||
})
|
||||
}
|
||||
@@ -601,7 +618,14 @@ fn validate_known_fields(value: &toml::Value, source: &Path) -> Result<(), Confi
|
||||
validate_table(
|
||||
root,
|
||||
"",
|
||||
&["vault", "default_key", "key_material", "editor", "git"],
|
||||
&[
|
||||
"vault",
|
||||
"default_key",
|
||||
"key_material",
|
||||
"editor",
|
||||
"clipboard_timeout_seconds",
|
||||
"git",
|
||||
],
|
||||
)?;
|
||||
let Some(git) = root.get("git") else {
|
||||
return Ok(());
|
||||
|
||||
Reference in New Issue
Block a user