Open configured vault folders

This commit is contained in:
2026-08-10 17:21:35 +02:00
parent c301d9a3df
commit 491d7b1557
11 changed files with 712 additions and 19 deletions

View File

@@ -6,7 +6,7 @@ use crate::{
authentication::{
AuthenticationTimeout, NativeAuthenticationHandle, NativeAuthenticationSession,
},
config::Config,
config::{Config, ConfigSettings, EditorCommand},
crypto::{KeyInfo, KeyStore, SecretProvider},
document::{DocumentError, EntryDocument, EntryDocumentService},
git::{AutomaticEntryCommitter, GitIdentity},
@@ -117,6 +117,54 @@ impl DesktopStorage {
self.config.authentication_timeout()
}
pub fn vault(&self) -> &Path {
self.config.vault()
}
pub fn config_source(&self) -> &Path {
self.config.source()
}
pub fn default_key(&self) -> &str {
self.config.default_key().as_str()
}
pub fn configured_editor(&self) -> Option<&EditorCommand> {
self.config.configured_editor()
}
pub fn settings(&self) -> ConfigSettings {
self.config.settings()
}
pub fn update_settings(&self, mut settings: ConfigSettings) -> Result<Self, DesktopError> {
let repository = Repository::open(settings.vault())
.map_err(|error| DesktopError::new(DesktopErrorKind::Repository, error))?;
settings.set_vault(repository.root_path().to_owned());
let config = self
.config
.with_settings(settings)
.map_err(|error| DesktopError::new(DesktopErrorKind::Configuration, error))?;
let storage = Self { config };
let keys = storage.keys()?;
keys.resolve(storage.config.default_key().as_str())
.map_err(|error| DesktopError::new(DesktopErrorKind::KeyMaterial, error))?;
storage.tree()?;
storage
.config
.persist()
.map_err(|error| DesktopError::new(DesktopErrorKind::Configuration, error))?;
Ok(storage)
}
/// Validate a selected folder through the same repository and key path as
/// normal desktop reads, then atomically update the shared configuration.
pub fn switch_vault(&self, vault: &Path) -> Result<Self, DesktopError> {
let mut settings = self.settings();
settings.set_vault(vault.to_owned());
self.update_settings(settings)
}
pub fn tree(&self) -> Result<TreeModel, DesktopError> {
let repository = self.repository()?;
let keys = self.keys()?;