diff --git a/src/ui/webview/appkit/webview_appkit.mm b/src/ui/webview/appkit/webview_appkit.mm index 7b076ee..ea53406 100644 --- a/src/ui/webview/appkit/webview_appkit.mm +++ b/src/ui/webview/appkit/webview_appkit.mm @@ -18,7 +18,7 @@ ~Internal() { [webView_ release]; } - void load_url(const std::string &url) { + auto load_url(const std::string &url) -> void { NSString *urlString = [NSString stringWithUTF8String:url.c_str()]; NSURL *nsUrl = [NSURL URLWithString:urlString]; if (nsUrl) { @@ -29,6 +29,18 @@ void load_url(const std::string &url) { } } + auto load_html(const std::string &html_path) -> void { + NSBundle *bundle = [NSBundle mainBundle]; + NSString *html_filename = [NSString stringWithUTF8String:html_path.c_str()]; + NSString *html_filename_without_extension = + [html_filename stringByDeletingPathExtension]; + NSURL *html_url = [bundle URLForResource:html_filename_without_extension + withExtension:@"html"]; + + [this->get_webview() loadFileURL:html_url + allowingReadAccessToURL:[html_url URLByDeletingLastPathComponent]]; + } + auto get_webview() -> WKWebView * { return webView_; } private: @@ -58,17 +70,6 @@ void load_url(const std::string &url) { } auto WebView::load_html(const std::string &html_path) -> void { - NSString *html_filename = [NSString stringWithUTF8String:html_path.c_str()]; - NSString *html_filename_without_extension = - html_filename.stringByDeletingPathExtension; - NSBundle *bundle = [NSBundle mainBundle]; - NSString *path = [bundle pathForResource:html_filename_without_extension - ofType:@"html"]; - NSString *html = [NSString stringWithContentsOfFile:path - encoding:NSUTF8StringEncoding - error:nil]; - - WKWebView *webview = internal_->get_webview(); - [webview loadHTMLString:html baseURL:[bundle resourceURL]]; + internal_->load_html(html_path); } } // namespace sourcemeta::native