2023-08-20 16:14:31 -04:00
|
|
|
/*
|
2025-03-20 12:59:44 -04:00
|
|
|
* Copyright (c) 2023-2025, Tim Flynn <trflynn89@ladybird.org>
|
2023-08-20 16:14:31 -04:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
2024-11-09 12:50:33 -05:00
|
|
|
#include <Interface/LadybirdWebViewBridge.h>
|
2023-08-20 16:14:31 -04:00
|
|
|
#include <LibCore/EventLoop.h>
|
2024-04-28 10:48:29 -04:00
|
|
|
#include <LibCore/ThreadEventQueue.h>
|
2024-08-19 19:17:49 -04:00
|
|
|
#include <LibWebView/Application.h>
|
2024-08-28 15:45:55 -04:00
|
|
|
#include <Utilities/Conversions.h>
|
2023-08-20 16:14:31 -04:00
|
|
|
|
|
|
|
|
#import <Application/Application.h>
|
|
|
|
|
|
|
|
|
|
#if !__has_feature(objc_arc)
|
|
|
|
|
# error "This project requires ARC"
|
|
|
|
|
#endif
|
|
|
|
|
|
2024-08-19 19:17:49 -04:00
|
|
|
namespace Ladybird {
|
|
|
|
|
|
|
|
|
|
class ApplicationBridge : public WebView::Application {
|
|
|
|
|
WEB_VIEW_APPLICATION(ApplicationBridge)
|
2024-08-28 15:45:55 -04:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
virtual Optional<ByteString> ask_user_for_download_folder() const override
|
|
|
|
|
{
|
|
|
|
|
auto* panel = [NSOpenPanel openPanel];
|
|
|
|
|
[panel setAllowsMultipleSelection:NO];
|
|
|
|
|
[panel setCanChooseDirectories:YES];
|
|
|
|
|
[panel setCanChooseFiles:NO];
|
|
|
|
|
[panel setMessage:@"Select download directory"];
|
|
|
|
|
|
|
|
|
|
if ([panel runModal] != NSModalResponseOK)
|
|
|
|
|
return {};
|
|
|
|
|
|
|
|
|
|
return Ladybird::ns_string_to_byte_string([[panel URL] path]);
|
|
|
|
|
}
|
2024-08-19 19:17:49 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
ApplicationBridge::ApplicationBridge(Badge<WebView::Application>, Main::Arguments&)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-20 16:14:31 -04:00
|
|
|
@interface Application ()
|
2024-04-15 17:39:48 -06:00
|
|
|
{
|
|
|
|
|
OwnPtr<Ladybird::ApplicationBridge> m_application_bridge;
|
2024-08-19 19:17:49 -04:00
|
|
|
|
|
|
|
|
RefPtr<Requests::RequestClient> m_request_server_client;
|
|
|
|
|
RefPtr<ImageDecoderClient::Client> m_image_decoder_client;
|
2024-04-15 17:39:48 -06:00
|
|
|
}
|
|
|
|
|
|
2023-08-20 16:14:31 -04:00
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation Application
|
|
|
|
|
|
2024-07-30 14:01:05 -04:00
|
|
|
#pragma mark - Public methods
|
2024-04-15 17:39:48 -06:00
|
|
|
|
2024-07-30 14:01:05 -04:00
|
|
|
- (void)setupWebViewApplication:(Main::Arguments&)arguments
|
|
|
|
|
{
|
2025-03-20 12:59:44 -04:00
|
|
|
m_application_bridge = Ladybird::ApplicationBridge::create(arguments);
|
2024-04-15 17:39:48 -06:00
|
|
|
}
|
|
|
|
|
|
2024-11-13 15:33:02 -05:00
|
|
|
- (ErrorOr<void>)launchServices
|
2024-04-15 17:39:48 -06:00
|
|
|
{
|
2024-11-13 15:33:02 -05:00
|
|
|
TRY(m_application_bridge->launch_services());
|
2024-08-19 19:17:49 -04:00
|
|
|
return {};
|
2024-06-26 13:44:42 -06:00
|
|
|
}
|
|
|
|
|
|
2024-04-15 17:39:48 -06:00
|
|
|
#pragma mark - NSApplication
|
|
|
|
|
|
2023-08-20 16:14:31 -04:00
|
|
|
- (void)terminate:(id)sender
|
|
|
|
|
{
|
|
|
|
|
Core::EventLoop::current().quit(0);
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-28 10:48:29 -04:00
|
|
|
- (void)sendEvent:(NSEvent*)event
|
|
|
|
|
{
|
|
|
|
|
if ([event type] == NSEventTypeApplicationDefined) {
|
|
|
|
|
Core::ThreadEventQueue::current().process();
|
|
|
|
|
} else {
|
|
|
|
|
[super sendEvent:event];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-20 16:14:31 -04:00
|
|
|
@end
|