2022-09-07 20:30:31 +02:00
|
|
|
/*
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2022, Andreas Kling <andreas@ladybird.org>
|
2022-09-07 20:30:31 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <AK/Function.h>
|
2026-02-28 10:30:49 +01:00
|
|
|
#include <LibCore/EventLoop.h>
|
2022-09-07 20:30:31 +02:00
|
|
|
#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;
|
|
|
|
|
|
2026-02-28 10:30:49 +01:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-07 20:30:31 +02:00
|
|
|
}
|