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

Wait on shutdown for docks to close on Linux (Event-based solution) #460

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions panel/browser-panel-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,13 @@ bool QCefBrowserClient::OnBeforePopup(CefRefPtr<CefBrowser>, CefRefPtr<CefFrame>
return true;
}

void QCefBrowserClient::OnBeforeClose(CefRefPtr<CefBrowser>)
{
if (widget) {
emit widget->CloseSafely();
}
}

bool QCefBrowserClient::OnSetFocus(CefRefPtr<CefBrowser>, CefFocusHandler::FocusSource source)
{
/* Don't steal focus when the webpage navigates. This is especially
Expand Down
2 changes: 2 additions & 0 deletions panel/browser-panel-client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class QCefBrowserClient : public CefClient,
CefRefPtr<CefClient> &client, CefBrowserSettings &settings,
CefRefPtr<CefDictionaryValue> &extra_info, bool *no_javascript_access) override;

virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) override;

/* CefFocusHandler */
virtual bool OnSetFocus(CefRefPtr<CefBrowser> browser, CefFocusHandler::FocusSource source) override;

Expand Down
4 changes: 4 additions & 0 deletions panel/browser-panel-internal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class QCefWidgetInternal : public QCefWidget {
virtual bool zoomPage(int direction) override;
virtual void executeJavaScript(const std::string &script) override;

void CloseSafely();
void Resize();

#ifdef __linux__
Expand All @@ -61,4 +62,7 @@ class QCefWidgetInternal : public QCefWidget {

public slots:
void Init();

signals:
void readyToClose();
};
24 changes: 16 additions & 8 deletions panel/browser-panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,21 +160,24 @@ void QCefWidgetInternal::closeBrowser()
{
CefRefPtr<CefBrowser> browser = cefBrowser;
if (!!browser) {
auto destroyBrowser = [](CefRefPtr<CefBrowser> cefBrowser) {
auto destroyBrowser = [=](CefRefPtr<CefBrowser> cefBrowser) {
CefRefPtr<CefClient> client = cefBrowser->GetHost()->GetClient();
QCefBrowserClient *bc = reinterpret_cast<QCefBrowserClient *>(client.get());

if (bc) {
bc->widget = nullptr;
}

cefBrowser->GetHost()->CloseBrowser(true);

#if !defined(_WIN32) && !defined(__APPLE__) && CHROME_VERSION_BUILD >= 6533
while (cefBrowser && cefBrowser->IsValid()) {
os_sleep_ms(10);
}
QEventLoop loop;

connect(this, &QCefWidgetInternal::readyToClose, &loop, &QEventLoop::quit);

QTimer::singleShot(1000, &loop, &QEventLoop::quit);

loop.exec();
#endif
if (bc) {
bc->widget = nullptr;
}
};

/* So you're probably wondering what's going on here. If you
Expand Down Expand Up @@ -398,6 +401,11 @@ void QCefWidgetInternal::Resize()
#endif
}

void QCefWidgetInternal::CloseSafely()
{
emit readyToClose();
}

void QCefWidgetInternal::showEvent(QShowEvent *event)
{
QWidget::showEvent(event);
Expand Down