@@ -580,26 +580,14 @@ namespace maix::app
580
580
log::error (" switch app failed, app_id and idx must have one is valid\n " );
581
581
return ;
582
582
}
583
- // inform this app to exit, code should check this flag by app::need_exit()
584
- set_exit_flag (true );
585
583
vector<APP_Info> &apps_info = get_apps_info ();
586
-
587
- // write app_id to file, launcher will read this file and start the app
588
- string path = get_app_start_info_path ();
589
- FILE *fp = fopen (path.c_str (), " w" );
590
- if (fp == NULL )
591
- {
592
- log::error (" open app start info file failed: %s" , path.c_str ());
593
- return ;
594
- }
595
584
std::string final_app_id = app_id;
596
585
std::string final_app_path = " " ;
597
586
if (idx >= 0 )
598
587
{
599
588
if ((size_t )idx >= apps_info.size ())
600
589
{
601
590
log::error (" idx error, should < %lld, but %d" , apps_info.size (), idx);
602
- fclose (fp);
603
591
throw err::Exception (err::ERR_ARGS, " idx error" );
604
592
}
605
593
final_app_id = apps_info[idx].id ;
@@ -617,6 +605,23 @@ namespace maix::app
617
605
}
618
606
}
619
607
}
608
+ // if switch to current app, just return.
609
+ if (final_app_id == app::app_id ())
610
+ {
611
+ return ;
612
+ }
613
+
614
+ // inform this app to exit, code should check this flag by app::need_exit()
615
+ set_exit_flag (true );
616
+
617
+ // write app_id to file, launcher will read this file and start the app
618
+ string path = get_app_start_info_path ();
619
+ FILE *fp = fopen (path.c_str (), " w" );
620
+ if (fp == NULL )
621
+ {
622
+ log::error (" open app start info file failed: %s" , path.c_str ());
623
+ return ;
624
+ }
620
625
fprintf (fp, " %s\n %s\n %s\n " , final_app_path.c_str (), final_app_id.c_str (), start_param.c_str ());
621
626
fclose (fp);
622
627
// when this app exit, the launcher will check this file and start the app
0 commit comments