feat: add si cli
This commit is contained in:
@@ -9,6 +9,7 @@ signed_core = { path = "../signed_core" }
|
||||
signed_git = { path = "../signed_git" }
|
||||
signed_nostr = { path = "../signed_nostr" }
|
||||
settings = { path = "../settings" }
|
||||
paths = { path = "../paths" }
|
||||
utils = { path = "../utils" }
|
||||
|
||||
nostr.workspace = true
|
||||
|
||||
@@ -41,6 +41,8 @@ pub enum BackendEvent {
|
||||
status: PushStepStatus,
|
||||
},
|
||||
Error(String),
|
||||
/// The relay list, profile and grasp list of a new identity were published; `Err` when no relay took them.
|
||||
IdentityPublished(Result<(), String>),
|
||||
}
|
||||
|
||||
impl BackendEvent {
|
||||
@@ -550,13 +552,19 @@ impl Backend {
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
cx.spawn(async move |this, cx| {
|
||||
if let Err(error) = futures::future::try_join_all(publishes).await {
|
||||
this.update(cx, |_this, cx| {
|
||||
cx.emit(BackendEvent::error(format!(
|
||||
"identity created, but publishing it failed: {error}"
|
||||
)));
|
||||
})?;
|
||||
}
|
||||
let published = futures::future::try_join_all(publishes)
|
||||
.await
|
||||
.map(|_| ())
|
||||
.map_err(|error| {
|
||||
format!("identity created, but publishing it failed: {error}")
|
||||
});
|
||||
|
||||
this.update(cx, |_this, cx| {
|
||||
if let Err(message) = &published {
|
||||
cx.emit(BackendEvent::error(message.clone()));
|
||||
}
|
||||
cx.emit(BackendEvent::IdentityPublished(published));
|
||||
})?;
|
||||
|
||||
Ok::<(), anyhow::Error>(())
|
||||
})
|
||||
@@ -1153,7 +1161,7 @@ impl Backend {
|
||||
self.passphrase_required
|
||||
}
|
||||
|
||||
pub fn sign_out(&mut self, cx: &mut Context<Self>) {
|
||||
pub fn sign_out(&mut self, cx: &mut Context<Self>) -> Task<Result<(), Error>> {
|
||||
self.supersede_session();
|
||||
// Nothing may be signed with the identity the user just left.
|
||||
self.signer.swap_inner(Keys::generate());
|
||||
@@ -1165,6 +1173,11 @@ impl Backend {
|
||||
});
|
||||
|
||||
let delete = cx.delete_credentials(USER_KEYRING);
|
||||
|
||||
cx.emit(BackendEvent::SignerChanged);
|
||||
cx.emit(BackendEvent::SignerRequired);
|
||||
cx.notify();
|
||||
|
||||
cx.spawn(async move |this, cx| {
|
||||
if let Err(error) = delete.await {
|
||||
this.update(cx, |_this, cx| {
|
||||
@@ -1176,10 +1189,6 @@ impl Backend {
|
||||
|
||||
Ok::<(), Error>(())
|
||||
})
|
||||
.detach();
|
||||
cx.emit(BackendEvent::SignerChanged);
|
||||
cx.emit(BackendEvent::SignerRequired);
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
fn sync_inbox(&mut self, cx: &mut Context<Self>) {
|
||||
|
||||
@@ -12,8 +12,6 @@ mod repos;
|
||||
mod state;
|
||||
mod sync_status;
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
pub use backend::{Backend, BackendEvent};
|
||||
pub use bootstrap::{sync_bootstrap_only, user_grasp_list_servers};
|
||||
pub use checkouts::CheckoutsStore;
|
||||
@@ -26,17 +24,29 @@ pub use push::{GraspServer, PushOutcome};
|
||||
pub use refresh::{RefreshGate, RefreshRequest};
|
||||
pub use repo::RepoStore;
|
||||
pub use repos::RepoListStore;
|
||||
use settings::SettingsStore;
|
||||
pub use signed_git::{Nip34Binding, Nip34Kind};
|
||||
use signed_nostr::NostrBackend;
|
||||
pub use state::{GitPushMode, GitPushPolicy, GitRef, PushStep, PushStepStatus, SyncState};
|
||||
pub use sync_status::{CheckoutSyncStatus, SyncEvent, SyncStatusDirectory, SyncStatusStore};
|
||||
|
||||
pub fn init(
|
||||
db_path: impl AsRef<Path>,
|
||||
repos_root: impl Into<PathBuf>,
|
||||
scan_paths: Vec<PathBuf>,
|
||||
cx: &mut App,
|
||||
) -> anyhow::Result<()> {
|
||||
/// Loads the settings, creates the data directories and installs the stores every frontend shares.
|
||||
pub fn init(cx: &mut App) -> anyhow::Result<()> {
|
||||
SettingsStore::set_global(cx.new(|_| SettingsStore::new(paths::settings_file())), cx);
|
||||
|
||||
let scan_paths = SettingsStore::global(cx)
|
||||
.read(cx)
|
||||
.settings()
|
||||
.local_repos
|
||||
.scan_paths
|
||||
.clone();
|
||||
|
||||
for dir in [paths::nostr_dir(), paths::repos_dir()] {
|
||||
if let Err(error) = std::fs::create_dir_all(dir) {
|
||||
log::warn!("failed to create {}: {error}", dir.display());
|
||||
}
|
||||
}
|
||||
|
||||
// rustls uses the `aws_lc_rs` provider by default.
|
||||
if rustls::crypto::aws_lc_rs::default_provider()
|
||||
.install_default()
|
||||
@@ -45,7 +55,7 @@ pub fn init(
|
||||
log::debug!("a crypto provider is already installed");
|
||||
}
|
||||
|
||||
let db_path = db_path.as_ref().to_path_buf();
|
||||
let db_path = paths::nostr_dir().to_path_buf();
|
||||
|
||||
let backend = match cx
|
||||
.foreground_executor()
|
||||
@@ -89,7 +99,7 @@ pub fn init(
|
||||
|
||||
let (client, signer) = (backend.client, backend.signer);
|
||||
|
||||
Mirrors::install(repos_root);
|
||||
Mirrors::install(paths::repos_dir().to_path_buf());
|
||||
|
||||
Backend::set_global(cx.new(|cx| Backend::new(client, signer, cx)), cx);
|
||||
RepoListStore::set_global(cx.new(RepoListStore::new), cx);
|
||||
|
||||
Reference in New Issue
Block a user