mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-14 16:07:52 +00:00
Tauri runs commands declared without `async` on the main thread, so Local History, shelf, change-list and run-configuration reads and writes, `.env` loading and the line diff of two arbitrary texts blocked input, painting and every other IPC call while they ran. They are now async and run on the blocking pool; IPC signatures are unchanged. `vcs_changelists_save` stays synchronous so its fire-and-forget saves land in order. A guard test keeps these commands async. Co-authored-by: rohitdanda <10144914+rohitdanda@users.noreply.github.com>
47 lines
1.6 KiB
Rust
47 lines
1.6 KiB
Rust
//! Tauri runs a command declared without `async` on the main thread, so disk I/O or a
|
|
//! large diff there freezes the window (input, painting, every other IPC call).
|
|
|
|
/// Commands that read or write project files, Local History or `.env` files, or diff two
|
|
/// arbitrary texts: they must be `async` and do that work on the blocking pool.
|
|
const OFF_MAIN_THREAD: &[(&str, &[&str])] = &[
|
|
("doc.rs", &["history_list", "history_content"]),
|
|
(
|
|
"vcs.rs",
|
|
&[
|
|
"vcs_diff_hunks",
|
|
"vcs_shelves",
|
|
"vcs_shelf_delete",
|
|
"vcs_shelf_rename",
|
|
"vcs_shelf_patch",
|
|
"vcs_changelists_load",
|
|
],
|
|
),
|
|
(
|
|
"run.rs",
|
|
&[
|
|
"run_save_configs",
|
|
"run_templates",
|
|
"run_save_templates",
|
|
"run_import_sources",
|
|
"run_import_configs",
|
|
"run_env_files",
|
|
],
|
|
),
|
|
];
|
|
|
|
#[test]
|
|
fn disk_and_diff_commands_stay_off_the_main_thread() {
|
|
let dir = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("src/commands");
|
|
let mut on_main = Vec::new();
|
|
for (file, commands) in OFF_MAIN_THREAD {
|
|
let source = std::fs::read_to_string(dir.join(file)).unwrap();
|
|
for command in *commands {
|
|
assert!(source.contains(&format!("fn {command}(")), "{file} has no command {command}");
|
|
if !source.contains(&format!("pub async fn {command}(")) {
|
|
on_main.push(*command);
|
|
}
|
|
}
|
|
}
|
|
assert!(on_main.is_empty(), "synchronous commands run on the main thread: {on_main:?}");
|
|
}
|