Skip to content

Commit

Permalink
Send text updates to p2panda
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas2515 authored and swick committed Dec 8, 2024
1 parent e908d3a commit 5db1001
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use automerge::transaction::Transactable;
use automerge::ObjType;
use std::cell::RefCell;
use automerge::ObjId;
use tokio::sync::mpsc;

mod imp {
use super::*;
Expand All @@ -40,13 +41,16 @@ mod imp {
pub struct AardvarkApplication {
automerge: RefCell<AutoCommit>,
root: ObjId,
tx: mpsc::Sender<Vec<u8>>,
rx: mpsc::Receiver<Vec<u8>>,
}

impl AardvarkApplication {
fn update_text(&self, text: &str) {
println!("app: {}", text);
let mut doc = self.automerge.borrow_mut();
doc.update_text(&self.root, text).unwrap();
self.tx.send(doc.save());
}
}

Expand All @@ -60,9 +64,12 @@ 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,
rx,
}
}
}
Expand Down Expand Up @@ -97,8 +104,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 5db1001

Please sign in to comment.