mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 13:36:13 +03:00
Ladybird: Register Ladybird as a browser-type application on macOS
This allows Ladybird to be the default browser on macOS, and allows for opening some file types (.html, .svg, .md, etc.) with Ladybird. Note this currently only works in the GN build (and thus the Qt chrome). The CMake build does not set up the Resources directory properly for macOS to run the Ladybird app without $SERENITY_SOURCE_DIR set.
This commit is contained in:
parent
652bbe172b
commit
0415d03b4f
Notes:
sideshowbarker
2024-07-17 04:34:25 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/0415d03b4f Pull-request: https://github.com/SerenityOS/serenity/pull/21927 Reviewed-by: https://github.com/ADKaster
@ -20,5 +20,55 @@
|
|||||||
<string>NSApplication</string>
|
<string>NSApplication</string>
|
||||||
<key>NSHighResolutionCapable</key>
|
<key>NSHighResolutionCapable</key>
|
||||||
<string>True</string>
|
<string>True</string>
|
||||||
|
<key>CFBundleDocumentTypes</key>
|
||||||
|
<array>
|
||||||
|
<dict>
|
||||||
|
<key>CFBundleTypeName</key>
|
||||||
|
<string>Web documents</string>
|
||||||
|
<key>CFBundleTypeRole</key>
|
||||||
|
<string>Viewer</string>
|
||||||
|
<key>CFBundleTypeIconFile</key>
|
||||||
|
<string>document.icns</string>
|
||||||
|
<key>LSItemContentTypes</key>
|
||||||
|
<array>
|
||||||
|
<string>public.html</string>
|
||||||
|
<string>public.xhtml</string>
|
||||||
|
<string>public.svg-image</string>
|
||||||
|
</array>
|
||||||
|
</dict>
|
||||||
|
<dict>
|
||||||
|
<key>CFBundleTypeName</key>
|
||||||
|
<string>Other documents</string>
|
||||||
|
<key>CFBundleTypeRole</key>
|
||||||
|
<string>Viewer</string>
|
||||||
|
<key>CFBundleTypeIconFile</key>
|
||||||
|
<string>document.icns</string>
|
||||||
|
<key>CFBundleTypeExtensions</key>
|
||||||
|
<array>
|
||||||
|
<string>md</string>
|
||||||
|
</array>
|
||||||
|
</dict>
|
||||||
|
</array>
|
||||||
|
<key>CFBundleURLTypes</key>
|
||||||
|
<array>
|
||||||
|
<dict>
|
||||||
|
<key>CFBundleURLName</key>
|
||||||
|
<string>Web site URL</string>
|
||||||
|
<key>CFBundleURLSchemes</key>
|
||||||
|
<array>
|
||||||
|
<string>http</string>
|
||||||
|
<string>https</string>
|
||||||
|
<string>gemini</string>
|
||||||
|
</array>
|
||||||
|
</dict>
|
||||||
|
<dict>
|
||||||
|
<key>CFBundleURLName</key>
|
||||||
|
<string>Local file URL</string>
|
||||||
|
<key>CFBundleURLSchemes</key>
|
||||||
|
<array>
|
||||||
|
<string>file</string>
|
||||||
|
</array>
|
||||||
|
</dict>
|
||||||
|
</array>
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include <LibWebView/Database.h>
|
#include <LibWebView/Database.h>
|
||||||
#include <LibWebView/URL.h>
|
#include <LibWebView/URL.h>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QFileOpenEvent>
|
||||||
|
|
||||||
namespace Ladybird {
|
namespace Ladybird {
|
||||||
|
|
||||||
@ -54,9 +55,40 @@ static ErrorOr<void> handle_attached_debugger()
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class LadybirdApplication : public QApplication {
|
||||||
|
public:
|
||||||
|
LadybirdApplication(int& argc, char** argv)
|
||||||
|
: QApplication(argc, argv)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Function<void(URL)> on_open_file;
|
||||||
|
|
||||||
|
bool event(QEvent* event) override
|
||||||
|
{
|
||||||
|
switch (event->type()) {
|
||||||
|
case QEvent::FileOpen: {
|
||||||
|
if (!on_open_file)
|
||||||
|
break;
|
||||||
|
|
||||||
|
auto const& open_event = *static_cast<QFileOpenEvent const*>(event);
|
||||||
|
auto file = MUST(ak_string_from_qstring(open_event.file()));
|
||||||
|
|
||||||
|
if (auto file_url = WebView::sanitize_url(file); file_url.has_value())
|
||||||
|
on_open_file(file_url.release_value());
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return QApplication::event(event);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
{
|
{
|
||||||
QApplication app(arguments.argc, arguments.argv);
|
LadybirdApplication app(arguments.argc, arguments.argv);
|
||||||
|
|
||||||
Core::EventLoopManager::install(*new Ladybird::EventLoopManagerQt);
|
Core::EventLoopManager::install(*new Ladybird::EventLoopManagerQt);
|
||||||
Core::EventLoop event_loop;
|
Core::EventLoop event_loop;
|
||||||
@ -111,6 +143,10 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||||||
Ladybird::BrowserWindow window(initial_urls, cookie_jar, webdriver_content_ipc_path, enable_callgrind_profiling ? WebView::EnableCallgrindProfiling::Yes : WebView::EnableCallgrindProfiling::No, use_lagom_networking ? Ladybird::UseLagomNetworking::Yes : Ladybird::UseLagomNetworking::No, use_gpu_painting ? WebView::EnableGPUPainting::Yes : WebView::EnableGPUPainting::No);
|
Ladybird::BrowserWindow window(initial_urls, cookie_jar, webdriver_content_ipc_path, enable_callgrind_profiling ? WebView::EnableCallgrindProfiling::Yes : WebView::EnableCallgrindProfiling::No, use_lagom_networking ? Ladybird::UseLagomNetworking::Yes : Ladybird::UseLagomNetworking::No, use_gpu_painting ? WebView::EnableGPUPainting::Yes : WebView::EnableGPUPainting::No);
|
||||||
window.setWindowTitle("Ladybird");
|
window.setWindowTitle("Ladybird");
|
||||||
|
|
||||||
|
app.on_open_file = [&](auto file_url) {
|
||||||
|
window.view().load(file_url);
|
||||||
|
};
|
||||||
|
|
||||||
if (Ladybird::Settings::the()->is_maximized()) {
|
if (Ladybird::Settings::the()->is_maximized()) {
|
||||||
window.showMaximized();
|
window.showMaximized();
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user