Compare commits

...
Sign in to create a new pull request.

2 commits
main ... async

Author SHA1 Message Date
07b63963d5 wagie start 2024-12-04 10:31:36 -05:00
f90866be8a add tokio runtime to hoot 2024-12-02 09:42:07 -05:00
4 changed files with 83 additions and 21 deletions

36
Cargo.lock generated
View file

@ -1131,9 +1131,9 @@ dependencies = [
[[package]]
name = "crossbeam-channel"
version = "0.5.12"
version = "0.5.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab3db02a9c5b5121e1e42fbdb1aeb65f5e02624cc58c43f2884c6ccac0b82f95"
checksum = "33480d6946193aa8033910124896ca395333cae7e2d1113d1fef6c3272217df2"
dependencies = [
"crossbeam-utils",
]
@ -2090,6 +2090,7 @@ dependencies = [
name = "hoot-app"
version = "0.1.0"
dependencies = [
"crossbeam-channel",
"eframe",
"egui_extras",
"egui_tabs",
@ -2103,6 +2104,7 @@ dependencies = [
"security-framework",
"serde",
"serde_json",
"tokio",
"tracing",
"tracing-appender",
"tracing-subscriber",
@ -2657,13 +2659,14 @@ dependencies = [
[[package]]
name = "mio"
version = "0.8.11"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c"
checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec"
dependencies = [
"hermit-abi",
"libc",
"wasi",
"windows-sys 0.48.0",
"windows-sys 0.52.0",
]
[[package]]
@ -2875,16 +2878,6 @@ dependencies = [
"autocfg",
]
[[package]]
name = "num_cpus"
version = "1.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43"
dependencies = [
"hermit-abi",
"libc",
]
[[package]]
name = "num_enum"
version = "0.7.2"
@ -4361,26 +4354,27 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]]
name = "tokio"
version = "1.38.0"
version = "1.41.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a"
checksum = "22cfb5bee7a6a52939ca9224d6ac897bb669134078daa8735560897f69de4d33"
dependencies = [
"backtrace",
"bytes",
"libc",
"mio",
"num_cpus",
"parking_lot",
"pin-project-lite",
"signal-hook-registry",
"socket2 0.5.7",
"tokio-macros",
"windows-sys 0.48.0",
"windows-sys 0.52.0",
]
[[package]]
name = "tokio-macros"
version = "2.3.0"
version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a"
checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752"
dependencies = [
"proc-macro2",
"quote",

View file

@ -28,6 +28,8 @@ rand = "0.8.5"
nostr = { version = "0.32.1", features = ["std", "nip59"] }
serde = "1.0.204"
serde_json = "1.0.121"
tokio = { version = "1.41.1", features = ["full"] }
crossbeam-channel = "0.5.13"
[target.'cfg(target_os = "macos")'.dependencies]
security-framework = "3.0.0"

View file

@ -5,6 +5,7 @@ use egui::FontFamily::Proportional;
use egui_extras::{Column, TableBuilder};
use std::collections::HashMap;
use tracing::{debug, error, info, Level};
use tokio::runtime;
mod account_manager;
mod error;
@ -12,6 +13,7 @@ mod keystorage;
mod mail_event;
mod relay;
mod ui;
mod wagie;
fn main() -> Result<(), eframe::Error> {
let (non_blocking, _guard) = tracing_appender::non_blocking(std::io::stdout()); // add log files in prod one day
@ -74,6 +76,7 @@ pub struct HootState {
}
pub struct Hoot {
rt: runtime::Runtime,
pub page: Page,
focused_post: String,
status: HootStatus,
@ -303,6 +306,10 @@ impl Hoot {
let ndb = nostrdb::Ndb::new(storage_dir.to_str().unwrap(), &ndb_config)
.expect("could not load nostrdb");
Self {
rt: runtime::Builder::new_multi_thread()
.enable_all()
.build()
.unwrap(),
page: Page::Inbox,
focused_post: "".into(),
status: HootStatus::Initalizing,

59
src/wagie/mod.rs Normal file
View file

@ -0,0 +1,59 @@
use tokio::sync::mpsc;
#[derive(Debug)]
pub enum Command {
Decrypt { content: String, pk: String }
}
#[derive(Debug)]
pub enum Response {
DecryptedText
}
pub struct Boss {
from_wagie: crossbeam_channel::Receiver<Response>,
to_wagie: mpsc::UnboundedSender<Command>,
}
impl Boss {
pub fn init() -> Self {
let (from_wagie_sender, from_wagie_receiver) = crossbeam_channel::unbounded::<Response>();
let (to_wagie_sender, to_wagie_receiver) = mpsc::unbounded_channel::<Command>();
tokio::spawn(async move {
let mut wagie = Wagie::init(to_wagie_receiver, from_wagie_sender);
wagie.run().await;
});
Self {
from_wagie: from_wagie_receiver,
to_wagie: to_wagie_sender,
}
}
}
pub struct Wagie {
to_boss: crossbeam_channel::Sender<Response>,
from_boss: mpsc::UnboundedReceiver<Command>,
}
impl Wagie {
pub fn init(from_boss: mpsc::UnboundedReceiver<Command>, to_boss: crossbeam_channel::Sender<Response>) -> Self {
Self {
to_boss,
from_boss,
}
}
async fn run(&mut self) {
while let Some(command) = self.from_boss.recv().await {
match command {
Command::Decrypt { content, pk } => {
// Process the decrypt command
// For now, just send a dummy response
let _ = self.to_boss.send(Response::DecryptedText);
}
}
}
}
}