@@ -68,8 +68,12 @@ void ProjectActionsController::init()
6868
6969 dispatcher ()->reg (this , " file-close" , [this ]() {
7070 auto anyInstanceWithoutProject = multiInstancesProvider ()->isHasAppInstanceWithoutProject ();
71- closeOpenedProject (anyInstanceWithoutProject);
72- if (anyInstanceWithoutProject) {
71+ bool ok = closeOpenedProject ();
72+ if (ok && anyInstanceWithoutProject) {
73+ // ! NOTE: we need to call `quit` in the next event loop due to controlling the lifecycle of this method
74+ async::Async::call (this , [this ]() {
75+ dispatcher ()->dispatch (" quit" , ActionData::make_arg1<bool >(false ));
76+ });
7377 multiInstancesProvider ()->activateWindowWithoutProject ();
7478 }
7579 });
@@ -603,11 +607,10 @@ muse::async::Notification ProjectActionsController::projectBeingDownloadedChange
603607
604608Ret ProjectActionsController::openPageIfNeed (Uri pageUri)
605609{
606- if (interactive ()->isOpened (pageUri).val ) {
607- return make_ret (Ret::Code::Ok );
610+ if (! interactive ()->isOpened (pageUri).val ) {
611+ interactive ()-> open (pageUri );
608612 }
609-
610- return interactive ()->openSync (pageUri).ret ;
613+ return make_ret (Ret::Code::Ok);
611614}
612615
613616bool ProjectActionsController::isProjectOpened (const muse::io::path_t & scorePath) const
@@ -674,7 +677,7 @@ void ProjectActionsController::newProject()
674677 });
675678}
676679
677- bool ProjectActionsController::closeOpenedProject (bool quitApp )
680+ bool ProjectActionsController::closeOpenedProject (bool goToHome )
678681{
679682 if (m_isProjectClosing) {
680683 return false ;
@@ -712,12 +715,7 @@ bool ProjectActionsController::closeOpenedProject(bool quitApp)
712715 interactive ()->closeAllDialogs ();
713716 globalContext ()->setCurrentProject (nullptr );
714717
715- if (quitApp) {
716- // ! NOTE: we need to call `quit` in the next event loop due to controlling the lifecycle of this method
717- async::Async::call (this , [this ]() {
718- dispatcher ()->dispatch (" quit" , ActionData::make_arg1<bool >(false ));
719- });
720- } else {
718+ if (goToHome) {
721719 Ret ret = openPageIfNeed (HOME_PAGE_URI);
722720 if (!ret) {
723721 LOGE () << ret.toString ();
0 commit comments