-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7dbb705
commit 218bd9f
Showing
4 changed files
with
119 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod node; | ||
pub mod repos; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use tauri::State; | ||
|
||
use radicle::node::address::Store; | ||
use radicle::node::Handle; | ||
use radicle::{Node, Profile}; | ||
|
||
use crate::error::Error; | ||
use crate::types::NodeInfo; | ||
|
||
#[tauri::command] | ||
pub fn node_info(profile: State<Profile>) -> Result<NodeInfo, Error> { | ||
let node = Node::new(profile.socket()); | ||
let home = profile.home.database()?; | ||
let agent = home | ||
.get(&profile.public_key) | ||
.unwrap_or_default() | ||
.map(|node| node.agent); | ||
let node_state = if node.is_running() { | ||
"running" | ||
} else { | ||
"stopped" | ||
}; | ||
|
||
Ok(NodeInfo { | ||
id: profile.public_key, | ||
alias: node.config().ok().map(|c| c.alias), | ||
agent, | ||
state: node_state.to_string(), | ||
avatar_url: profile.config.web.avatar_url.clone(), | ||
banner_url: profile.config.web.banner_url.clone(), | ||
description: profile.config.web.description.clone(), | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
use radicle::issue::cache::Issues; | ||
use radicle::node::routing::Store; | ||
use radicle::patch::cache::Patches; | ||
use radicle::storage::{ReadRepository, ReadStorage}; | ||
use radicle::Profile; | ||
use tauri::State; | ||
|
||
use crate::types::Author; | ||
use crate::{error::Error, types::RepositoryInfo}; | ||
|
||
#[tauri::command] | ||
pub fn repo_list(profile: State<Profile>) -> Result<Vec<RepositoryInfo>, Error> { | ||
let storage = &profile.storage; | ||
let db = &profile.database()?; | ||
|
||
let mut repos = storage.repositories()?.into_iter().collect::<Vec<_>>(); | ||
repos.sort_by_key(|p| p.rid); | ||
|
||
let infos = repos | ||
.into_iter() | ||
.filter_map(|info| { | ||
let Ok(repo) = storage.repository(info.rid) else { | ||
return None; | ||
}; | ||
let Ok((_, head)) = repo.head() else { | ||
return None; | ||
}; | ||
let Ok(commit) = repo.commit(head) else { | ||
return None; | ||
}; | ||
let Ok(payload) = info.doc.project() else { | ||
return None; | ||
}; | ||
let Ok(issues) = profile.issues(&repo) else { | ||
return None; | ||
}; | ||
let Ok(issues) = issues.counts() else { | ||
return None; | ||
}; | ||
let Ok(patches) = profile.patches(&repo) else { | ||
return None; | ||
}; | ||
let Ok(patches) = patches.counts() else { | ||
return None; | ||
}; | ||
let aliases = profile.aliases(); | ||
let delegates = info | ||
.doc | ||
.delegates | ||
.into_iter() | ||
.map(|did| Author::new(*did, &aliases)) | ||
.collect::<Vec<_>>(); | ||
let seeding = db.count(&info.rid).unwrap_or_default(); | ||
let last_update = commit.committer().when().seconds(); | ||
|
||
Some(RepositoryInfo { | ||
name: payload.name().to_owned(), | ||
description: payload.description().to_owned(), | ||
default_branch: payload.default_branch().to_owned(), | ||
delegates, | ||
head, | ||
threshold: info.doc.threshold, | ||
visibility: info.doc.visibility, | ||
issues, | ||
patches, | ||
id: info.rid, | ||
seeding, | ||
last_update, | ||
}) | ||
}) | ||
.collect::<Vec<_>>(); | ||
|
||
Ok(infos) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
#[tauri::command] | ||
fn greet(name: &str) -> String { | ||
format!("Hello, {}!", name) | ||
} | ||
mod commands; | ||
mod error; | ||
mod types; | ||
|
||
use commands::{node, repos}; | ||
use radicle::Profile; | ||
|
||
#[cfg_attr(mobile, tauri::mobile_entry_point)] | ||
pub fn run() { | ||
let profile = Profile::load().expect("Not able to load profile"); | ||
|
||
tauri::Builder::default() | ||
.manage(profile) | ||
.plugin(tauri_plugin_shell::init()) | ||
.invoke_handler(tauri::generate_handler![greet]) | ||
.invoke_handler(tauri::generate_handler![repos::repo_list, node::node_info]) | ||
.run(tauri::generate_context!()) | ||
.expect("error while running tauri application"); | ||
} |