diff --git a/src-tauri/src/app.rs b/src-tauri/src/app.rs index 31e928a42..29dac64ca 100644 --- a/src-tauri/src/app.rs +++ b/src-tauri/src/app.rs @@ -496,10 +496,7 @@ impl App { ) .context("failed to open repository")?; - let session = gb_repository - .get_or_create_current_session() - .context("failed to get session")?; - let writer = sessions::Writer::open(&gb_repository, &session)?; + let pty_writer = pty::Writer::new(&gb_repository)?; let timestamp = std::time::SystemTime::now() .duration_since(std::time::UNIX_EPOCH) @@ -512,7 +509,7 @@ impl App { bytes: bytes.to_vec(), }; - writer.append_pty(&record).context("failed to append pty")?; + pty_writer.write(&record).context("failed to append pty")?; Ok(()) } diff --git a/src-tauri/src/pty/mod.rs b/src-tauri/src/pty/mod.rs index f53923886..36e3c4d98 100644 --- a/src-tauri/src/pty/mod.rs +++ b/src-tauri/src/pty/mod.rs @@ -1,6 +1,8 @@ mod connection; mod recorder; mod server; +mod writer; pub use recorder::{Record, Type}; pub use server::start_server; +pub use writer::PtyWriter as Writer; diff --git a/src-tauri/src/pty/writer.rs b/src-tauri/src/pty/writer.rs new file mode 100644 index 000000000..4b3a3bf95 --- /dev/null +++ b/src-tauri/src/pty/writer.rs @@ -0,0 +1,37 @@ +use anyhow::{Context, Result}; + +use crate::gb_repository; + +use super::Record; + +pub struct PtyWriter<'writer> { + repository: &'writer gb_repository::Repository, +} + +impl<'writer> PtyWriter<'writer> { + pub fn new(repository: &'writer gb_repository::Repository) -> Result { + repository + .get_or_create_current_session() + .context("failed to create session")?; + Ok(Self { repository }) + } + + pub fn write(&self, record: &Record) -> Result<()> { + self.repository.lock()?; + defer! { + self.repository.unlock().expect("failed to unlock"); + } + + serde_jsonlines::append_json_lines( + self.repository.session_path().join("pty.jsonl"), + [record], + )?; + + log::info!( + "{}: appended pty record to session", + self.repository.project_id + ); + + Ok(()) + } +} diff --git a/src-tauri/src/sessions/writer.rs b/src-tauri/src/sessions/writer.rs index 485addbaa..d4411aead 100644 --- a/src-tauri/src/sessions/writer.rs +++ b/src-tauri/src/sessions/writer.rs @@ -3,7 +3,7 @@ use std::time; use anyhow::{anyhow, Context, Result}; use crate::{ - bookmarks, gb_repository, pty, + bookmarks, gb_repository, reader::{self, Reader}, writer::{self, Writer}, }; @@ -127,25 +127,6 @@ impl<'writer> SessionWriter<'writer> { Ok(writer) } - pub fn append_pty(&self, record: &pty::Record) -> Result<()> { - self.repository.lock()?; - defer! { - self.repository.unlock().expect("failed to unlock"); - } - - serde_jsonlines::append_json_lines( - self.repository.session_path().join("pty.jsonl"), - [record], - )?; - - log::info!( - "{}: appended pty record to session", - self.repository.project_id - ); - - Ok(()) - } - pub fn write_session_wd_file>( &self, path: P,