AdvancedSettingsViewController.m 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. // _____ _
  2. // |_ _| |_ _ _ ___ ___ _ __ __ _
  3. // | | | ' \| '_/ -_) -_) ' \/ _` |_
  4. // |_| |_||_|_| \___\___|_|_|_\__,_(_)
  5. //
  6. // Threema iOS Client
  7. // Copyright (c) 2013-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 "AdvancedSettingsViewController.h"
  21. #import "UserSettings.h"
  22. #import "ValidationLogger.h"
  23. #import "NSString+Hex.h"
  24. #import "AppDelegate.h"
  25. #import "AppGroup.h"
  26. #import "ServerConnector.h"
  27. #import "MessageQueue.h"
  28. #import "BundleUtil.h"
  29. #import "ThreemaFramework/ThreemaFramework-swift.h"
  30. #import "ActivityUtil.h"
  31. #import "Utils.h"
  32. #ifdef DEBUG
  33. static const DDLogLevel ddLogLevel = DDLogLevelAll;
  34. #else
  35. static const DDLogLevel ddLogLevel = DDLogLevelNotice;
  36. #endif
  37. @interface AdvancedSettingsViewController ()
  38. @end
  39. @implementation AdvancedSettingsViewController
  40. - (void)viewDidLoad
  41. {
  42. [super viewDidLoad];
  43. self.validationLoggingSwitch.on = [UserSettings sharedUserSettings].validationLogging;
  44. self.enableIPv6Switch.on = [UserSettings sharedUserSettings].enableIPv6;
  45. self.proximityMonitoringSwitch.on = ![UserSettings sharedUserSettings].disableProximityMonitoring;
  46. self.sentryAppDeviceLabel.text = [UserSettings sharedUserSettings].sentryAppDevice != nil ? [UserSettings sharedUserSettings].sentryAppDevice : @"-";
  47. [self.tableView reloadData];
  48. }
  49. - (void)viewWillAppear:(BOOL)animated {
  50. [super viewWillAppear:animated];
  51. [self updateLogSize];
  52. _flushMessageQueueCell.textLabel.text = [BundleUtil localizedStringForKey:@"settings_advanced_flush_message_queue"];
  53. }
  54. - (void)updateLogSize {
  55. self.logSizeLabel.text = [NSString stringWithFormat:@"%lld KB", ([LogManager logFileSize:[LogManager debugLogFile]] + 1023) / 1024];
  56. }
  57. - (BOOL)shouldAutorotate {
  58. return YES;
  59. }
  60. -(UIInterfaceOrientationMask)supportedInterfaceOrientations {
  61. if (SYSTEM_IS_IPAD) {
  62. return UIInterfaceOrientationMaskAll;
  63. }
  64. return UIInterfaceOrientationMaskAllButUpsideDown;
  65. }
  66. - (IBAction)enableIPv6Changed:(id)sender {
  67. [UserSettings sharedUserSettings].enableIPv6 = self.enableIPv6Switch.on;
  68. [self.tableView reloadData];
  69. [[ServerConnector sharedServerConnector] reconnect];
  70. }
  71. - (IBAction)validationLoggingChanged:(id)sender {
  72. [UserSettings sharedUserSettings].validationLogging = self.validationLoggingSwitch.on;
  73. if ([UserSettings sharedUserSettings].validationLogging) {
  74. [LogManager addFileLogger:[LogManager debugLogFile]];
  75. DDLogNotice(@"Start logging %@", [Utils getClientVersion]);
  76. }
  77. else {
  78. [LogManager removeFileLogger:[LogManager debugLogFile]];
  79. }
  80. }
  81. - (IBAction)proximityMonitoringChanged:(id)sender {
  82. [UserSettings sharedUserSettings].disableProximityMonitoring = !self.proximityMonitoringSwitch.on;
  83. [self.tableView reloadData];
  84. }
  85. #pragma mark - UITableView
  86. - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section {
  87. if (section == 1) {
  88. if ([UserSettings sharedUserSettings].disableProximityMonitoring) {
  89. return NSLocalizedString(@"proximity_monitoring_off", nil);
  90. } else {
  91. return NSLocalizedString(@"proximity_monitoring_on", nil);
  92. }
  93. } else if (section == 2) {
  94. return NSLocalizedString(@"validation_logging_expl", nil);
  95. }
  96. return nil;
  97. }
  98. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  99. [super tableView:tableView willDisplayCell:cell forRowAtIndexPath:indexPath];
  100. _logSizeLabel.textColor = [Colors fontLight];
  101. }
  102. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  103. if (indexPath.section == 2 && indexPath.row == 2) {
  104. /* share log */
  105. if ([LogManager logFileSize:[LogManager debugLogFile]] > 0) {
  106. UIActivityViewController *activityViewController = [ActivityUtil activityViewControllerWithActivityItems:@[[LogManager debugLogFile]] applicationActivities:nil];
  107. if (SYSTEM_IS_IPAD == YES) {
  108. CGRect rect = [tableView rectForRowAtIndexPath:indexPath];
  109. activityViewController.popoverPresentationController.sourceRect = rect;
  110. activityViewController.popoverPresentationController.sourceView = self.view;
  111. }
  112. [self presentViewController:activityViewController animated:YES completion:nil];
  113. } else {
  114. [UIAlertTemplate showAlertWithOwner:self title:@"" message:NSLocalizedString(@"log_empty_message", nil) actionOk:nil];
  115. }
  116. } else if (indexPath.section == 2 && indexPath.row == 3) {
  117. /* clear log */
  118. UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  119. [actionSheet addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"validation_log_clear", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction * action) {
  120. [LogManager deleteLogFile:[LogManager debugLogFile]];
  121. [self updateLogSize];
  122. }]];
  123. [actionSheet addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"cancel", nil) style:UIAlertActionStyleCancel handler:nil]];
  124. if (!self.tabBarController) {
  125. CGRect cellRect = [tableView rectForRowAtIndexPath:indexPath];
  126. actionSheet.popoverPresentationController.sourceRect = cellRect;
  127. actionSheet.popoverPresentationController.sourceView = self.view;
  128. }
  129. [self presentViewController:actionSheet animated:YES completion:nil];
  130. }
  131. else if (indexPath.section == 4 && indexPath.row == 1) {
  132. [[MessageQueue sharedMessageQueue] flush];
  133. }
  134. [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
  135. }
  136. @end