@@ -301,7 +301,25 @@ pub async fn launch(app: AppHandle, launcher_id: i64) -> Result<(), OneClickLaun
301301 OneClickLaunchError :: ExecutionError ( "Unable to get DatabaseManager" . to_string ( ) ) ,
302302 ) ?;
303303
304- let resources = launcher_resource:: query_by_launcher_id ( & db. pool , launcher_id) . await ?;
304+ let mut resources = launcher_resource:: query_by_launcher_id ( & db. pool , launcher_id) . await ?;
305+
306+ // 必须从启动资源中排除自己,防止出现死循环
307+ let app_path = current_exe_path_str ( ) ?;
308+ resources. retain ( |e| {
309+ // 检查路径是否包含空格
310+ if e. path . contains ( ' ' ) {
311+ // 按空格拆分并取第一个部分进行比较
312+ e. path . split_whitespace ( ) . next ( ) == Some ( & app_path)
313+ } else {
314+ // 不包含空格时直接比较
315+ e. path . eq ( & app_path)
316+ }
317+ } ) ;
318+
319+ if resources. is_empty ( ) {
320+ tracing:: debug!( "资源列表为空" ) ;
321+ return Ok ( ( ) ) ;
322+ }
305323
306324 launch_resources ( & app, & resources) ;
307325
@@ -354,17 +372,10 @@ pub async fn create_handler_shortcut(
354372 launcher_id : i64 ,
355373 db : State < ' _ , DatabaseManager > ,
356374) -> Result < String , OneClickLaunchError > {
357- // 获取当前应用程序的绝对路径
358- let exe_path = std:: env:: current_exe ( ) ?;
359-
360- // 转换为 Windows 可识别的普通路径
361- let mut app_path = exe_path. to_string_lossy ( ) . to_string ( ) ;
362- if app_path. starts_with ( r"\\?\" ) {
363- app_path = app_path. trim_start_matches ( r"\\?\" ) . to_string ( ) ;
364- }
365-
366375 let launcher = launcher:: find_by_id ( & db. pool , launcher_id) . await ?;
367376
377+ let app_path = current_exe_path_str ( ) ?;
378+
368379 // 构建参数
369380 let args = Some ( vec ! [ format!( "launch {}" , launcher_id) ] ) ;
370381
@@ -377,3 +388,15 @@ pub async fn create_handler_shortcut(
377388 )
378389 . map ( |path| path. to_string_lossy ( ) . to_string ( ) )
379390}
391+
392+ fn current_exe_path_str ( ) -> Result < String , OneClickLaunchError > {
393+ // 获取当前应用程序的绝对路径
394+ let exe_path = std:: env:: current_exe ( ) ?;
395+
396+ // 转换为 Windows 可识别的普通路径
397+ let mut app_path = exe_path. to_string_lossy ( ) . to_string ( ) ;
398+ if app_path. starts_with ( r"\\?\" ) {
399+ app_path = app_path. trim_start_matches ( r"\\?\" ) . to_string ( ) ;
400+ }
401+ Ok ( app_path)
402+ }
0 commit comments