Radish alpha
r
Radicle desktop app
Radicle
Git (anonymous pull)
Log in to clone via SSH
Add Tauri commands for release CRUD + settings
Daniel Norman committed 7 days ago
commit 02827e993ba139541ffcf7f38b3c8777dddd8ca3
parent 9c5b661190b1a5b78dd9086c98b01903b73e6f6b
3 files changed +172 -0
modified crates/radicle-tauri/src/commands/cob.rs
@@ -13,6 +13,7 @@ use crate::AppState;
pub mod issue;
pub mod job;
pub mod patch;
+
pub mod release;

#[tauri::command]
pub async fn get_embed(
added crates/radicle-tauri/src/commands/cob/release.rs
@@ -0,0 +1,159 @@
+
use std::path::PathBuf;
+

+
use radicle::git;
+
use radicle::identity::RepoId;
+
use radicle_types::cobs::release;
+
use radicle_types::error::Error;
+
use radicle_types::traits::release::Releases;
+
use radicle_types::traits::release_mut::ReleasesMut;
+

+
use crate::AppState;
+

+
#[tauri::command]
+
pub async fn list_releases(
+
    ctx: tauri::State<'_, AppState>,
+
    rid: RepoId,
+
) -> Result<Vec<release::Release>, Error> {
+
    let ctx = ctx.inner().clone();
+
    tauri::async_runtime::spawn_blocking(move || ctx.list_releases(rid))
+
        .await
+
        .map_err(|e| Error::Iroh(format!("join: {e}")))?
+
}
+

+
#[tauri::command]
+
pub async fn release_by_id(
+
    ctx: tauri::State<'_, AppState>,
+
    rid: RepoId,
+
    release_id: String,
+
) -> Result<Option<release::Release>, Error> {
+
    let ctx = ctx.inner().clone();
+
    tauri::async_runtime::spawn_blocking(move || ctx.release_by_id(rid, release_id))
+
        .await
+
        .map_err(|e| Error::Iroh(format!("join: {e}")))?
+
}
+

+
#[tauri::command]
+
pub async fn releases_by_commit(
+
    ctx: tauri::State<'_, AppState>,
+
    rid: RepoId,
+
    sha: git::Oid,
+
) -> Result<Vec<release::Release>, Error> {
+
    let ctx = ctx.inner().clone();
+
    tauri::async_runtime::spawn_blocking(move || ctx.releases_by_commit(rid, sha))
+
        .await
+
        .map_err(|e| Error::Iroh(format!("join: {e}")))?
+
}
+

+
/// CID computation can be expensive on large files; off-load to the
+
/// blocking pool so the IPC thread stays responsive.
+
#[tauri::command]
+
pub async fn compute_artifact_cid(
+
    ctx: tauri::State<'_, AppState>,
+
    path: PathBuf,
+
) -> Result<String, Error> {
+
    let ctx = ctx.inner().clone();
+
    tauri::async_runtime::spawn_blocking(move || ctx.compute_cid(path))
+
        .await
+
        .map_err(|e| Error::Iroh(format!("join: {e}")))?
+
}
+

+
#[tauri::command]
+
pub async fn create_or_open_release(
+
    ctx: tauri::State<'_, AppState>,
+
    rid: RepoId,
+
    oid: git::Oid,
+
) -> Result<String, Error> {
+
    let ctx = ctx.inner().clone();
+
    tauri::async_runtime::spawn_blocking(move || ctx.create_or_open_release(rid, oid))
+
        .await
+
        .map_err(|e| Error::Iroh(format!("join: {e}")))?
+
}
+

+
#[tauri::command]
+
pub async fn add_artifact(
+
    ctx: tauri::State<'_, AppState>,
+
    rid: RepoId,
+
    release_id: String,
+
    cid: String,
+
    name: String,
+
) -> Result<(), Error> {
+
    let ctx = ctx.inner().clone();
+
    tauri::async_runtime::spawn_blocking(move || ctx.add_artifact(rid, release_id, cid, name))
+
        .await
+
        .map_err(|e| Error::Iroh(format!("join: {e}")))?
+
}
+

+
#[tauri::command]
+
pub async fn add_location(
+
    ctx: tauri::State<'_, AppState>,
+
    rid: RepoId,
+
    release_id: String,
+
    cid: String,
+
    url: String,
+
) -> Result<(), Error> {
+
    let ctx = ctx.inner().clone();
+
    tauri::async_runtime::spawn_blocking(move || ctx.add_location(rid, release_id, cid, url))
+
        .await
+
        .map_err(|e| Error::Iroh(format!("join: {e}")))?
+
}
+

+
#[tauri::command]
+
pub async fn remove_location(
+
    ctx: tauri::State<'_, AppState>,
+
    rid: RepoId,
+
    release_id: String,
+
    cid: String,
+
    url: String,
+
) -> Result<(), Error> {
+
    let ctx = ctx.inner().clone();
+
    tauri::async_runtime::spawn_blocking(move || ctx.remove_location(rid, release_id, cid, url))
+
        .await
+
        .map_err(|e| Error::Iroh(format!("join: {e}")))?
+
}
+

+
#[tauri::command]
+
pub async fn attest_artifact(
+
    ctx: tauri::State<'_, AppState>,
+
    rid: RepoId,
+
    release_id: String,
+
    cid: String,
+
) -> Result<(), Error> {
+
    let ctx = ctx.inner().clone();
+
    tauri::async_runtime::spawn_blocking(move || ctx.attest_artifact(rid, release_id, cid))
+
        .await
+
        .map_err(|e| Error::Iroh(format!("join: {e}")))?
+
}
+

+
#[tauri::command]
+
pub async fn redact_artifact(
+
    ctx: tauri::State<'_, AppState>,
+
    rid: RepoId,
+
    release_id: String,
+
    cid: String,
+
    reason: String,
+
) -> Result<(), Error> {
+
    let ctx = ctx.inner().clone();
+
    tauri::async_runtime::spawn_blocking(move || {
+
        ctx.redact_artifact(rid, release_id, cid, reason)
+
    })
+
    .await
+
    .map_err(|e| Error::Iroh(format!("join: {e}")))?
+
}
+

+
// Settings ------------------------------------------------------------------
+

+
#[tauri::command]
+
pub fn get_auto_seed_artifacts(ctx: tauri::State<AppState>) -> Result<bool, Error> {
+
    let settings = radicle_types::settings::load(ctx.profile.home().path());
+
    Ok(settings.auto_seed_artifacts)
+
}
+

+
#[tauri::command]
+
pub fn set_auto_seed_artifacts(
+
    ctx: tauri::State<AppState>,
+
    enabled: bool,
+
) -> Result<(), Error> {
+
    let mut settings = radicle_types::settings::load(ctx.profile.home().path());
+
    settings.auto_seed_artifacts = enabled;
+
    radicle_types::settings::save(ctx.profile.home().path(), &settings)
+
}
modified crates/radicle-tauri/src/lib.rs
@@ -44,6 +44,18 @@ pub fn run() {
            cob::patch::revisions_by_patch,
            cob::patch::revision_by_patch_and_id,
            cob::patch::revisions_by_patch,
+
            cob::release::list_releases,
+
            cob::release::release_by_id,
+
            cob::release::releases_by_commit,
+
            cob::release::compute_artifact_cid,
+
            cob::release::create_or_open_release,
+
            cob::release::add_artifact,
+
            cob::release::add_location,
+
            cob::release::remove_location,
+
            cob::release::attest_artifact,
+
            cob::release::redact_artifact,
+
            cob::release::get_auto_seed_artifacts,
+
            cob::release::set_auto_seed_artifacts,
            cob::save_embed_by_bytes,
            cob::save_embed_by_clipboard,
            cob::save_embed_by_path,