mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2026-04-18 09:50:27 +00:00
EventLoopPluginSerenity was the only implementation of the abstract EventLoopPlugin base class. Its methods simply wrapped Core::EventLoop calls with GC function unwrapping. Remove the virtual dispatch by making EventLoopPlugin concrete and absorbing the EventLoopPluginSerenity implementation directly.
50 lines
1 KiB
C++
50 lines
1 KiB
C++
/*
|
|
* Copyright (c) 2022, Andreas Kling <andreas@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <AK/Function.h>
|
|
#include <LibCore/EventLoop.h>
|
|
#include <LibWeb/Platform/EventLoopPlugin.h>
|
|
|
|
namespace Web::Platform {
|
|
|
|
EventLoopPlugin* s_the;
|
|
|
|
EventLoopPlugin& EventLoopPlugin::the()
|
|
{
|
|
VERIFY(s_the);
|
|
return *s_the;
|
|
}
|
|
|
|
void EventLoopPlugin::install(EventLoopPlugin& plugin)
|
|
{
|
|
VERIFY(!s_the);
|
|
s_the = &plugin;
|
|
}
|
|
|
|
EventLoopPlugin::~EventLoopPlugin() = default;
|
|
|
|
void EventLoopPlugin::spin_until(GC::Root<GC::Function<bool()>> goal_condition)
|
|
{
|
|
Core::EventLoop::current().spin_until([goal_condition = move(goal_condition)]() {
|
|
if (Core::EventLoop::current().was_exit_requested())
|
|
::exit(0);
|
|
return goal_condition->function()();
|
|
});
|
|
}
|
|
|
|
void EventLoopPlugin::deferred_invoke(GC::Root<GC::Function<void()>> function)
|
|
{
|
|
Core::deferred_invoke([function = move(function)]() {
|
|
function->function()();
|
|
});
|
|
}
|
|
|
|
void EventLoopPlugin::quit()
|
|
{
|
|
Core::EventLoop::current().quit(0);
|
|
}
|
|
|
|
}
|