Просмотр исходного кода

replace DBDebugKit with simple ViewController showing our custom debugging variables

cyberta 2 лет назад
Родитель
Сommit
4656ea79a3

+ 0 - 1
Podfile

@@ -12,7 +12,6 @@ target 'deltachat-ios' do
   # pod 'openssl-ios-bitcode'
   pod 'ReachabilitySwift'
   pod 'SwiftyBeaver'
-  pod 'DBDebugToolkit'
   pod 'SCSiriWaveformView'
   pod 'SDWebImage', '~> 5.9.1'
   pod 'SDWebImageWebPCoder'

+ 4 - 2
deltachat-ios.xcodeproj/project.pbxproj

@@ -112,6 +112,7 @@
 		30DAF71C275901610073C154 /* BackgroundOptionsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30DAF71B275901610073C154 /* BackgroundOptionsViewController.swift */; };
 		30DDCBE928FCA1FA00465D22 /* PartialScreenPresentationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30DDCBE828FCA1F900465D22 /* PartialScreenPresentationController.swift */; };
 		30DDCBEB28FCA21800465D22 /* AccountSwitchViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30DDCBEA28FCA21800465D22 /* AccountSwitchViewController.swift */; };
+		30DED713292EE4280040835D /* LogViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30DED712292EE4280040835D /* LogViewController.swift */; };
 		30E348DF24F3F819005C93D1 /* ChatTableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30E348DE24F3F819005C93D1 /* ChatTableView.swift */; };
 		30E348E124F53772005C93D1 /* ImageTextCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30E348E024F53772005C93D1 /* ImageTextCell.swift */; };
 		30E348E524F6647D005C93D1 /* FileTextCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30E348E424F6647D005C93D1 /* FileTextCell.swift */; };
@@ -393,6 +394,7 @@
 		30DAF71B275901610073C154 /* BackgroundOptionsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackgroundOptionsViewController.swift; sourceTree = "<group>"; };
 		30DDCBE828FCA1F900465D22 /* PartialScreenPresentationController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PartialScreenPresentationController.swift; sourceTree = "<group>"; };
 		30DDCBEA28FCA21800465D22 /* AccountSwitchViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountSwitchViewController.swift; sourceTree = "<group>"; };
+		30DED712292EE4280040835D /* LogViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogViewController.swift; sourceTree = "<group>"; };
 		30E348DE24F3F819005C93D1 /* ChatTableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatTableView.swift; sourceTree = "<group>"; };
 		30E348E024F53772005C93D1 /* ImageTextCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageTextCell.swift; sourceTree = "<group>"; };
 		30E348E424F6647D005C93D1 /* FileTextCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileTextCell.swift; sourceTree = "<group>"; };
@@ -960,6 +962,7 @@
 				AED423D2249F578B00B6B2BB /* AddGroupMembersViewController.swift */,
 				AE39D322249CFC1A007346A1 /* DocumentGalleryController.swift */,
 				AE57C083255310BB003CFE70 /* ContextMenuController.swift */,
+				30DED712292EE4280040835D /* LogViewController.swift */,
 			);
 			path = Controller;
 			sourceTree = "<group>";
@@ -1263,7 +1266,6 @@
 			inputPaths = (
 				"${PODS_ROOT}/Target Support Files/Pods-deltachat-ios/Pods-deltachat-ios-frameworks.sh",
 				"${BUILT_PRODUCTS_DIR}/CocoaLumberjack/CocoaLumberjack.framework",
-				"${BUILT_PRODUCTS_DIR}/DBDebugToolkit/DBDebugToolkit.framework",
 				"${BUILT_PRODUCTS_DIR}/ReachabilitySwift/Reachability.framework",
 				"${BUILT_PRODUCTS_DIR}/SCSiriWaveformView/SCSiriWaveformView.framework",
 				"${BUILT_PRODUCTS_DIR}/SDWebImage/SDWebImage.framework",
@@ -1277,7 +1279,6 @@
 			name = "[CP] Embed Pods Frameworks";
 			outputPaths = (
 				"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CocoaLumberjack.framework",
-				"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/DBDebugToolkit.framework",
 				"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Reachability.framework",
 				"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SCSiriWaveformView.framework",
 				"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SDWebImage.framework",
@@ -1445,6 +1446,7 @@
 				78ED839421D5AF8A00243125 /* QrCodeView.swift in Sources */,
 				30CE137828D9C40800158DF4 /* ChatDropInteraction.swift in Sources */,
 				3059620E234614E700C80F33 /* DcContact+Extension.swift in Sources */,
+				30DED713292EE4280040835D /* LogViewController.swift in Sources */,
 				AED423D7249F580700B6B2BB /* BlockedContactsViewController.swift in Sources */,
 				303492B32577E40700A523D0 /* DocumentPreview.swift in Sources */,
 				3008CB7424F9436C00E6A617 /* AudioPlayerView.swift in Sources */,

+ 0 - 4
deltachat-ios/AppDelegate.swift

@@ -4,7 +4,6 @@ import SwiftyBeaver
 import UIKit
 import UserNotifications
 import DcCore
-import DBDebugToolkit
 import SDWebImageWebPCoder
 import Intents
 import SDWebImageSVGKitPlugin
@@ -55,9 +54,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
         // setupCrashReporting() may create an additional handler, but we do not want to rely on that
         signal(SIGPIPE, SIG_IGN)
 
-        DBDebugToolkit.setup(with: []) // empty array will override default device shake trigger
-        DBDebugToolkit.setupCrashReporting()
-
         let console = ConsoleDestination()
         console.format = "$DHH:mm:ss.SSS$d $C$L$c $M" // see https://docs.swiftybeaver.com/article/20-custom-format
         logger.addDestination(console)

+ 7 - 1
deltachat-ios/Controller/AccountSetup/AccountSetupController.swift

@@ -449,7 +449,7 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler {
             showCertCheckOptions()
         case tagViewLogCell:
             tableView.deselectRow(at: indexPath, animated: false)
-            SettingsViewController.showDebugToolkit(dcContext: dcContext)
+            showLogViewController()
         default:
             break
         }
@@ -735,6 +735,12 @@ class AccountSetupController: UITableViewController, ProgressAlertHandler {
     }
 
     // MARK: - coordinator
+
+    private func showLogViewController() {
+        let controller = LogViewController(dcContext: dcContext)
+        navigationController?.pushViewController(controller, animated: true)
+    }
+
     private func showCertCheckOptions() {
         let certificateCheckController = CertificateCheckController(dcContext: dcContext, sectionTitle: String.localized("login_certificate_checks"))
         navigationController?.pushViewController(certificateCheckController, animated: true)

+ 110 - 0
deltachat-ios/Controller/LogViewController.swift

@@ -0,0 +1,110 @@
+import UIKit
+import DcCore
+
+public class LogViewController: UIViewController {
+
+    private let dcContext: DcContext
+
+    private lazy var logText: UITextView = {
+        let label = UITextView()
+        label.contentInset = UIEdgeInsets(top: 12, left: 0, bottom: 0, right: 0)
+        label.translatesAutoresizingMaskIntoConstraints = false
+        return label
+    }()
+
+    init(dcContext: DcContext) {
+        self.dcContext = dcContext
+        super.init(nibName: nil, bundle: nil)
+        self.navigationItem.title = String.localized("pref_log_header")
+        self.hidesBottomBarWhenPushed = true
+    }
+
+    required init?(coder: NSCoder) {
+        fatalError("init(coder:) has not been implemented")
+    }
+
+    public override func viewDidLoad() {
+        setupSubviews()
+    }
+
+    private func setupSubviews() {
+        self.view.addSubview(logText)
+        self.view.backgroundColor = DcColors.defaultBackgroundColor
+        self.view.addConstraints([
+            logText.constraintAlignTopToAnchor(view.safeAreaLayoutGuide.topAnchor),
+            logText.constraintAlignLeadingToAnchor(view.safeAreaLayoutGuide.leadingAnchor, paddingLeading: 12),
+            logText.constraintAlignTrailingToAnchor(view.safeAreaLayoutGuide.trailingAnchor, paddingTrailing: 12),
+            logText.constraintAlignBottomToAnchor(view.safeAreaLayoutGuide.bottomAnchor, paddingBottom: 12)
+        ])
+        logText.text = getDebugVariables(dcContext: dcContext)
+        logText.setContentOffset(.zero, animated: false)
+    }
+
+    @objc
+    private func doneButtonPressed() {
+        dismiss(animated: true)
+    }
+
+    public func getDebugVariables(dcContext: DcContext) -> String {
+        var info = ""
+
+        let systemVersion = UIDevice.current.systemVersion
+        info += "iosVersion=\(systemVersion)\n"
+
+        let notifyEnabled = !UserDefaults.standard.bool(forKey: "notifications_disabled")
+        info += "notify-enabled=\(notifyEnabled)\n"
+
+        if let appDelegate = UIApplication.shared.delegate as? AppDelegate {
+            info += "notify-token=\(appDelegate.notifyToken ?? "<unset>")\n"
+        }
+
+        for name in ["notify-remote-launch", "notify-remote-receive", "notify-local-wakeup"] {
+            let cnt = UserDefaults.standard.integer(forKey: name + "-count")
+
+            let startDbl = UserDefaults.standard.double(forKey: name + "-start")
+            let startStr = startDbl==0.0 ? "" : " since " + DateUtils.getExtendedRelativeTimeSpanString(timeStamp: startDbl)
+
+            let timestampDbl = UserDefaults.standard.double(forKey: name + "-last")
+            let timestampStr = timestampDbl==0.0 ? "" : ", last " + DateUtils.getExtendedRelativeTimeSpanString(timeStamp: timestampDbl)
+
+            info += "\(name)=\(cnt)x\(startStr)\(timestampStr)\n"
+        }
+
+        info += "notify-timestamps="
+        if let timestamps = UserDefaults.standard.array(forKey: Constants.Keys.notificationTimestamps) as? [Double] {
+            for currTimestamp in timestamps {
+                info += DateUtils.getExtendedAbsTimeSpanString(timeStamp: currTimestamp) + " "
+            }
+        }
+        info += "\n"
+
+        info += "notify-fetch-info2="
+        if let infos = UserDefaults.standard.array(forKey: "notify-fetch-info2")  as? [String] {
+            for currInfo in infos {
+                info += currInfo
+                    .replacingOccurrences(of: "📡", with: "\n📡")
+                    .replacingOccurrences(of: "🏠", with: "\n🏠") + " "
+            }
+        }
+        info += "\n"
+
+        var val = "?"
+        switch UIApplication.shared.backgroundRefreshStatus {
+        case .restricted: val = "restricted"
+        case .available: val = "available"
+        case .denied: val = "denied"
+        }
+        info += "backgroundRefreshStatus=\(val)\n"
+
+        #if DEBUG
+        info += "DEBUG=1\n"
+        #else
+        info += "DEBUG=0\n"
+        #endif
+
+        info += "\n" + dcContext.getInfo()
+
+        return info
+    }
+
+}

+ 6 - 64
deltachat-ios/Controller/Settings/SettingsViewController.swift

@@ -1,6 +1,5 @@
 import UIKit
 import DcCore
-import DBDebugToolkit
 import Intents
 
 internal final class SettingsViewController: UITableViewController, ProgressAlertHandler {
@@ -428,6 +427,11 @@ internal final class SettingsViewController: UITableViewController, ProgressAler
         present(askAlert, animated: true, completion: nil)
     }
 
+    private func showLogViewController() {
+        let controller = LogViewController(dcContext: dcContext)
+        navigationController?.pushViewController(controller, animated: true)
+    }
+
     private func showExperimentalDialog() {
         let alert = UIAlertController(title: String.localized("pref_experimental_features"), message: nil, preferredStyle: .safeActionSheet)
 
@@ -500,7 +504,7 @@ internal final class SettingsViewController: UITableViewController, ProgressAler
 
         let logAction = UIAlertAction(title: String.localized("pref_view_log"), style: .default, handler: { [weak self] _ in
             guard let self = self else { return }
-            SettingsViewController.showDebugToolkit(dcContext: self.dcContext)
+            self.showLogViewController()
         })
         alert.addAction(logAction)
         alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: nil))
@@ -592,66 +596,4 @@ internal final class SettingsViewController: UITableViewController, ProgressAler
         navigationController?.pushViewController(BackgroundOptionsViewController(dcContext: dcContext), animated: true)
     }
 
-    public static func showDebugToolkit(dcContext: DcContext) {
-        var info = ""
-
-        let systemVersion = UIDevice.current.systemVersion
-        info += "iosVersion=\(systemVersion)\n"
-
-        let notifyEnabled = !UserDefaults.standard.bool(forKey: "notifications_disabled")
-        info += "notify-enabled=\(notifyEnabled)\n"
-
-        if let appDelegate = UIApplication.shared.delegate as? AppDelegate {
-            info += "notify-token=\(appDelegate.notifyToken ?? "<unset>")\n"
-        }
-
-        for name in ["notify-remote-launch", "notify-remote-receive", "notify-local-wakeup"] {
-            let cnt = UserDefaults.standard.integer(forKey: name + "-count")
-
-            let startDbl = UserDefaults.standard.double(forKey: name + "-start")
-            let startStr = startDbl==0.0 ? "" : " since " + DateUtils.getExtendedRelativeTimeSpanString(timeStamp: startDbl)
-
-            let timestampDbl = UserDefaults.standard.double(forKey: name + "-last")
-            let timestampStr = timestampDbl==0.0 ? "" : ", last " + DateUtils.getExtendedRelativeTimeSpanString(timeStamp: timestampDbl)
-
-            info += "\(name)=\(cnt)x\(startStr)\(timestampStr)\n"
-        }
-
-        info += "notify-timestamps="
-        if let timestamps = UserDefaults.standard.array(forKey: Constants.Keys.notificationTimestamps) as? [Double] {
-            for currTimestamp in timestamps {
-                info += DateUtils.getExtendedAbsTimeSpanString(timeStamp: currTimestamp) + " "
-            }
-        }
-        info += "\n"
-
-        info += "notify-fetch-info2="
-        if let infos = UserDefaults.standard.array(forKey: "notify-fetch-info2")  as? [String] {
-            for currInfo in infos {
-                info += currInfo
-                    .replacingOccurrences(of: "📡", with: "\n📡")
-                    .replacingOccurrences(of: "🏠", with: "\n🏠") + " "
-            }
-        }
-        info += "\n"
-
-        var val = "?"
-        switch UIApplication.shared.backgroundRefreshStatus {
-        case .restricted: val = "restricted"
-        case .available: val = "available"
-        case .denied: val = "denied"
-        }
-        info += "backgroundRefreshStatus=\(val)\n"
-
-        #if DEBUG
-        info += "DEBUG=1\n"
-        #else
-        info += "DEBUG=0\n"
-        #endif
-
-        info += "\n" + dcContext.getInfo()
-
-        DBDebugToolkit.add(DBCustomVariable(name: "", value: info))
-        DBDebugToolkit.showMenu()
-    }
 }