From 1146f068e1a2ce4244982532c621270c022bcdff Mon Sep 17 00:00:00 2001 From: Fabian-Lars Date: Mon, 24 Jun 2024 10:27:34 +0200 Subject: [PATCH] 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 --- .changes/fix-fs-async-cmds.md | 5 +++++ plugins/fs/src/commands.rs | 24 ++++++++++++------------ 2 files changed, 17 insertions(+), 12 deletions(-) create mode 100644 .changes/fix-fs-async-cmds.md diff --git a/.changes/fix-fs-async-cmds.md b/.changes/fix-fs-async-cmds.md new file mode 100644 index 00000000..9f40d56c --- /dev/null +++ b/.changes/fix-fs-async-cmds.md @@ -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. diff --git a/plugins/fs/src/commands.rs b/plugins/fs/src/commands.rs index 9fac4f06..1cb4c910 100644 --- a/plugins/fs/src/commands.rs +++ b/plugins/fs/src/commands.rs @@ -182,7 +182,7 @@ pub struct CopyFileOptions { } #[tauri::command] -pub fn copy_file( +pub async fn copy_file( webview: Webview, global_scope: GlobalScope, command_scope: CommandScope, @@ -291,7 +291,7 @@ fn read_dir_inner>(path: P) -> crate::Result> { } #[tauri::command] -pub fn read_dir( +pub async fn read_dir( webview: Webview, global_scope: GlobalScope, command_scope: CommandScope, @@ -317,7 +317,7 @@ pub fn read_dir( } #[tauri::command] -pub fn read( +pub async fn read( webview: Webview, rid: ResourceId, len: u32, @@ -330,7 +330,7 @@ pub fn read( } #[tauri::command] -pub fn read_file( +pub async fn read_file( webview: Webview, global_scope: GlobalScope, command_scope: CommandScope, @@ -356,7 +356,7 @@ pub fn read_file( } #[tauri::command] -pub fn read_text_file( +pub async fn read_text_file( webview: Webview, global_scope: GlobalScope, command_scope: CommandScope, @@ -412,7 +412,7 @@ pub fn read_text_file_lines( } #[tauri::command] -pub fn read_text_file_lines_next( +pub async fn read_text_file_lines_next( webview: Webview, rid: ResourceId, ) -> CommandResult<(Option, bool)> { @@ -547,7 +547,7 @@ pub enum SeekMode { } #[tauri::command] -pub fn seek( +pub async fn seek( webview: Webview, rid: ResourceId, offset: i64, @@ -623,7 +623,7 @@ pub fn fstat(webview: Webview, rid: ResourceId) -> CommandResult< } #[tauri::command] -pub fn truncate( +pub async fn truncate( webview: Webview, global_scope: GlobalScope, command_scope: CommandScope, @@ -658,7 +658,7 @@ pub fn truncate( } #[tauri::command] -pub fn ftruncate( +pub async fn ftruncate( webview: Webview, rid: ResourceId, len: Option, @@ -670,7 +670,7 @@ pub fn ftruncate( } #[tauri::command] -pub fn write( +pub async fn write( webview: Webview, rid: ResourceId, data: Vec, @@ -753,7 +753,7 @@ fn write_file_inner( } #[tauri::command] -pub fn write_file( +pub async fn write_file( webview: Webview, global_scope: GlobalScope, command_scope: CommandScope, @@ -781,7 +781,7 @@ pub fn write_file( } #[tauri::command] -pub fn write_text_file( +pub async fn write_text_file( webview: Webview, global_scope: GlobalScope, command_scope: CommandScope,