LicenseViewController.m 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // _____ _
  2. // |_ _| |_ _ _ ___ ___ _ __ __ _
  3. // | | | ' \| '_/ -_) -_) ' \/ _` |_
  4. // |_| |_||_|_| \___\___|_|_|_\__,_(_)
  5. //
  6. // Threema iOS Client
  7. // Copyright (c) 2012-2020 Threema GmbH
  8. //
  9. // This program is free software: you can redistribute it and/or modify
  10. // it under the terms of the GNU Affero General Public License, version 3,
  11. // as published by the Free Software Foundation.
  12. //
  13. // This program is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. // GNU Affero General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Affero General Public License
  19. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. #import "LicenseViewController.h"
  21. #import "BundleUtil.h"
  22. @interface LicenseViewController () <WKNavigationDelegate>
  23. @end
  24. @implementation LicenseViewController
  25. static NSString *licenseFile = @"license.html";
  26. - (void)viewDidLoad {
  27. [super viewDidLoad];
  28. self.view.backgroundColor = [Colors background];
  29. WKPreferences *webprefs = [[WKPreferences alloc] init];
  30. webprefs.javaScriptEnabled = NO;
  31. WKWebViewConfiguration *webconfig = [[WKWebViewConfiguration alloc] init];
  32. webconfig.preferences = webprefs;
  33. self.webView = [[WKWebView alloc] initWithFrame:self.view.frame configuration:webconfig];
  34. self.webView.allowsLinkPreview = NO;
  35. self.webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  36. self.webView.opaque = false;
  37. [self.view addSubview:self.webView];
  38. }
  39. - (void)viewWillAppear:(BOOL)animated {
  40. [super viewWillAppear:animated];
  41. NSString *licenseFilePath = [BundleUtil pathForResource:licenseFile ofType:nil];
  42. NSString *path = [[NSBundle mainBundle] bundlePath];
  43. NSURL *baseURL = [NSURL fileURLWithPath:path];
  44. NSString *htmlString = [NSString stringWithContentsOfFile:licenseFilePath encoding:NSUTF8StringEncoding error:nil];
  45. self.webView.backgroundColor = [Colors backgroundDark];
  46. self.webView.navigationDelegate = self;
  47. switch ([Colors getTheme]) {
  48. case ColorThemeDark:
  49. case ColorThemeDarkWork:
  50. htmlString = [htmlString stringByReplacingOccurrencesOfString:@"/*backgroundcolor*/background-color: white;/*backgroundcolor*/" withString:@"background-color: #333"];
  51. htmlString = [htmlString stringByReplacingOccurrencesOfString:@"/*fontcolor*/color: black;/*fontcolor*/" withString:@"color: white"];
  52. htmlString = [htmlString stringByReplacingOccurrencesOfString:@"/*titlefontcolor*/color: #555;/*titlefontcolor*/" withString:@"color: #CCC;"];
  53. htmlString = [htmlString stringByReplacingOccurrencesOfString:@"/*titlefontcolor*/color: #777;/*titlefontcolor*/" withString:@"color: #AAA;"];
  54. break;
  55. case ColorThemeLight:
  56. case ColorThemeLightWork:
  57. case ColorThemeUndefined:
  58. break;
  59. }
  60. [self.webView loadHTMLString:htmlString baseURL:baseURL];
  61. }
  62. - (BOOL)shouldAutorotate {
  63. return YES;
  64. }
  65. -(UIInterfaceOrientationMask)supportedInterfaceOrientations {
  66. if (SYSTEM_IS_IPAD) {
  67. return UIInterfaceOrientationMaskAll;
  68. }
  69. return UIInterfaceOrientationMaskAllButUpsideDown;
  70. }
  71. - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
  72. if (navigationAction.navigationType == WKNavigationTypeLinkActivated) {
  73. if (navigationAction.request.URL != nil) {
  74. [[UIApplication sharedApplication] openURL:navigationAction.request.URL options:@{} completionHandler:nil];
  75. decisionHandler(WKNavigationActionPolicyCancel);
  76. return;
  77. }
  78. }
  79. decisionHandler(WKNavigationActionPolicyAllow);
  80. }
  81. @end