wip: refactor
This commit is contained in:
10
Cargo.lock
generated
10
Cargo.lock
generated
@@ -1095,6 +1095,7 @@ dependencies = [
|
|||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"smol",
|
"smol",
|
||||||
|
"state",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
"ui",
|
"ui",
|
||||||
@@ -4905,6 +4906,15 @@ version = "1.2.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
|
checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "state"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"dirs 5.0.1",
|
||||||
|
"nostr-sdk",
|
||||||
|
"tokio",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "static_assertions"
|
name = "static_assertions"
|
||||||
version = "1.1.0"
|
version = "1.1.0"
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ path = "src/main.rs"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
ui = { path = "../ui" }
|
ui = { path = "../ui" }
|
||||||
common = { path = "../common" }
|
common = { path = "../common" }
|
||||||
|
state = { path = "../state" }
|
||||||
|
|
||||||
gpui.workspace = true
|
gpui.workspace = true
|
||||||
reqwest_client.workspace = true
|
reqwest_client.workspace = true
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ use common::constants::{
|
|||||||
ALL_MESSAGES_SUB_ID, APP_ID, APP_NAME, FAKE_SIG, KEYRING_SERVICE, METADATA_DELAY,
|
ALL_MESSAGES_SUB_ID, APP_ID, APP_NAME, FAKE_SIG, KEYRING_SERVICE, METADATA_DELAY,
|
||||||
NEW_MESSAGE_SUB_ID,
|
NEW_MESSAGE_SUB_ID,
|
||||||
};
|
};
|
||||||
use dirs::config_dir;
|
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions, point, px, size, App, AppContext, Bounds, SharedString, TitlebarOptions,
|
actions, point, px, size, App, AppContext, Bounds, SharedString, TitlebarOptions,
|
||||||
VisualContext, WindowBounds, WindowKind, WindowOptions,
|
VisualContext, WindowBounds, WindowKind, WindowOptions,
|
||||||
@@ -11,14 +10,9 @@ use gpui::{
|
|||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
use gpui::{WindowBackgroundAppearance, WindowDecorations};
|
use gpui::{WindowBackgroundAppearance, WindowDecorations};
|
||||||
use nostr_sdk::prelude::*;
|
use nostr_sdk::prelude::*;
|
||||||
|
use state::{get_client, initialize_client};
|
||||||
use states::{app::AppRegistry, chat::ChatRegistry};
|
use states::{app::AppRegistry, chat::ChatRegistry};
|
||||||
use std::{
|
use std::{collections::HashSet, str::FromStr, sync::Arc, time::Duration};
|
||||||
collections::HashSet,
|
|
||||||
fs,
|
|
||||||
str::FromStr,
|
|
||||||
sync::{Arc, OnceLock},
|
|
||||||
time::Duration,
|
|
||||||
};
|
|
||||||
use tokio::{
|
use tokio::{
|
||||||
sync::{mpsc, Mutex},
|
sync::{mpsc, Mutex},
|
||||||
time::sleep,
|
time::sleep,
|
||||||
@@ -31,9 +25,6 @@ mod states;
|
|||||||
mod views;
|
mod views;
|
||||||
|
|
||||||
actions!(main_menu, [Quit]);
|
actions!(main_menu, [Quit]);
|
||||||
actions!(app, [ReloadMetadata]);
|
|
||||||
|
|
||||||
static CLIENT: OnceLock<Client> = OnceLock::new();
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub enum Signal {
|
pub enum Signal {
|
||||||
@@ -43,29 +34,6 @@ pub enum Signal {
|
|||||||
Eose,
|
Eose,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn initialize_client() {
|
|
||||||
// Setup app data folder
|
|
||||||
let config_dir = config_dir().expect("Config directory not found");
|
|
||||||
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");
|
|
||||||
|
|
||||||
// Client options
|
|
||||||
let opts = Options::new()
|
|
||||||
.gossip(true)
|
|
||||||
.max_avg_latency(Duration::from_secs(2));
|
|
||||||
|
|
||||||
// Setup Nostr Client
|
|
||||||
let client = ClientBuilder::default().database(lmdb).opts(opts).build();
|
|
||||||
|
|
||||||
CLIENT.set(client).expect("Client is already initialized!");
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_client() -> &'static Client {
|
|
||||||
CLIENT.get().expect("Client is NOT initialized!")
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
tracing_subscriber::fmt::init();
|
tracing_subscriber::fmt::init();
|
||||||
|
|||||||
10
crates/state/Cargo.toml
Normal file
10
crates/state/Cargo.toml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
[package]
|
||||||
|
name = "state"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
publish = false
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
nostr-sdk.workspace = true
|
||||||
|
tokio.workspace = true
|
||||||
|
dirs.workspace = true
|
||||||
28
crates/state/src/lib.rs
Normal file
28
crates/state/src/lib.rs
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
use dirs::config_dir;
|
||||||
|
use nostr_sdk::prelude::*;
|
||||||
|
use std::{fs, sync::OnceLock, time::Duration};
|
||||||
|
|
||||||
|
static CLIENT: OnceLock<Client> = OnceLock::new();
|
||||||
|
|
||||||
|
pub fn initialize_client() {
|
||||||
|
// Setup app data folder
|
||||||
|
let config_dir = config_dir().expect("Config directory not found");
|
||||||
|
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");
|
||||||
|
|
||||||
|
// Client options
|
||||||
|
let opts = Options::new()
|
||||||
|
.gossip(true)
|
||||||
|
.max_avg_latency(Duration::from_secs(2));
|
||||||
|
|
||||||
|
// Setup Nostr Client
|
||||||
|
let client = ClientBuilder::default().database(lmdb).opts(opts).build();
|
||||||
|
|
||||||
|
CLIENT.set(client).expect("Client is already initialized!");
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_client() -> &'static Client {
|
||||||
|
CLIENT.get().expect("Client is NOT initialized!")
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user