feat(v2): add PTY backend with portable-pty

- Implement PtyManager: spawn, write, resize, kill operations
- Wire Tauri commands: pty_spawn, pty_write, pty_resize, pty_kill
- Reader thread streams PTY output via Tauri events (pty-data-{id})
- Process exit detection emits pty-exit-{id} event
- Add portable-pty 0.8 and uuid 1.0 dependencies
This commit is contained in:
Hibryda 2026-03-05 23:42:20 +01:00
parent 406683799b
commit f15e60be60
4 changed files with 384 additions and 17 deletions

View file

@ -1,16 +1,69 @@
mod pty;
mod sidecar;
mod watcher;
mod session;
use pty::{PtyManager, PtyOptions};
use std::sync::Arc;
use tauri::State;
struct AppState {
pty_manager: Arc<PtyManager>,
}
#[tauri::command]
fn pty_spawn(
app: tauri::AppHandle,
state: State<'_, AppState>,
options: PtyOptions,
) -> Result<String, String> {
state.pty_manager.spawn(&app, options)
}
#[tauri::command]
fn pty_write(state: State<'_, AppState>, id: String, data: String) -> Result<(), String> {
state.pty_manager.write(&id, &data)
}
#[tauri::command]
fn pty_resize(
state: State<'_, AppState>,
id: String,
cols: u16,
rows: u16,
) -> Result<(), String> {
state.pty_manager.resize(&id, cols, rows)
}
#[tauri::command]
fn pty_kill(state: State<'_, AppState>, id: String) -> Result<(), String> {
state.pty_manager.kill(&id)
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
tauri::Builder::default()
.setup(|app| {
if cfg!(debug_assertions) {
app.handle().plugin(
tauri_plugin_log::Builder::default()
.level(log::LevelFilter::Info)
.build(),
)?;
}
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
let app_state = AppState {
pty_manager: Arc::new(PtyManager::new()),
};
tauri::Builder::default()
.manage(app_state)
.invoke_handler(tauri::generate_handler![
pty_spawn,
pty_write,
pty_resize,
pty_kill,
])
.setup(|app| {
if cfg!(debug_assertions) {
app.handle().plugin(
tauri_plugin_log::Builder::default()
.level(log::LevelFilter::Info)
.build(),
)?;
}
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}