Skip to content

Commit

Permalink
Fix confirming exit when commands are running
Browse files Browse the repository at this point in the history
  • Loading branch information
hluk committed Nov 5, 2024
1 parent c9129a1 commit 9b59ec1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/app/clipboardserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <QMenu>
#include <QMessageBox>
#include <QMimeData>
#include <QPushButton>
#include <QSessionManager>
#include <QStyleFactory>
#include <QTextEdit>
Expand Down Expand Up @@ -370,19 +371,20 @@ bool ClipboardServer::askToQuit()
m_wnd );

messageBox.addButton(tr("Cancel Exiting"), QMessageBox::RejectRole);
messageBox.addButton(tr("Exit Anyway"), QMessageBox::AcceptRole);
QAbstractButton *exitButton = messageBox.addButton(tr("Exit Anyway"), QMessageBox::AcceptRole);

// Close the message box automatically after all running commands finish.
QTimer timerCheckRunningCommands;
timerCheckRunningCommands.setInterval(1000);
connect( &timerCheckRunningCommands, &QTimer::timeout,
this, [&]() {
exitButton, [&]() {
if ( !hasRunningCommands() )
messageBox.accept();
exitButton->click();
});
timerCheckRunningCommands.start();

return messageBox.exec() == QMessageBox::Accepted;
messageBox.exec();
return exitButton == messageBox.clickedButton();
}

return true;
Expand Down
9 changes: 9 additions & 0 deletions src/tests/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4775,6 +4775,15 @@ void Tests::exitNoConfirm()
TEST( m_test->waitForServerToStop() );
}

void Tests::exitStopCommands()
{
RUN("config" << "confirm_exit" << "false", "false\n");
RUN("action" << "copyq sleep 999999", "");
RUN("keys" << clipboardBrowserId << "CTRL+Q", "");
RUN("keys" << confirmExitDialogId << "ENTER", "");
TEST( m_test->waitForServerToStop() );
}

void Tests::abortInputReader()
{
RUN_WITH_INPUT("afterMilliseconds(0, abort); input(); 'DONE'", KEEP_STDIN_OPEN, "");
Expand Down
1 change: 1 addition & 0 deletions src/tests/tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ private slots:

void exitConfirm();
void exitNoConfirm();
void exitStopCommands();

void abortInputReader();

Expand Down

0 comments on commit 9b59ec1

Please sign in to comment.