Skip to content

Commit 43e6f43

Browse files
authored
refactor(ui/webview): hide load_html in internals (#40)
Signed-off-by: Tony Gorez <[email protected]>
1 parent a9e2d8f commit 43e6f43

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/ui/webview/appkit/webview_appkit.mm

+14-13
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
~Internal() { [webView_ release]; }
2020

21-
void load_url(const std::string &url) {
21+
auto load_url(const std::string &url) -> void {
2222
NSString *urlString = [NSString stringWithUTF8String:url.c_str()];
2323
NSURL *nsUrl = [NSURL URLWithString:urlString];
2424
if (nsUrl) {
@@ -29,6 +29,18 @@ void load_url(const std::string &url) {
2929
}
3030
}
3131

32+
auto load_html(const std::string &html_path) -> void {
33+
NSBundle *bundle = [NSBundle mainBundle];
34+
NSString *html_filename = [NSString stringWithUTF8String:html_path.c_str()];
35+
NSString *html_filename_without_extension =
36+
[html_filename stringByDeletingPathExtension];
37+
NSURL *html_url = [bundle URLForResource:html_filename_without_extension
38+
withExtension:@"html"];
39+
40+
[this->get_webview() loadFileURL:html_url
41+
allowingReadAccessToURL:[html_url URLByDeletingLastPathComponent]];
42+
}
43+
3244
auto get_webview() -> WKWebView * { return webView_; }
3345

3446
private:
@@ -58,17 +70,6 @@ void load_url(const std::string &url) {
5870
}
5971

6072
auto WebView::load_html(const std::string &html_path) -> void {
61-
NSString *html_filename = [NSString stringWithUTF8String:html_path.c_str()];
62-
NSString *html_filename_without_extension =
63-
html_filename.stringByDeletingPathExtension;
64-
NSBundle *bundle = [NSBundle mainBundle];
65-
NSString *path = [bundle pathForResource:html_filename_without_extension
66-
ofType:@"html"];
67-
NSString *html = [NSString stringWithContentsOfFile:path
68-
encoding:NSUTF8StringEncoding
69-
error:nil];
70-
71-
WKWebView *webview = internal_->get_webview();
72-
[webview loadHTMLString:html baseURL:[bundle resourceURL]];
73+
internal_->load_html(html_path);
7374
}
7475
} // namespace sourcemeta::native

0 commit comments

Comments
 (0)