Skip to content

Commit aaa4f60

Browse files
committed
fixed close application
1 parent 3c9ee54 commit aaa4f60

File tree

4 files changed

+15
-17
lines changed

4 files changed

+15
-17
lines changed

src/appshell/internal/applicationactioncontroller.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ bool ApplicationActionController::quit(bool isAllInstances, const muse::io::path
218218
m_quiting = false;
219219
};
220220

221-
if (!projectFilesController()->closeOpenedProject()) {
221+
if (!projectFilesController()->closeOpenedProject(false)) {
222222
return false;
223223
}
224224

@@ -244,7 +244,7 @@ bool ApplicationActionController::quit(bool isAllInstances, const muse::io::path
244244

245245
void ApplicationActionController::restart()
246246
{
247-
if (projectFilesController()->closeOpenedProject()) {
247+
if (projectFilesController()->closeOpenedProject(false)) {
248248
if (multiInstancesProvider()->instances().size() == 1) {
249249
application()->restart();
250250
} else {

src/project/internal/projectactionscontroller.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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

604608
Ret 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

613616
bool 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();

src/project/internal/projectactionscontroller.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class ProjectActionsController : public IProjectFilesController, public muse::mi
9292
bool isUrlSupported(const QUrl& url) const override;
9393
bool isFileSupported(const muse::io::path_t& path) const override;
9494
muse::Ret openProject(const ProjectFile& file) override;
95-
bool closeOpenedProject(bool quitApp = false) override;
95+
bool closeOpenedProject(bool goToHome = true) override;
9696
bool saveProject(const muse::io::path_t& path = muse::io::path_t()) override;
9797
bool saveProjectLocally(
9898
const muse::io::path_t& path = muse::io::path_t(), SaveMode saveMode = SaveMode::Save, bool createBackup = true) override;

src/project/iprojectfilescontroller.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class IProjectFilesController : MODULE_EXPORT_INTERFACE
4141
virtual bool isUrlSupported(const QUrl& url) const = 0;
4242
virtual bool isFileSupported(const muse::io::path_t& path) const = 0;
4343
virtual muse::Ret openProject(const ProjectFile& file) = 0;
44-
virtual bool closeOpenedProject(bool quitApp = false) = 0;
44+
virtual bool closeOpenedProject(bool goToHome = true) = 0;
4545
virtual bool saveProject(const muse::io::path_t& path = muse::io::path_t()) = 0;
4646
virtual bool saveProjectLocally(
4747
const muse::io::path_t& path = muse::io::path_t(), SaveMode saveMode = SaveMode::Save, bool createBackup = true) = 0;

0 commit comments

Comments
 (0)