//! This example showcases setting up a basic application and window, setting up some views to //! work with autolayout, and some basic ways to handle colors. use cacao::webview::{WebView, WebViewConfig, WebViewDelegate}; use cacao::macos::menu::{Menu, MenuItem}; use cacao::macos::toolbar::Toolbar; use cacao::macos::window::{Window, WindowConfig, WindowDelegate, WindowToolbarStyle}; use cacao::macos::{App, AppDelegate}; struct BasicApp { window: Window } impl AppDelegate for BasicApp { fn did_finish_launching(&self) { App::activate(); self.window.show(); } } #[derive(Default)] pub struct WebViewInstance; impl WebViewDelegate for WebViewInstance { fn on_custom_protocol_request(&self, path: &str) -> Option> { let requested_asset_path = path.replace("cacao://", ""); let index_html = r#"

Welcome 🍫

Link "#; let link_html = r#"

Hello!

Back home "#; return match requested_asset_path.as_str() { "/hello.html" => Some(link_html.as_bytes().into()), _ => Some(index_html.as_bytes().into()) }; } } struct AppWindow { content: WebView } impl AppWindow { pub fn new() -> Self { let mut webview_config = WebViewConfig::default(); // register the protocol in the webview webview_config.add_custom_protocol("cacao"); AppWindow { content: WebView::with(webview_config, WebViewInstance::default()) } } pub fn load_url(&self, url: &str) { self.content.load_url(url); } } impl WindowDelegate for AppWindow { const NAME: &'static str = "WindowDelegate"; fn did_load(&mut self, window: Window) { window.set_title("Browser Example"); window.set_autosave_name("CacaoBrowserExample"); window.set_minimum_content_size(400., 400.); window.set_content_view(&self.content); // load custom protocol self.load_url("cacao://"); } } fn main() { App::new("com.test.window", BasicApp { window: Window::with(WindowConfig::default(), AppWindow::new()) }) .run(); }