Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create QMessageBox on heap and continue running the app when update is ready. #3566

Merged

Conversation

allexzander
Copy link
Contributor

@allexzander allexzander commented Jul 19, 2021

Signed-off-by: allexzander [email protected]

This should fix #2379 and #3538

@allexzander allexzander marked this pull request as ready for review July 19, 2021 16:55
@allexzander allexzander force-pushed the bugfix/desktop-client-high-cpu-usage-on-auto-update branch 2 times, most recently from 46f9062 to 34eeb5e Compare July 20, 2021 17:25
@allexzander allexzander requested a review from FlexW July 20, 2021 17:27
QMessageBox::Ok)) {
const auto messageBoxStartInstaller = new QMessageBox(QMessageBox::Information,
tr("New %1 Update Ready").arg(Theme::instance()->appNameGUI()),
tr("A new update for %1 is about to be installed. The updater may ask\n"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need that new line character? I think the gui should figure out line breaks on it own. If it's just because you don't want to have a long string in the source code, you can use C++ multiline strings :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FlexW Not sure. I haven't checked if that newline character is not needed. Just copy-pasted that code.

.arg(name),
QMessageBox::Ok)) {
const auto messageBoxStartInstaller = new QMessageBox(QMessageBox::Information,
tr("New %1 Update Ready").arg(Theme::instance()->appNameGUI()),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jancborchardt told me once we never use capitalization in titles. So should be "New %1 update ready"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FlexW I don't want to change this now. This will require translation. So, let's use the old text for now. Or, should we ask Jan's opinion? @jancborchardt Do you think I should change existing strings?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get your point, but why not change it now. At some point, we need to change it. If we do not do it now, it may never happen.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, agree with @FlexW here – better to change things when we find them. :) (Also cause there’s probably not so many wrong anyway.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FlexW fixed

}
});
connect(messageBoxStartInstaller, &QMessageBox::rejected, this, [this] {
slotStartInstaller();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am confused about this one, is this not a behavior change from before ?
why do you need it ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mgallien Yes. I need to change behavior. Otherwise, I can not fix the issue, because, it is caused by incorrect behavior. We must not return true. Otherwise, QCoreApplication would never enter the event loop, because, this code:

if (updater && updater->handleStartup()) {
    return 1;
}

in src/gui/main.cpp.

That's why, we must not return true when displaying the message box. Also, we should be able to call qApp->quit() when closing this message box. Otherwise, if we call it right away when displaying the message box, the QCoreApplication hasn't entered the event loop yet. This leads to calling qApp->quit() having no effect because the event loop hasn't started yet. According to Qt documentation.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in that case, you may use QDialog::finished such that you avoid needing to connect to two signals

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mgallien At first, I wanted to use it, but then, I've decided to make this code more deterministic so I only execute that line on accepting or rejecting and no other reason for dialog finish.

Will that QDialog::finished be triggered only when I close the dialog via the X button (ESC on keyboard) and via OK button (ENTER on keyboard) ? If that is the case, I am going to use QDialog::finished.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

finished should happen only for accepted or rejected in our case
it is always possible to call the done slot with another return code but the user can not cause that by closing the dialog
you should be safe using it

Copy link
Collaborator

@mgallien mgallien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks

@allexzander allexzander force-pushed the bugfix/desktop-client-high-cpu-usage-on-auto-update branch 2 times, most recently from 52f7c4f to 9350e63 Compare July 21, 2021 11:23
…ue from OCUpdater to allow for a proper app::quit

Signed-off-by: allexzander <[email protected]>
@allexzander allexzander force-pushed the bugfix/desktop-client-high-cpu-usage-on-auto-update branch from 9350e63 to 801e4ad Compare July 21, 2021 11:24
@allexzander allexzander merged commit 309e8bd into master Jul 21, 2021
@allexzander allexzander deleted the bugfix/desktop-client-high-cpu-usage-on-auto-update branch July 21, 2021 11:26
@nextcloud-desktop-bot
Copy link

AppImage file: Nextcloud-PR-3566-9350e636b2009bffac77c2cdb9589f8f98023906-x86_64.AppImage

To test this change/fix you can simply download above AppImage file and test it.

Please make sure to quit your existing Nextcloud app and backup your data.

@allexzander allexzander linked an issue Jul 21, 2021 that may be closed by this pull request
@allexzander allexzander changed the title Show custom QDialog instead of QMessageBox when update is ready. Create QMessageBox on heap and continue running the app when update is ready. Jul 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants