ladybird/Ladybird/main.cpp
Matthew Costa 7bf3010185 Ladybird: Trigger browser to quit when the main window is closed
This patch adds an event handler to the main window which allows it to
respond to a user closing the window. This event is then passed on to
the LibCore event loop, which allows the application quit itself.
Previously the application would hang, only running in the background,
until killed by an external force.
2022-12-25 07:58:58 -07:00

46 lines
1.1 KiB
C++

/*
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "BrowserWindow.h"
#include "WebView.h"
#include <LibCore/ArgsParser.h>
#include <LibCore/EventLoop.h>
#include <LibCore/Timer.h>
#include <LibMain/Main.h>
#include <QApplication>
#include <QWidget>
extern void initialize_web_engine();
ErrorOr<int> serenity_main(Main::Arguments arguments)
{
initialize_web_engine();
String url;
Core::ArgsParser args_parser;
args_parser.set_general_help("The Ladybird web browser :^)");
args_parser.add_positional_argument(url, "URL to open", "url", Core::ArgsParser::Required::No);
args_parser.parse(arguments);
Core::EventLoop event_loop;
QApplication app(arguments.argc, arguments.argv);
BrowserWindow window(event_loop);
window.setWindowTitle("Ladybird");
window.resize(800, 600);
window.show();
auto qt_event_loop_driver = Core::Timer::create_repeating(50, [&] {
app.processEvents();
});
qt_event_loop_driver->start();
if (!url.is_empty()) {
window.view().load(url);
}
return event_loop.exec();
}