From 4d8a1d44cc52c855c0832b40580c0b4da7999469 Mon Sep 17 00:00:00 2001 From: reya Date: Tue, 19 Nov 2024 08:23:43 +0700 Subject: [PATCH] initial commit --- .gitignore | 21 ++++++++++++++++++ Cargo.toml | 37 +++++++++++++++++++++++++++++++ README.md | 12 ++++++++++ crates/nostr/Cargo.toml | 9 ++++++++ crates/nostr/src/lib.rs | 1 + crates/nostr/src/state.rs | 37 +++++++++++++++++++++++++++++++ crates/ui/Cargo.toml | 14 ++++++++++++ crates/ui/src/main.rs | 46 +++++++++++++++++++++++++++++++++++++++ 8 files changed, 177 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.toml create mode 100644 README.md create mode 100644 crates/nostr/Cargo.toml create mode 100644 crates/nostr/src/lib.rs create mode 100644 crates/nostr/src/state.rs create mode 100644 crates/ui/Cargo.toml create mode 100644 crates/ui/src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..64bf0eb --- /dev/null +++ b/.gitignore @@ -0,0 +1,21 @@ +# Generated by Cargo +# will have compiled files and executables +debug/ +target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk + +# MSVC Windows builds of rustc generate these, which store debugging information +*.pdb + +# RustRover +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..f71cbe1 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,37 @@ +[workspace] +members = ["crates/*"] +default-members = ["crates/ui"] +resolver = "2" + +[workspace.dependencies] +coop = { path = "crates/*" } + +# Account +keyring-search = "1.2.0" +keyring = { version = "3", features = [ + "apple-native", + "windows-native", + "linux-native", +] } + +# UI +gpui = { git = "https://github.com/zed-industries/zed" } +components = { package = "ui", git = "https://github.com/longbridgeapp/gpui-component", version = "0.1.0" } + +# Nostr +nostr-relay-builder = { git = "https://github.com/rust-nostr/nostr" } +nostr-sdk = { git = "https://github.com/rust-nostr/nostr", features = [ + "lmdb", + "all-nips", +] } + +tokio = { version = "1", features = ["full"] } +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" +dirs = "5.0" +itertools = "0.13.0" +futures = "0.3.30" +chrono = "0.4.38" +tracing = "0.1.40" +anyhow = "1.0.44" +smallvec = "1.13.2" diff --git a/README.md b/README.md new file mode 100644 index 0000000..2f542c9 --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +# coop + +Created with Create GPUI App. + +- [`gpui`](https://www.gpui.rs/) +- [GPUI documentation](https://github.com/zed-industries/zed/tree/main/crates/gpui/docs) +- [GPUI examples](https://github.com/zed-industries/zed/tree/main/crates/gpui/examples) + +## Usage + +- Ensure Rust is installed - [Rustup](https://rustup.rs/) +- Run your app with `cargo run` diff --git a/crates/nostr/Cargo.toml b/crates/nostr/Cargo.toml new file mode 100644 index 0000000..ae340bd --- /dev/null +++ b/crates/nostr/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "nostr" +version = "0.1.0" +edition = "2021" + +[dependencies] +nostr-sdk.workspace = true +dirs.workspace = true +tokio.workspace = true diff --git a/crates/nostr/src/lib.rs b/crates/nostr/src/lib.rs new file mode 100644 index 0000000..266c62a --- /dev/null +++ b/crates/nostr/src/lib.rs @@ -0,0 +1 @@ +pub mod state; diff --git a/crates/nostr/src/state.rs b/crates/nostr/src/state.rs new file mode 100644 index 0000000..19dd857 --- /dev/null +++ b/crates/nostr/src/state.rs @@ -0,0 +1,37 @@ +use dirs::config_dir; +use nostr_sdk::prelude::*; +use std::fs; +use tokio::sync::OnceCell; + +pub static CLIENT: OnceCell = OnceCell::const_new(); + +pub async fn get_client() -> &'static Client { + CLIENT + .get_or_init(|| async { + // Setup app data folder + let config_dir = config_dir().unwrap(); + let _ = fs::create_dir_all(config_dir.join("Coop/")); + + // Setup database + let lmdb = NostrLMDB::open(config_dir.join("Coop/nostr")) + .expect("Database is NOT initialized"); + + // Setup Nostr Client + let client = ClientBuilder::default().database(lmdb).build(); + + // Add some bootstrap relays + let _ = client.add_relay("wss://relay.damus.io").await; + let _ = client.add_relay("wss://relay.primal.net").await; + let _ = client.add_relay("wss://nostr.fmt.wiz.biz").await; + let _ = client.add_relay("wss://directory.yabu.me").await; + let _ = client.add_relay("wss://purplepag.es").await; + let _ = client.add_relay("wss://user.kindpag.es/").await; + + // Connect to all relays + client.connect().await; + + // Return client + client + }) + .await +} diff --git a/crates/ui/Cargo.toml b/crates/ui/Cargo.toml new file mode 100644 index 0000000..5fa7866 --- /dev/null +++ b/crates/ui/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "coop" +version = "0.1.0" +edition = "2021" +publish = false + +[[bin]] +name = "coop" +path = "src/main.rs" + +[dependencies] +gpui.workspace = true +tokio.workspace = true +nostr = { version = "0.1.0", path = "../nostr" } diff --git a/crates/ui/src/main.rs b/crates/ui/src/main.rs new file mode 100644 index 0000000..8a74505 --- /dev/null +++ b/crates/ui/src/main.rs @@ -0,0 +1,46 @@ +use gpui::*; +use nostr::state::get_client; + +struct HelloWorld { + text: SharedString, +} + +impl Render for HelloWorld { + fn render(&mut self, _cx: &mut ViewContext) -> impl IntoElement { + div() + .bg(rgb(0xffffff)) + .flex() + .size_full() + .justify_center() + .items_center() + .child(format!("Hello, {}!", &self.text)) + } +} + +#[tokio::main] +async fn main() { + let _client = get_client().await; + + App::new().run(|cx: &mut AppContext| { + let bounds = Bounds::centered(None, size(px(860.0), px(650.0)), cx); + + cx.open_window( + WindowOptions { + window_bounds: Some(WindowBounds::Windowed(bounds)), + window_decorations: Some(WindowDecorations::Client), + titlebar: Some(TitlebarOptions { + title: Some(SharedString::new_static("coop")), + appears_transparent: true, + ..Default::default() + }), + ..Default::default() + }, + |cx| { + cx.new_view(|_cx| HelloWorld { + text: "coop".into(), + }) + }, + ) + .unwrap(); + }); +}