Add commands to delete and check repositories

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/4/head
trivernis 3 years ago
parent b91a3ab4d2
commit 55fc99bcce

@ -65,6 +65,32 @@ pub async fn add_repository(
Ok(repositories)
}
#[tauri::command]
pub async fn remove_repository(app_state: AppAccess<'_>, name: String) -> PluginResult<()> {
let mut settings = app_state.settings.write().await;
if let Some(_repo) = settings.repositories.remove(&name) {
save_settings(&settings)?;
Ok(())
} else {
Err(PluginError::from(format!(
"The repository '{}' does not exist.",
name
)))
}
}
#[tauri::command]
pub async fn check_local_repository_exists(path: String) -> PluginResult<bool> {
let config_path = PathBuf::from(path).join(REPO_CONFIG_FILE);
if !config_path.exists() {
Ok(false)
} else {
Ok(true)
}
}
#[tauri::command]
pub async fn disconnect_repository(
app_state: AppAccess<'_>,
@ -104,15 +130,7 @@ pub async fn select_repository(
.ok_or(PluginError::from(
format!("Repository '{}' not found", name).as_str(),
))?;
if let Some(path) = app_state
.active_repo
.read()
.await
.clone()
.and_then(|r| r.path)
{
app_state.stop_running_daemon(&path).await?;
}
close_selected_repository(&app_state).await?;
let address = if let Some(address) = &repo.address {
address.clone()
} else {
@ -142,6 +160,20 @@ pub async fn select_repository(
Ok(())
}
async fn close_selected_repository(app_state: &AppAccess<'_>) -> PluginResult<()> {
if let Some(path) = app_state
.active_repo
.read()
.await
.clone()
.and_then(|r| r.path)
{
app_state.stop_running_daemon(&path).await?;
}
Ok(())
}
async fn read_repo_config(path: PathBuf) -> PluginResult<RepoConfig> {
let toml_str = fs::read_to_string(path).await?;
let config = toml::from_str(&toml_str)?;

@ -27,6 +27,12 @@ impl From<&str> for PluginError {
}
}
impl From<String> for PluginError {
fn from(message: String) -> Self {
Self { message }
}
}
impl From<ApiError> for PluginError {
fn from(e: ApiError) -> Self {
let message = match e {

@ -45,7 +45,9 @@ impl<R: Runtime> MediarepoPlugin<R> {
check_daemon_running,
stop_daemon,
disconnect_repository,
close_local_repository
close_local_repository,
check_local_repository_exists,
remove_repository
]),
}
}

Loading…
Cancel
Save