From af2cdd48d6deea68d8987d1c22925ee0150f8aba Mon Sep 17 00:00:00 2001 From: naturecodevoid <44983869+naturecodevoid@users.noreply.github.com> Date: Sun, 9 Apr 2023 13:34:57 -0700 Subject: [PATCH] feat: add debug logging toggle --- AltStore/Generated/Localizations.swift | 2 ++ AltStore/LaunchViewController.swift | 1 + AltStore/Resources/en.lproj/Localizable.strings | 1 + AltStore/Views/Settings/SettingsView.swift | 17 +++++++++++++++-- .../Extensions/UserDefaults+AltStore.swift | 2 ++ 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/AltStore/Generated/Localizations.swift b/AltStore/Generated/Localizations.swift index 7a481eb0..6942a616 100644 --- a/AltStore/Generated/Localizations.swift +++ b/AltStore/Generated/Localizations.swift @@ -345,6 +345,8 @@ internal enum L10n { internal static let credits = L10n.tr("Localizable", "SettingsView.credits", fallback: "Credits") /// Debug internal static let debug = L10n.tr("Localizable", "SettingsView.debug", fallback: "Debug") + /// Debug Logging + internal static let debugLogging = L10n.tr("Localizable", "SettingsView.debugLogging", fallback: "Debug Logging") /// Export Logs internal static let exportLogs = L10n.tr("Localizable", "SettingsView.exportLogs", fallback: "Export Logs") /// Refreshing Apps diff --git a/AltStore/LaunchViewController.swift b/AltStore/LaunchViewController.swift index cc028720..d333f62b 100644 --- a/AltStore/LaunchViewController.swift +++ b/AltStore/LaunchViewController.swift @@ -159,6 +159,7 @@ final class LaunchViewController: RSTLaunchViewController, UIDocumentPickerDeleg try! FileManager.default.removeItem(at: FileManager.default.documentsDirectory.appendingPathComponent("\(pairingFileName)")) displayError("minimuxer failed to start, please restart SideStore. \(minimuxerToOperationError(error).failureReason ?? "UNKNOWN ERROR!!!!!! REPORT TO GITHUB ISSUES!")") } + set_debug(UserDefaults.shared.isDebugLoggingEnabled) start_auto_mounter(documentsDirectory) } } diff --git a/AltStore/Resources/en.lproj/Localizable.strings b/AltStore/Resources/en.lproj/Localizable.strings index ee820eb6..536f0a2d 100644 --- a/AltStore/Resources/en.lproj/Localizable.strings +++ b/AltStore/Resources/en.lproj/Localizable.strings @@ -62,6 +62,7 @@ "SettingsView.title" = "Settings"; "SettingsView.refreshingAppsFooter" = "Enable Background Refresh to automatically refresh apps in the background when connected to WiFi and with Wireguard active."; "SettingsView.exportLogs" = "Export Logs"; +"SettingsView.debugLogging" = "Debug Logging"; /* ConnectAppleIDView */ "ConnectAppleIDView.startWithSignIn" = "Sign in with your Apple ID to get started."; diff --git a/AltStore/Views/Settings/SettingsView.swift b/AltStore/Views/Settings/SettingsView.swift index 160ebc9d..94b12307 100644 --- a/AltStore/Views/Settings/SettingsView.swift +++ b/AltStore/Views/Settings/SettingsView.swift @@ -12,6 +12,7 @@ import SFSafeSymbols import LocalConsole import AltStoreCore import Intents +import minimuxer struct SettingsView: View { @ObservedObject private var iO = Inject.observer @@ -30,6 +31,9 @@ struct SettingsView: View { @AppStorage("isDevModeEnabled") var isDevModeEnabled: Bool = false + @AppStorage("isDebugLoggingEnabled") + var isDebugLoggingEnabled: Bool = false + @State var isShowingConnectAppleIDView = false @State var isShowingResetPairingFileConfirmation = false @State var isShowingDevModePrompt = false @@ -167,6 +171,12 @@ struct SettingsView: View { AdvancedSettingsView() } + Toggle(L10n.SettingsView.debugLogging, isOn: self.$isDebugLoggingEnabled) + .onChange(of: self.isDebugLoggingEnabled) { value in + UserDefaults.shared.isDebugLoggingEnabled = value + set_debug(value) + } + AsyncFallibleButton(action: self.exportLogs, label: { execute in Text(L10n.SettingsView.exportLogs) }) if MailComposeView.canSendMail { @@ -325,10 +335,10 @@ struct SettingsView: View { } func exportLogs() throws { - guard let path = FileManager.default.altstoreSharedDirectory?.appendingPathComponent("logs.txt") else { throw NSError(domain: "Failed to get path.", code: 1) } + let path = FileManager.default.documentsDirectory.appendingPathComponent("sidestore.log") var text = LCManager.shared.currentText - // TODO: add more potentially sensitive info to this array like UDID + // TODO: add more potentially sensitive info to this array var remove = [String]() if let connectedAppleID = connectedTeams.first { remove.append(connectedAppleID.name) @@ -339,6 +349,9 @@ struct SettingsView: View { remove.append(connectedAppleID.account.identifier) remove.append(connectedAppleID.identifier) } + if let udid = fetch_udid() { + remove.append(udid.toString()) + } for toRemove in remove { text = text.replacingOccurrences(of: toRemove, with: "[removed]") diff --git a/AltStoreCore/Extensions/UserDefaults+AltStore.swift b/AltStoreCore/Extensions/UserDefaults+AltStore.swift index c87b36da..653a5042 100644 --- a/AltStoreCore/Extensions/UserDefaults+AltStore.swift +++ b/AltStoreCore/Extensions/UserDefaults+AltStore.swift @@ -28,6 +28,7 @@ public extension UserDefaults @NSManaged var isDevModeEnabled: Bool @NSManaged var isConsoleEnabled: Bool + @NSManaged var isDebugLoggingEnabled: Bool @NSManaged var isBackgroundRefreshEnabled: Bool @NSManaged var isDebugModeEnabled: Bool @@ -75,6 +76,7 @@ public extension UserDefaults let defaults = [ #keyPath(UserDefaults.isDevModeEnabled): false, #keyPath(UserDefaults.isConsoleEnabled): false, + #keyPath(UserDefaults.isDebugLoggingEnabled): false, #keyPath(UserDefaults.isBackgroundRefreshEnabled): true, #keyPath(UserDefaults.isLegacyDeactivationSupported): isLegacyDeactivationSupported, #keyPath(UserDefaults.activeAppLimitIncludesExtensions): activeAppLimitIncludesExtensions,