feat: implement a basic backend (#1)

Reviewed-on: https://git.reya.su/reya/signed/pulls/1
This commit was merged in pull request #1.
This commit is contained in:
2026-08-05 00:57:52 +00:00
parent 9809b986af
commit 7249a323f8
22 changed files with 4033 additions and 21 deletions
+50
View File
@@ -0,0 +1,50 @@
mod backend;
mod profile;
mod repo;
mod repo_list;
use std::path::Path;
pub use backend::{Backend, BackendEvent};
use gpui::{App, AppContext, Entity};
pub use profile::{Profile, ProfileStore, shorten_pubkey};
pub use repo::RepoStore;
pub use repo_list::RepoListStore;
use signed_nostr::NostrBackend;
/// Initialize the backend and stores, and install them as globals. Call once
/// at startup, before opening any window that uses the stores.
#[cfg(not(target_arch = "wasm32"))]
pub fn init(db_path: impl AsRef<Path>, cx: &mut App) -> Entity<Backend> {
// rustls uses the `aws_lc_rs` provider by default; ignore if already installed.
rustls::crypto::aws_lc_rs::default_provider()
.install_default()
.ok();
let path = db_path.as_ref().to_path_buf();
let inner = cx.foreground_executor().block_on(async move {
NostrBackend::new(path)
.await
.expect("failed to initialize nostr backend")
});
let entity = cx.new(|cx| Backend::new(inner, cx));
Backend::set_global(entity.clone(), cx);
ProfileStore::set_global(cx.new(ProfileStore::new), cx);
entity
}
/// Initialize the backend with an in-memory database on wasm.
#[cfg(target_arch = "wasm32")]
pub fn init(cx: &mut App) -> Entity<Backend> {
let inner = NostrBackend::new().expect("failed to initialize nostr backend");
let entity = cx.new(|cx| Backend::new(inner, cx));
Backend::set_global(entity.clone(), cx);
ProfileStore::set_global(cx.new(ProfileStore::new), cx);
entity
}