Skip to content

Commit

Permalink
Added error printing
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicletz committed Dec 8, 2024
1 parent 2832200 commit c2cc35b
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,25 @@ use automerge::transaction::Transactable;
use automerge::ObjType;
use std::cell::RefCell;
use automerge::ObjId;

use std::sync::mpsc::{Receiver, Sender};
mod imp {
use super::*;

#[derive(Debug)]
pub struct AardvarkApplication {
automerge: RefCell<AutoCommit>,
root: ObjId,
tx: Sender<Vec<u8>>,
rx: Receiver<Vec<u8>>,
}

impl AardvarkApplication {
fn update_text(&self, text: &str) {
println!("app: {}", text);
let ret = self.tx.send(text.as_bytes().to_vec());
if ret.is_err() {
println!("error sending message to network: {:?}", ret.err().unwrap().to_string());
}
let mut doc = self.automerge.borrow_mut();
doc.update_text(&self.root, text).unwrap();
}
Expand All @@ -60,9 +66,14 @@ mod imp {
let mut am = AutoCommit::new();
let root = am.put_object(automerge::ROOT, "root", ObjType::Text).unwrap();
let automerge = RefCell::new(am);

let (tx, rx) = network::run().expect("running p2p backend");

AardvarkApplication {
automerge,
root,
tx: tx,
rx: rx,
}
}
}
Expand Down Expand Up @@ -97,8 +108,6 @@ mod imp {
window.upcast()
});

network::run().expect("running p2p backend");

// Ask the window manager/compositor to present the window
window.present();
}
Expand Down

0 comments on commit c2cc35b

Please sign in to comment.