|
17 | 17 | #import "IASKAppSettingsWebViewController.h" |
18 | 18 | #import "IASKSettingsReader.h" |
19 | 19 | #import "IASKSpecifier.h" |
| 20 | +#import "UIColor+IASKAdditions.h" |
20 | 21 |
|
21 | 22 | @interface IASKAppSettingsWebViewController() |
22 | 23 | @property (nullable, nonatomic, strong, readwrite) WKWebView *webView; |
@@ -209,14 +210,15 @@ - (void)viewWillLayoutSubviews { |
209 | 210 | [super viewWillLayoutSubviews]; |
210 | 211 |
|
211 | 212 | self.webView.frame = self.view.bounds; |
212 | | - if (@available(iOS 15.0, *)) { |
213 | | - self.webView.underPageBackgroundColor = UIColor.systemBackgroundColor; |
214 | | - } |
215 | 213 | } |
216 | 214 |
|
217 | 215 | - (void)viewWillAppear:(BOOL)animated { |
218 | 216 | [super viewWillAppear:animated]; |
219 | | - |
| 217 | + |
| 218 | + if (@available(iOS 15.0, *)) { |
| 219 | + self.webView.underPageBackgroundColor = UIColor.systemBackgroundColor; |
| 220 | + } |
| 221 | + |
220 | 222 | // Load URL: |
221 | 223 | [self.webView loadRequest:[NSURLRequest requestWithURL:self.url]]; |
222 | 224 | } |
@@ -348,11 +350,50 @@ - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigat |
348 | 350 | // Stop and hide default indicator and update title: |
349 | 351 | [self.activityIndicatorView stopAnimating]; |
350 | 352 | [self.webView evaluateJavaScript:@"document.title" completionHandler:^(id result, NSError *error) { |
351 | | - NSString* title = (NSString*)result; |
352 | | - self.title = self.customTitle.length ? self.customTitle : title; |
| 353 | + self.title = self.customTitle.length ? self.customTitle : result; |
353 | 354 | }]; |
354 | 355 |
|
355 | | - // Update button states when loading finishes: |
| 356 | + if (@available(iOS 15.0, *)) { |
| 357 | + NSString *javascript = @"function getThemeColorAsHex() {\n" |
| 358 | + " const themeColorMeta = document.querySelector('meta[name=\"theme-color\"]');\n" |
| 359 | + " if (!themeColorMeta) {\n" |
| 360 | + " return null;\n" |
| 361 | + " }\n" |
| 362 | + " \n" |
| 363 | + " const color = themeColorMeta.content;\n" |
| 364 | + " \n" |
| 365 | + " const temp = document.createElement('div');\n" |
| 366 | + " temp.style.color = color;\n" |
| 367 | + " document.body.appendChild(temp);\n" |
| 368 | + " \n" |
| 369 | + " const computedColor = window.getComputedStyle(temp).color;\n" |
| 370 | + " document.body.removeChild(temp);\n" |
| 371 | + " \n" |
| 372 | + " const match = computedColor.match(/rgba?\\((\\d+),\\s*(\\d+),\\s*(\\d+)(?:,\\s*([\\d.]+))?\\)/);\n" |
| 373 | + " \n" |
| 374 | + " if (!match) {\n" |
| 375 | + " return color; // Fallback: Originalwert zurückgeben\n" |
| 376 | + " }\n" |
| 377 | + " \n" |
| 378 | + " const r = parseInt(match[1]);\n" |
| 379 | + " const g = parseInt(match[2]);\n" |
| 380 | + " const b = parseInt(match[3]);\n" |
| 381 | + " const a = match[4] ? parseFloat(match[4]) : 1;\n" |
| 382 | + " \n" |
| 383 | + " const toHex = (num) => num.toString(16).padStart(2, '0');\n" |
| 384 | + " \n" |
| 385 | + " const alphaHex = Math.round(a * 255).toString(16).padStart(2, '0');\n" |
| 386 | + " return `${toHex(r)}${toHex(g)}${toHex(b)}${alphaHex}`;\n" |
| 387 | + "}\n" |
| 388 | + "getThemeColorAsHex()"; |
| 389 | + |
| 390 | + [self.webView evaluateJavaScript:javascript completionHandler: ^(id result, NSError *error) { |
| 391 | + UIColor *color = [UIColor iaskColorWithHexString:result]; |
| 392 | + self.webView.underPageBackgroundColor = color; |
| 393 | + }]; |
| 394 | + } |
| 395 | + |
| 396 | + // Update button states when loading finishes: |
356 | 397 | [self updateNavigationButtons]; |
357 | 398 | } |
358 | 399 |
|
|
0 commit comments