/* * Copyright (c) 2023-2024, Tim Flynn * * SPDX-License-Identifier: BSD-2-Clause */ #include #include #include #include #include #import #if !__has_feature(objc_arc) # error "This project requires ARC" #endif namespace Ladybird { class ApplicationBridge : public WebView::Application { WEB_VIEW_APPLICATION(ApplicationBridge) private: virtual Optional 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]); } }; ApplicationBridge::ApplicationBridge(Badge, Main::Arguments&) { } } @interface Application () { OwnPtr m_application_bridge; RefPtr m_request_server_client; RefPtr m_image_decoder_client; } @end @implementation Application #pragma mark - Public methods - (void)setupWebViewApplication:(Main::Arguments&)arguments newTabPageURL:(URL::URL)new_tab_page_url { m_application_bridge = Ladybird::ApplicationBridge::create(arguments, move(new_tab_page_url)); } - (ErrorOr)launchServices { TRY(m_application_bridge->launch_services()); return {}; } #pragma mark - NSApplication - (void)terminate:(id)sender { Core::EventLoop::current().quit(0); } - (void)sendEvent:(NSEvent*)event { if ([event type] == NSEventTypeApplicationDefined) { Core::ThreadEventQueue::current().process(); } else { [super sendEvent:event]; } } @end