1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 08:18:11 +00:00

LibGUI: Turn GUI::Application::the() into a pointer

During app teardown, the Application object may be destroyed before
something else, and so having Application::the() return a reference was
obscuring the truth about its lifetime.

This patch makes the API more honest by returning a pointer. While
this makes call sites look a bit more sketchy, do note that the global
Application pointer only becomes null during app teardown.
This commit is contained in:
Andreas Kling 2020-07-04 16:52:01 +02:00
parent f7577585a6
commit ca93c22ae2
26 changed files with 51 additions and 49 deletions

View file

@ -157,14 +157,17 @@ Action::Action(const StringView& text, const Shortcut& shortcut, RefPtr<Gfx::Bit
m_scope = ShortcutScope::WindowLocal;
} else {
m_scope = ShortcutScope::ApplicationGlobal;
Application::the().register_global_shortcut_action({}, *this);
if (auto* app = Application::the())
app->register_global_shortcut_action({}, *this);
}
}
Action::~Action()
{
if (m_shortcut.is_valid() && m_scope == ShortcutScope::ApplicationGlobal)
Application::the().unregister_global_shortcut_action({}, *this);
if (m_shortcut.is_valid() && m_scope == ShortcutScope::ApplicationGlobal) {
if (auto* app = Application::the())
app->unregister_global_shortcut_action({}, *this);
}
}
void Action::activate(Core::Object* activator)