Move blocking host work off the main thread and fix Git SSH settings

Window close no longer waits on the main thread. The handler revokes
browser sessions and plugin leases with short locks. A cleanup thread
stops terminals, closes browser tabs, and erases plugin review folders.
The browser cleanup sends closeTab without a wait for the reply, and
stops the engine outside the engine lock.

Terminal, plugin, background, and browser commands do their file,
process, and plugin-lock work on blocking workers. Terminal events go
to the window that opened the session. Command names, arguments,
results, and events do not change.

The Git service keeps GIT_SSH, GIT_SSH_COMMAND, GIT_SSH_VARIANT, and a
configured core.sshCommand. It adds its SSH defaults only when the user
has none. It still removes other inherited GIT_* variables.

After the first check, Git status starts 2 processes and an unstaged
diff starts 1. The service finds Git once, checks Git once per run,
caches the repository check per root until the Git metadata changes,
waits on its pipes instead of a 15 ms poll, and locks each root
separately.

Lease errors name the plugin. A profile copy rejects junctions.
This commit is contained in:
Knotty Wyvern
2026-10-27 23:08:59 -07:00
parent 70510a114f
commit 2448c68abf
8 changed files with 738 additions and 217 deletions
+22 -17
View File
@@ -18,10 +18,14 @@ pub struct BackgroundFile {
}
fn require_plugin(app: &AppHandle, window: &Window, id: &str) -> Result<()> {
app.state::<PluginState>()
.require_lease(app, window.label(), id)
.map_err(|_| "The plugin is not enabled in this window.".into())
fn require_plugin(app: &AppHandle, label: &str, id: &str) -> Result<()> {
app.state::<PluginState>().require_lease(app, label, id)
}
/// Check the lease on a blocking worker, because the plugin lock can wait for package work.
async fn check_plugin(app: &AppHandle, window: &Window, id: &str) -> Result<()> {
let (app, label, id) = (app.clone(), window.label().to_owned(), id.to_owned());
tauri::async_runtime::spawn_blocking(move || require_plugin(&app, &label, &id)).await?
}
fn folder_root(folder: &Path) -> Result<PathBuf> {
@@ -128,11 +132,12 @@ pub async fn backgrounds_default_folder(
window: Window,
id: String,
) -> Result<String> {
require_plugin(&app, &window, &id)?;
check_plugin(&app, &window, &id).await?;
let pictures = app.path().picture_dir()?;
let folder = pictures.join("RuneStone Backgrounds");
fs::create_dir_all(&folder)?;
require_plugin(&app, &window, &id)?;
let created = folder.clone();
tauri::async_runtime::spawn_blocking(move || fs::create_dir_all(created)).await??;
check_plugin(&app, &window, &id).await?;
folder_root(&folder).map(|root| root.to_string_lossy().into_owned())
}
@@ -142,7 +147,7 @@ pub async fn backgrounds_choose_folder(
window: Window,
id: String,
) -> Result<Option<String>> {
require_plugin(&app, &window, &id)?;
check_plugin(&app, &window, &id).await?;
let picker_app = app.clone();
let picker_window = window.clone();
let selected = tauri::async_runtime::spawn_blocking(move || {
@@ -154,7 +159,7 @@ pub async fn backgrounds_choose_folder(
.blocking_pick_folder()
})
.await?;
require_plugin(&app, &window, &id)?;
check_plugin(&app, &window, &id).await?;
selected
.map(|source| {
let path = source.into_path().map_err(Error::from_display)?;
@@ -170,10 +175,10 @@ pub async fn backgrounds_list(
id: String,
folder: String,
) -> Result<Vec<BackgroundFile>> {
require_plugin(&app, &window, &id)?;
check_plugin(&app, &window, &id).await?;
let result = tauri::async_runtime::spawn_blocking(move || list_images(Path::new(&folder)))
.await??;
require_plugin(&app, &window, &id)?;
check_plugin(&app, &window, &id).await?;
Ok(result)
}
@@ -185,11 +190,11 @@ pub async fn backgrounds_read(
folder: String,
name: String,
) -> Result<String> {
require_plugin(&app, &window, &id)?;
check_plugin(&app, &window, &id).await?;
let result =
tauri::async_runtime::spawn_blocking(move || read_image(Path::new(&folder), &name))
.await??;
require_plugin(&app, &window, &id)?;
check_plugin(&app, &window, &id).await?;
Ok(base64::engine::general_purpose::STANDARD.encode(result))
}
@@ -243,18 +248,18 @@ fn write_image_settings(folder: &Path, contents: &str, expected: Option<&str>) -
#[tauri::command]
pub async fn backgrounds_read_image_settings(app: AppHandle, window: Window, id: String, folder: String) -> Result<Option<String>> {
require_plugin(&app, &window, &id)?;
check_plugin(&app, &window, &id).await?;
let result = tauri::async_runtime::spawn_blocking(move || read_image_settings(Path::new(&folder))).await??;
require_plugin(&app, &window, &id)?;
check_plugin(&app, &window, &id).await?;
Ok(result)
}
#[tauri::command]
pub async fn backgrounds_write_image_settings(app: AppHandle, window: Window, id: String, folder: String, contents: String, expected: Option<String>) -> Result<()> {
require_plugin(&app, &window, &id)?;
check_plugin(&app, &window, &id).await?;
// Check the lease again immediately before the write on the blocking worker.
tauri::async_runtime::spawn_blocking(move || {
require_plugin(&app, &window, &id)?;
require_plugin(&app, window.label(), &id)?;
write_image_settings(Path::new(&folder), &contents, expected.as_deref())
}).await?
}