fix(fs): Make read/write commands async to not block the main thread (#1477)

* fix(fs): Make commands async to not block the main thread so long

* more async

* changefile
This commit is contained in:
Fabian-Lars
2024-06-24 10:27:34 +02:00
committed by GitHub
parent 0ee590366b
commit 1146f068e1
2 changed files with 17 additions and 12 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"fs": patch
---
Fixes an issue that caused the app to freeze when the `fs` plugin's read/write apis were used on large files.
+12 -12
View File
@@ -182,7 +182,7 @@ pub struct CopyFileOptions {
}
#[tauri::command]
pub fn copy_file<R: Runtime>(
pub async fn copy_file<R: Runtime>(
webview: Webview<R>,
global_scope: GlobalScope<Entry>,
command_scope: CommandScope<Entry>,
@@ -291,7 +291,7 @@ fn read_dir_inner<P: AsRef<Path>>(path: P) -> crate::Result<Vec<DirEntry>> {
}
#[tauri::command]
pub fn read_dir<R: Runtime>(
pub async fn read_dir<R: Runtime>(
webview: Webview<R>,
global_scope: GlobalScope<Entry>,
command_scope: CommandScope<Entry>,
@@ -317,7 +317,7 @@ pub fn read_dir<R: Runtime>(
}
#[tauri::command]
pub fn read<R: Runtime>(
pub async fn read<R: Runtime>(
webview: Webview<R>,
rid: ResourceId,
len: u32,
@@ -330,7 +330,7 @@ pub fn read<R: Runtime>(
}
#[tauri::command]
pub fn read_file<R: Runtime>(
pub async fn read_file<R: Runtime>(
webview: Webview<R>,
global_scope: GlobalScope<Entry>,
command_scope: CommandScope<Entry>,
@@ -356,7 +356,7 @@ pub fn read_file<R: Runtime>(
}
#[tauri::command]
pub fn read_text_file<R: Runtime>(
pub async fn read_text_file<R: Runtime>(
webview: Webview<R>,
global_scope: GlobalScope<Entry>,
command_scope: CommandScope<Entry>,
@@ -412,7 +412,7 @@ pub fn read_text_file_lines<R: Runtime>(
}
#[tauri::command]
pub fn read_text_file_lines_next<R: Runtime>(
pub async fn read_text_file_lines_next<R: Runtime>(
webview: Webview<R>,
rid: ResourceId,
) -> CommandResult<(Option<String>, bool)> {
@@ -547,7 +547,7 @@ pub enum SeekMode {
}
#[tauri::command]
pub fn seek<R: Runtime>(
pub async fn seek<R: Runtime>(
webview: Webview<R>,
rid: ResourceId,
offset: i64,
@@ -623,7 +623,7 @@ pub fn fstat<R: Runtime>(webview: Webview<R>, rid: ResourceId) -> CommandResult<
}
#[tauri::command]
pub fn truncate<R: Runtime>(
pub async fn truncate<R: Runtime>(
webview: Webview<R>,
global_scope: GlobalScope<Entry>,
command_scope: CommandScope<Entry>,
@@ -658,7 +658,7 @@ pub fn truncate<R: Runtime>(
}
#[tauri::command]
pub fn ftruncate<R: Runtime>(
pub async fn ftruncate<R: Runtime>(
webview: Webview<R>,
rid: ResourceId,
len: Option<u64>,
@@ -670,7 +670,7 @@ pub fn ftruncate<R: Runtime>(
}
#[tauri::command]
pub fn write<R: Runtime>(
pub async fn write<R: Runtime>(
webview: Webview<R>,
rid: ResourceId,
data: Vec<u8>,
@@ -753,7 +753,7 @@ fn write_file_inner<R: Runtime>(
}
#[tauri::command]
pub fn write_file<R: Runtime>(
pub async fn write_file<R: Runtime>(
webview: Webview<R>,
global_scope: GlobalScope<Entry>,
command_scope: CommandScope<Entry>,
@@ -781,7 +781,7 @@ pub fn write_file<R: Runtime>(
}
#[tauri::command]
pub fn write_text_file<R: Runtime>(
pub async fn write_text_file<R: Runtime>(
webview: Webview<R>,
global_scope: GlobalScope<Entry>,
command_scope: CommandScope<Entry>,