@@ -6,8 +6,6 @@ use base64::engine::general_purpose;
66use base64:: Engine ;
77
88use tauri:: Manager ;
9- use tauri:: Runtime ;
10- use tauri:: Url ;
119
1210#[ derive( Debug , Serialize , Deserialize ) ]
1311struct FolderEntry {
@@ -17,14 +15,13 @@ struct FolderEntry {
1715 #[ serde( skip_serializing_if = "Option::is_none" ) ]
1816 children : Option < Vec < FolderEntry > > ,
1917}
20- #[ cfg( desktop) ]
21- use tauri_plugin_updater:: UpdaterExt ;
2218
2319/// 递归读取文件夹结构,返回嵌套的文件夹结构
2420#[ tauri:: command]
2521fn read_folder_structure ( path : String ) -> FolderEntry {
2622 let path_buf = std:: path:: PathBuf :: from ( & path) ;
27- let name = path_buf. file_name ( )
23+ let name = path_buf
24+ . file_name ( )
2825 . and_then ( |n| n. to_str ( ) )
2926 . unwrap_or ( "" )
3027 . to_string ( ) ;
@@ -36,7 +33,7 @@ fn read_folder_structure(path: String) -> FolderEntry {
3633 let path = entry. path ( ) ;
3734 let child_name = entry. file_name ( ) . to_string_lossy ( ) . to_string ( ) ;
3835 let path_str = path. to_string_lossy ( ) . to_string ( ) ;
39-
36+
4037 if path. is_file ( ) {
4138 children. push ( FolderEntry {
4239 name : child_name,
@@ -50,7 +47,7 @@ fn read_folder_structure(path: String) -> FolderEntry {
5047 }
5148 }
5249 }
53-
50+
5451 FolderEntry {
5552 name,
5653 is_file : false ,
@@ -88,20 +85,23 @@ fn read_folder(path: String) -> Vec<String> {
8885/// 如果文件夹不存在,返回空列表
8986/// fileExts: 要读取的文件扩展名列表,例如:[".txt", ".md"]
9087#[ tauri:: command]
91- fn read_folder_recursive ( path : String , fileExts : Vec < String > ) -> Vec < String > {
88+ fn read_folder_recursive ( path : String , file_exts : Vec < String > ) -> Vec < String > {
9289 let mut files = Vec :: new ( ) ;
9390 if let Ok ( entries) = std:: fs:: read_dir ( path) {
9491 for entry in entries {
9592 if let Ok ( entry) = entry {
9693 let path = entry. path ( ) ;
9794 if path. is_file ( ) {
9895 if let Some ( file_name) = path. to_str ( ) {
99- if fileExts . iter ( ) . any ( |ext| file_name. ends_with ( ext) ) {
96+ if file_exts . iter ( ) . any ( |ext| file_name. ends_with ( ext) ) {
10097 files. push ( file_name. to_string ( ) ) ;
10198 }
10299 }
103100 } else if path. is_dir ( ) {
104- let mut sub_files = read_folder_recursive ( path. to_str ( ) . unwrap ( ) . to_string ( ) , fileExts. clone ( ) ) ;
101+ let mut sub_files = read_folder_recursive (
102+ path. to_str ( ) . unwrap ( ) . to_string ( ) ,
103+ file_exts. clone ( ) ,
104+ ) ;
105105 files. append ( & mut sub_files) ;
106106 }
107107 }
@@ -110,15 +110,13 @@ fn read_folder_recursive(path: String, fileExts: Vec<String>) -> Vec<String> {
110110 files
111111}
112112
113-
114113/// 删除文件
115114#[ tauri:: command]
116115fn delete_file ( path : String ) -> Result < ( ) , String > {
117116 std:: fs:: remove_file ( path) . map_err ( |e| e. to_string ( ) ) ?;
118117 Ok ( ( ) )
119118}
120119
121-
122120/// 读取文件,返回字符串
123121#[ tauri:: command]
124122fn read_text_file ( path : String ) -> String {
@@ -180,26 +178,6 @@ fn exit(code: i32) {
180178 std:: process:: exit ( code) ;
181179}
182180
183- #[ cfg( desktop) ]
184- #[ tauri:: command]
185- async fn set_update_channel < R : Runtime > (
186- app : tauri:: AppHandle < R > ,
187- channel : String ,
188- ) -> Result < ( ) , tauri_plugin_updater:: Error > {
189- println ! ( "Setting update channel to {}" , channel) ;
190- app. updater_builder ( )
191- . endpoints ( vec ! [ Url :: parse(
192- format!(
193- "https://github.com/LiRenTech/project-graph/releases/{channel}/download/latest.json"
194- )
195- . as_str( ) ,
196- ) ?] ) ?
197- . build ( ) ?
198- . check ( )
199- . await ?;
200- Ok ( ( ) )
201- }
202-
203181#[ cfg_attr( mobile, tauri:: mobile_entry_point) ]
204182pub fn run ( ) {
205183 // 在 Linux 上禁用 DMA-BUF 渲染器
@@ -226,6 +204,8 @@ pub fn run() {
226204 {
227205 app. handle ( ) . plugin ( tauri_plugin_cli:: init ( ) ) ?;
228206 app. handle ( ) . plugin ( tauri_plugin_process:: init ( ) ) ?;
207+ app. handle ( )
208+ . plugin ( tauri_plugin_window_state:: Builder :: new ( ) . build ( ) ) ?;
229209 app. handle ( )
230210 . plugin ( tauri_plugin_updater:: Builder :: new ( ) . build ( ) ) ?;
231211 }
@@ -244,9 +224,7 @@ pub fn run() {
244224 write_file_base64,
245225 write_stdout,
246226 write_stderr,
247- exit,
248- #[ cfg( desktop) ]
249- set_update_channel
227+ exit
250228 ] )
251229 . run ( tauri:: generate_context!( ) )
252230 . expect ( "error while running tauri application" ) ;
0 commit comments