From 6283992215658762204db7f8772b2da19123258b Mon Sep 17 00:00:00 2001 From: Zorg Date: Mon, 4 Jan 2021 16:12:58 -0800 Subject: [PATCH] Implement loadRequest method on SUWebView --- Sparkle/SULegacyWebView.m | 6 ++++++ Sparkle/SUUpdateAlert.m | 8 +++++++- Sparkle/SUWKWebView.m | 11 +++++++++++ Sparkle/SUWebView.h | 2 ++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Sparkle/SULegacyWebView.m b/Sparkle/SULegacyWebView.m index 88001013..f266a103 100644 --- a/Sparkle/SULegacyWebView.m +++ b/Sparkle/SULegacyWebView.m @@ -78,6 +78,12 @@ [[self.webView mainFrame] loadData:data MIMEType:MIMEType textEncodingName:textEncodingName baseURL:baseURL]; } +- (void)loadRequest:(NSURLRequest *)urlRequest completionHandler:(void (^)(NSError * _Nullable))completionHandler +{ + self.completionHandler = [completionHandler copy]; + [[self.webView mainFrame] loadRequest:urlRequest]; +} + - (void)stopLoading { self.completionHandler = nil; diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index 11518300..686af1f4 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -159,7 +159,13 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE // If there's a release notes URL, load it; otherwise, just stick the contents of the description into the web view. if ([self.updateItem releaseNotesURL]) { - //[[self.releaseNotesView mainFrame] loadRequest:[NSURLRequest requestWithURL:[self.updateItem releaseNotesURL] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30]]; + __weak __typeof__(self) weakSelf = self; + [self.webView loadRequest:[NSURLRequest requestWithURL:[self.updateItem releaseNotesURL] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30] completionHandler:^(NSError * _Nullable error) { + if (error != nil) { + SULog(SULogLevelError, @"Failed to load URL request from web view: %@", error); + } + [weakSelf stopReleaseNotesSpinner]; + }]; } else { diff --git a/Sparkle/SUWKWebView.m b/Sparkle/SUWKWebView.m index 4ff3957e..4d533e4a 100644 --- a/Sparkle/SUWKWebView.m +++ b/Sparkle/SUWKWebView.m @@ -135,6 +135,17 @@ static WKUserScript *_userScriptWithInjectedStyleSource(NSString *styleSource) #pragma clang diagnostic pop } +- (void)loadRequest:(NSURLRequest *)urlRequest completionHandler:(void (^)(NSError * _Nullable))completionHandler +{ + self.completionHandler = [completionHandler copy]; + + // Remove when minimum system requirement is 10.10+ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunguarded-availability" + self.currentNavigation = [self.webView loadRequest:urlRequest]; +#pragma clang diagnostic pop +} + - (void)setDrawsBackground:(BOOL)drawsBackground { if (self.drawsWebViewBackground != drawsBackground) { diff --git a/Sparkle/SUWebView.h b/Sparkle/SUWebView.h index 253536ed..e2226ce4 100644 --- a/Sparkle/SUWebView.h +++ b/Sparkle/SUWebView.h @@ -20,6 +20,8 @@ NS_ASSUME_NONNULL_BEGIN - (void)loadData:(NSData *)data MIMEType:(NSString *)MIMEType textEncodingName:(NSString *)textEncodingName baseURL:(NSURL *)baseURL completionHandler:(void (^)(NSError * _Nullable))completionHandler; +- (void)loadRequest:(NSURLRequest *)urlRequest completionHandler:(void (^)(NSError * _Nullable))completionHandler; + - (void)stopLoading; - (void)setDrawsBackground:(BOOL)drawsBackground;