mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Use gsl::finally to pop thread context where appropriate
This commit is contained in:
parent
1261c775d4
commit
b335741f99
3 changed files with 10 additions and 3 deletions
|
@ -574,6 +574,10 @@ int XDPFileDialog::exec() {
|
||||||
const auto context = Glib::MainContext::create();
|
const auto context = Glib::MainContext::create();
|
||||||
const auto loop = Glib::MainLoop::create(context);
|
const auto loop = Glib::MainLoop::create(context);
|
||||||
g_main_context_push_thread_default(context->gobj());
|
g_main_context_push_thread_default(context->gobj());
|
||||||
|
const auto contextGuard = gsl::finally([&] {
|
||||||
|
g_main_context_pop_thread_default(context->gobj());
|
||||||
|
});
|
||||||
|
|
||||||
rpl::lifetime lifetime;
|
rpl::lifetime lifetime;
|
||||||
|
|
||||||
accepted(
|
accepted(
|
||||||
|
@ -594,7 +598,6 @@ int XDPFileDialog::exec() {
|
||||||
QPointer<QDialog> guard = this;
|
QPointer<QDialog> guard = this;
|
||||||
|
|
||||||
loop->run();
|
loop->run();
|
||||||
g_main_context_pop_thread_default(context->gobj());
|
|
||||||
|
|
||||||
if (guard.isNull()) {
|
if (guard.isNull()) {
|
||||||
return QDialog::Rejected;
|
return QDialog::Rejected;
|
||||||
|
|
|
@ -108,6 +108,9 @@ bool ShowXDPOpenWithDialog(const QString &filepath) {
|
||||||
const auto context = Glib::MainContext::create();
|
const auto context = Glib::MainContext::create();
|
||||||
const auto loop = Glib::MainLoop::create(context);
|
const auto loop = Glib::MainLoop::create(context);
|
||||||
g_main_context_push_thread_default(context->gobj());
|
g_main_context_push_thread_default(context->gobj());
|
||||||
|
const auto contextGuard = gsl::finally([&] {
|
||||||
|
g_main_context_pop_thread_default(context->gobj());
|
||||||
|
});
|
||||||
|
|
||||||
const auto signalId = connection->signal_subscribe(
|
const auto signalId = connection->signal_subscribe(
|
||||||
[&](
|
[&](
|
||||||
|
@ -163,7 +166,6 @@ bool ShowXDPOpenWithDialog(const QString &filepath) {
|
||||||
QWindow window;
|
QWindow window;
|
||||||
QGuiApplicationPrivate::showModalWindow(&window);
|
QGuiApplicationPrivate::showModalWindow(&window);
|
||||||
loop->run();
|
loop->run();
|
||||||
g_main_context_pop_thread_default(context->gobj());
|
|
||||||
QGuiApplicationPrivate::hideModalWindow(&window);
|
QGuiApplicationPrivate::hideModalWindow(&window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -148,6 +148,9 @@ void PortalAutostart(bool start, bool silent) {
|
||||||
const auto context = Glib::MainContext::create();
|
const auto context = Glib::MainContext::create();
|
||||||
const auto loop = Glib::MainLoop::create(context);
|
const auto loop = Glib::MainLoop::create(context);
|
||||||
g_main_context_push_thread_default(context->gobj());
|
g_main_context_push_thread_default(context->gobj());
|
||||||
|
const auto contextGuard = gsl::finally([&] {
|
||||||
|
g_main_context_pop_thread_default(context->gobj());
|
||||||
|
});
|
||||||
|
|
||||||
const auto signalId = connection->signal_subscribe(
|
const auto signalId = connection->signal_subscribe(
|
||||||
[&](
|
[&](
|
||||||
|
@ -200,7 +203,6 @@ void PortalAutostart(bool start, bool silent) {
|
||||||
QWindow window;
|
QWindow window;
|
||||||
QGuiApplicationPrivate::showModalWindow(&window);
|
QGuiApplicationPrivate::showModalWindow(&window);
|
||||||
loop->run();
|
loop->run();
|
||||||
g_main_context_pop_thread_default(context->gobj());
|
|
||||||
QGuiApplicationPrivate::hideModalWindow(&window);
|
QGuiApplicationPrivate::hideModalWindow(&window);
|
||||||
}
|
}
|
||||||
} catch (const Glib::Error &e) {
|
} catch (const Glib::Error &e) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue