Add M3: APPDATA persistence + presets + per-pane distro/label
Backend:
- save_workspace / load_workspace Tauri commands writing to
%APPDATA%\com.megaproxy.tiletopia\workspace.json with atomic
tmp+rename. Path from app.path().app_config_dir() (no dirs crate).
Layout helpers:
- tree.ts: changeDistro (with id swap to force XtermPane remount via
{#key}), changeLabel, presetSingle / TwoColumns / ThreeColumns /
TwoRows / TwoByTwo.
- New ops.ts with PaneOps interface bundling split / close /
setDistro / setLabel / distros, drilled through Pane chain
instead of individual callbacks.
UI:
- LeafPane: in-toolbar editable label (click to rename, Enter
saves, Esc cancels) and distro chip popover. Picking a different
distro respawns the pane.
- App.svelte: migrated from localStorage to APPDATA via the new
Tauri commands, debounced 500ms. One-time localStorage migration
on boot. Split inherits parent's distro+cwd. Titlebar preset
buttons with confirm when replacing >1 pane.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
1869d08181
commit
64b90ebddb
10 changed files with 434 additions and 74 deletions
|
|
@ -1,10 +1,12 @@
|
|||
//! Tauri command surface. Every JS-callable function lives here.
|
||||
|
||||
use base64::{engine::general_purpose::STANDARD as B64, Engine as _};
|
||||
use tauri::AppHandle;
|
||||
use tauri::{AppHandle, Manager};
|
||||
|
||||
use crate::pty::{list_wsl_distros, PaneId, PtyManager};
|
||||
|
||||
const WORKSPACE_FILE: &str = "workspace.json";
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn list_distros() -> Result<Vec<String>, String> {
|
||||
list_wsl_distros().map_err(|e| e.to_string())
|
||||
|
|
@ -55,3 +57,38 @@ pub async fn kill_pane(
|
|||
) -> Result<(), String> {
|
||||
manager.kill(id).map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
/// Write the workspace JSON to `%APPDATA%\com.megaproxy.tiletopia\workspace.json`.
|
||||
/// Writes to a `.tmp` and renames over the real file so a crash mid-write
|
||||
/// can't leave a partial file readable.
|
||||
#[tauri::command]
|
||||
pub async fn save_workspace(app: AppHandle, json: String) -> Result<(), String> {
|
||||
let dir = app
|
||||
.path()
|
||||
.app_config_dir()
|
||||
.map_err(|e| format!("app_config_dir: {e}"))?;
|
||||
std::fs::create_dir_all(&dir).map_err(|e| format!("create_dir_all: {e}"))?;
|
||||
let path = dir.join(WORKSPACE_FILE);
|
||||
let tmp = dir.join(format!("{WORKSPACE_FILE}.tmp"));
|
||||
std::fs::write(&tmp, json.as_bytes()).map_err(|e| format!("write tmp: {e}"))?;
|
||||
// `std::fs::rename` is atomic on Unix and uses MoveFileEx with
|
||||
// REPLACE_EXISTING on Windows (>= Rust 1.50).
|
||||
std::fs::rename(&tmp, &path).map_err(|e| format!("rename: {e}"))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Read the workspace JSON. Returns `None` if the file doesn't exist yet
|
||||
/// (first launch).
|
||||
#[tauri::command]
|
||||
pub async fn load_workspace(app: AppHandle) -> Result<Option<String>, String> {
|
||||
let dir = app
|
||||
.path()
|
||||
.app_config_dir()
|
||||
.map_err(|e| format!("app_config_dir: {e}"))?;
|
||||
let path = dir.join(WORKSPACE_FILE);
|
||||
if !path.exists() {
|
||||
return Ok(None);
|
||||
}
|
||||
let s = std::fs::read_to_string(&path).map_err(|e| format!("read: {e}"))?;
|
||||
Ok(Some(s))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ pub fn run() {
|
|||
commands::write_to_pane,
|
||||
commands::resize_pane,
|
||||
commands::kill_pane,
|
||||
commands::save_workspace,
|
||||
commands::load_workspace,
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue