diff --git a/Loop.xcodeproj/project.pbxproj b/Loop.xcodeproj/project.pbxproj index 504223dd3a..f9e627120a 100644 --- a/Loop.xcodeproj/project.pbxproj +++ b/Loop.xcodeproj/project.pbxproj @@ -54,7 +54,6 @@ 1D4A3E2D2478628500FD601B /* StoredAlert+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D4A3E2B2478628500FD601B /* StoredAlert+CoreDataClass.swift */; }; 1D4A3E2E2478628500FD601B /* StoredAlert+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D4A3E2C2478628500FD601B /* StoredAlert+CoreDataProperties.swift */; }; 1D63DEA526E950D400F46FA5 /* SupportManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D63DEA426E950D400F46FA5 /* SupportManager.swift */; }; - C1A55E012E9F000000A10002 /* IssueReportSubmitter.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1A55E012E9F000000A10001 /* IssueReportSubmitter.swift */; }; 1D6B1B6726866D89009AC446 /* AlertPermissionsChecker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D6B1B6626866D89009AC446 /* AlertPermissionsChecker.swift */; }; 1D70C40126EC0F9D00C62570 /* SupportManagerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D70C40026EC0F9D00C62570 /* SupportManagerTests.swift */; }; 1D80313D24746274002810DF /* AlertStoreTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D80313C24746274002810DF /* AlertStoreTests.swift */; }; @@ -105,7 +104,6 @@ 4328E0351CFC0AE100E199AA /* WatchDataManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4328E0341CFC0AE100E199AA /* WatchDataManager.swift */; }; 432CF87520D8AC950066B889 /* NSUserDefaults+WatchApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4328E0231CFBE2C500E199AA /* NSUserDefaults+WatchApp.swift */; }; 432E73CB1D24B3D6009AD15D /* RemoteDataServicesManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 432E73CA1D24B3D6009AD15D /* RemoteDataServicesManager.swift */; }; - 433EA4C41D9F71C800CD78FB /* CommandResponseViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 433EA4C31D9F71C800CD78FB /* CommandResponseViewController.swift */; }; 4344628220A7A37F00C4BE6F /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4344628120A7A37E00C4BE6F /* CoreBluetooth.framework */; }; 4344629220A7C19800C4BE6F /* ButtonGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4344629120A7C19800C4BE6F /* ButtonGroup.swift */; }; 4344629820A8B2D700C4BE6F /* OSLog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4374B5EE209D84BE00D17AA8 /* OSLog.swift */; }; @@ -345,7 +343,6 @@ A987CD4924A58A0100439ADC /* ZipArchive.swift in Sources */ = {isa = PBXBuildFile; fileRef = A987CD4824A58A0100439ADC /* ZipArchive.swift */; }; A999D40624663D18004C89D4 /* PumpManagerError.swift in Sources */ = {isa = PBXBuildFile; fileRef = A999D40524663D18004C89D4 /* PumpManagerError.swift */; }; A9A056B324B93C62007CF06D /* CriticalEventLogExportView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9A056B224B93C62007CF06D /* CriticalEventLogExportView.swift */; }; - C1A55E012E9F000000A10004 /* SendIssueReportView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C1A55E012E9F000000A10003 /* SendIssueReportView.swift */; }; A9A056B524B94123007CF06D /* CriticalEventLogExportViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9A056B424B94123007CF06D /* CriticalEventLogExportViewModel.swift */; }; A9A63F8E246B271600588D5B /* NSTimeInterval.swift in Sources */ = {isa = PBXBuildFile; fileRef = 439897341CD2F7DE00223065 /* NSTimeInterval.swift */; }; A9B607B0247F000F00792BE4 /* UserNotifications+Loop.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9B607AF247F000F00792BE4 /* UserNotifications+Loop.swift */; }; @@ -791,7 +788,6 @@ 1D4A3E2B2478628500FD601B /* StoredAlert+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "StoredAlert+CoreDataClass.swift"; sourceTree = ""; }; 1D4A3E2C2478628500FD601B /* StoredAlert+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "StoredAlert+CoreDataProperties.swift"; sourceTree = ""; }; 1D63DEA426E950D400F46FA5 /* SupportManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SupportManager.swift; sourceTree = ""; }; - C1A55E012E9F000000A10001 /* IssueReportSubmitter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IssueReportSubmitter.swift; sourceTree = ""; }; 1D6B1B6626866D89009AC446 /* AlertPermissionsChecker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertPermissionsChecker.swift; sourceTree = ""; }; 1D70C40026EC0F9D00C62570 /* SupportManagerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SupportManagerTests.swift; sourceTree = ""; }; 1D80313C24746274002810DF /* AlertStoreTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlertStoreTests.swift; sourceTree = ""; }; @@ -844,7 +840,6 @@ 4328E0341CFC0AE100E199AA /* WatchDataManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = WatchDataManager.swift; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; 432E73CA1D24B3D6009AD15D /* RemoteDataServicesManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RemoteDataServicesManager.swift; sourceTree = ""; }; 4337615E1D52F487004A3647 /* GlucoseHUDView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GlucoseHUDView.swift; sourceTree = ""; }; - 433EA4C31D9F71C800CD78FB /* CommandResponseViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CommandResponseViewController.swift; sourceTree = ""; }; 4344628120A7A37E00C4BE6F /* CoreBluetooth.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreBluetooth.framework; path = Platforms/WatchOS.platform/Developer/SDKs/WatchOS.sdk/System/Library/Frameworks/CoreBluetooth.framework; sourceTree = DEVELOPER_DIR; }; 4344628320A7A3BE00C4BE6F /* LoopKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = LoopKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 4344628420A7A3BE00C4BE6F /* CGMBLEKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = CGMBLEKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -1157,7 +1152,6 @@ A987CD4824A58A0100439ADC /* ZipArchive.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ZipArchive.swift; sourceTree = ""; }; A999D40524663D18004C89D4 /* PumpManagerError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PumpManagerError.swift; sourceTree = ""; }; A9A056B224B93C62007CF06D /* CriticalEventLogExportView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CriticalEventLogExportView.swift; sourceTree = ""; }; - C1A55E012E9F000000A10003 /* SendIssueReportView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SendIssueReportView.swift; sourceTree = ""; }; A9A056B424B94123007CF06D /* CriticalEventLogExportViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CriticalEventLogExportViewModel.swift; sourceTree = ""; }; A9B607AF247F000F00792BE4 /* UserNotifications+Loop.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UserNotifications+Loop.swift"; sourceTree = ""; }; A9B996EF27235191002DC09C /* LoopWarning.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoopWarning.swift; sourceTree = ""; }; @@ -1956,7 +1950,6 @@ children = ( 43A51E1E1EB6D62A000736CC /* CarbAbsorptionViewController.swift */, 43A51E201EB6DBDD000736CC /* LoopChartsTableViewController.swift */, - 433EA4C31D9F71C800CD78FB /* CommandResponseViewController.swift */, C178249F1E19CF9800D9D25C /* GlucoseThresholdTableViewController.swift */, 4302F4E21D4EA54200F0FCAF /* InsulinDeliveryTableViewController.swift */, 437D9BA21D7BC977007245E8 /* PredictionTableViewController.swift */, @@ -1980,7 +1973,6 @@ 149A28BC2A853E6C00052EDF /* CarbEntryView.swift */, 431A8C3F1EC6E8AB00823B9C /* CircleMaskView.swift */, A9A056B224B93C62007CF06D /* CriticalEventLogExportView.swift */, - C1A55E012E9F000000A10003 /* SendIssueReportView.swift */, C191D2A025B3ACAA00C26C0B /* DosingStrategySelectionView.swift */, 149A28E32A8A63A700052EDF /* FavoriteFoodDetailView.swift */, 142CB75A2A60BFC30075748A /* FavoriteFoodsView.swift */, @@ -2038,7 +2030,6 @@ B470F5832AB22B5100049695 /* StatefulPluggable.swift */, 43FCEEA8221A615B0013DD30 /* StatusChartsManager.swift */, 1D63DEA426E950D400F46FA5 /* SupportManager.swift */, - C1A55E012E9F000000A10001 /* IssueReportSubmitter.swift */, 4F70C20F1DE8FAC5006380B7 /* ExtensionDataManager.swift */, 89ADE13A226BFA0F0067222B /* TestingScenariosManager.swift */, 1D82E69F25377C6B009131FB /* TrustedTimeChecker.swift */, @@ -3395,7 +3386,6 @@ 897A5A9624C2175B00C4E71D /* BolusEntryView.swift in Sources */, 4F70C2131DE90339006380B7 /* StatusExtensionContext.swift in Sources */, A9A056B324B93C62007CF06D /* CriticalEventLogExportView.swift in Sources */, - C1A55E012E9F000000A10004 /* SendIssueReportView.swift in Sources */, 43C05CC521EC29E3006FB252 /* TextFieldTableViewCell.swift in Sources */, 4FF4D1001E18374700846527 /* WatchContext.swift in Sources */, C1D289B522F90A52003FFBD9 /* BasalDeliveryState.swift in Sources */, @@ -3516,7 +3506,6 @@ A96DAC2C2838F31200D94E38 /* SharedLogging.swift in Sources */, 4302F4E31D4EA54200F0FCAF /* InsulinDeliveryTableViewController.swift in Sources */, 1D63DEA526E950D400F46FA5 /* SupportManager.swift in Sources */, - C1A55E012E9F000000A10002 /* IssueReportSubmitter.swift in Sources */, 4FC8C8011DEB93E400A1452E /* NSUserDefaults+StatusExtension.swift in Sources */, 43E93FB61E469A4000EAB8DB /* NumberFormatter.swift in Sources */, C1FB428C217806A400FAB378 /* StateColorPalette.swift in Sources */, @@ -3541,7 +3530,6 @@ A987CD4924A58A0100439ADC /* ZipArchive.swift in Sources */, 43F41C371D3BF32400C11ED6 /* UIAlertController.swift in Sources */, A9CBE45C248ACC03008E7BA2 /* SettingsStore+SimulatedCoreData.swift in Sources */, - 433EA4C41D9F71C800CD78FB /* CommandResponseViewController.swift in Sources */, E9B3552229358C440076AB04 /* MealDetectionManager.swift in Sources */, C16DA84222E8E112008624C2 /* PluginManager.swift in Sources */, 43785E932120A01B0057DED1 /* NewCarbEntryIntent+Loop.swift in Sources */, diff --git a/Loop/Localizable.xcstrings b/Loop/Localizable.xcstrings index 217ff2266f..afb02be490 100644 --- a/Loop/Localizable.xcstrings +++ b/Loop/Localizable.xcstrings @@ -19028,6 +19028,7 @@ }, "Export Critical Event Logs" : { "comment" : "The title of the export critical event logs in support", + "extractionState" : "stale", "localizations" : { "da" : { "stringUnit" : { @@ -24168,6 +24169,7 @@ }, "Issue Report" : { "comment" : "The title text for the issue report menu item\nThe view controller title for the issue report screen", + "extractionState" : "stale", "localizations" : { "ar" : { "stringUnit" : { @@ -24804,6 +24806,7 @@ }, "Loading..." : { "comment" : "The loading message for the diagnostic report screen", + "extractionState" : "stale", "localizations" : { "ar" : { "stringUnit" : { diff --git a/Loop/Managers/IssueReportSubmitter.swift b/Loop/Managers/IssueReportSubmitter.swift deleted file mode 100644 index 68669dd2f3..0000000000 --- a/Loop/Managers/IssueReportSubmitter.swift +++ /dev/null @@ -1,139 +0,0 @@ -// -// IssueReportSubmitter.swift -// Loop -// -// Copyright © 2026 LoopKit Authors. All rights reserved. -// - -import Foundation - -struct IssueReport { - struct Contact: Encodable { - var name: String? - var email: String? - var zulip: String? - var github: String? - } - - struct Attachment { - var filename: String - var contentType: String - var data: Data - } - - var title: String? - var description: String - var contact: Contact? - var context: [String: IssueReportContextValue] - var attachments: [Attachment] -} - -enum IssueReportContextValue: Encodable, Equatable { - case string(String) - case strings([String]) - - func encode(to encoder: Encoder) throws { - var container = encoder.singleValueContainer() - switch self { - case .string(let value): try container.encode(value) - case .strings(let value): try container.encode(value) - } - } -} - -enum IssueReportSubmitterError: LocalizedError { - case server(status: Int, reason: String?) - case invalidResponse - case network(Error) - - var isRetryable: Bool { - switch self { - case .server(let status, _): return status >= 500 - case .invalidResponse, .network: return true - } - } - - var errorDescription: String? { - switch self { - case .server(413, _): - return NSLocalizedString("The report is too large. Try fewer or smaller screenshots.", comment: "Issue report error when the upload is too large") - case .server(415, _): - return NSLocalizedString("One of the attachments isn't a supported image type.", comment: "Issue report error when an attachment type is refused") - case .server(429, _): - return NSLocalizedString("Too many reports have been sent from this network recently. Please try again later.", comment: "Issue report error when rate limited") - case .server(let status, let reason): - return String(format: NSLocalizedString("The server couldn't accept the report (%1$d %2$@).", comment: "Issue report error with HTTP status (1) and reason (2)"), status, reason ?? "") - case .invalidResponse: - return NSLocalizedString("The server sent an unexpected response.", comment: "Issue report error for an unreadable response") - case .network(let error): - return error.localizedDescription - } - } -} - -struct IssueReportSubmitter { - static let endpoint = URL(string: "https://ingest.loopkit.org/v1/issues")! - static let apiKey = "7dd7414785560c0dd1ef802ac10c00b4" - - var session: URLSession = .shared - - func submit(_ report: IssueReport) async throws -> String { - let boundary = "Boundary-\(UUID().uuidString)" - var request = URLRequest(url: Self.endpoint) - request.httpMethod = "POST" - request.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type") - - let body = try Self.body(for: report, boundary: boundary) - let data: Data - let response: URLResponse - do { - (data, response) = try await session.upload(for: request, from: body) - } catch { - throw IssueReportSubmitterError.network(error) - } - guard let response = response as? HTTPURLResponse else { - throw IssueReportSubmitterError.invalidResponse - } - let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any] - guard response.statusCode == 200 else { - throw IssueReportSubmitterError.server(status: response.statusCode, reason: json?["error"] as? String) - } - guard let id = json?["id"] as? String else { - throw IssueReportSubmitterError.invalidResponse - } - return id - } - - static func body(for report: IssueReport, boundary: String) throws -> Data { - struct Payload: Encodable { - var title: String? - var description: String - var contact: IssueReport.Contact? - var context: [String: IssueReportContextValue] - } - let payload = try JSONEncoder().encode(Payload(title: report.title, description: report.description, contact: report.contact, context: report.context)) - - var body = Data() - func appendPart(name: String, filename: String? = nil, contentType: String? = nil, data: Data) { - var header = "--\(boundary)\r\nContent-Disposition: form-data; name=\"\(name)\"" - if let filename { - header += "; filename=\"\(filename.replacingOccurrences(of: "\"", with: ""))\"" - } - header += "\r\n" - if let contentType { - header += "Content-Type: \(contentType)\r\n" - } - body.append(Data((header + "\r\n").utf8)) - body.append(data) - body.append(Data("\r\n".utf8)) - } - - appendPart(name: "client", data: Data(apiKey.utf8)) - appendPart(name: "report", contentType: "application/json", data: payload) - for attachment in report.attachments { - appendPart(name: "attachment", filename: attachment.filename, contentType: attachment.contentType, data: attachment.data) - } - body.append(Data("--\(boundary)--\r\n".utf8)) - return body - } -} diff --git a/Loop/Managers/LoopAppManager.swift b/Loop/Managers/LoopAppManager.swift index b9a36d1295..efe8d2ad67 100644 --- a/Loop/Managers/LoopAppManager.swift +++ b/Loop/Managers/LoopAppManager.swift @@ -228,7 +228,8 @@ class LoopAppManager: NSObject { supportManager = SupportManager(pluginManager: pluginManager, deviceSupportDelegate: deviceDataManager, servicesManager: deviceDataManager.servicesManager, - alertIssuer: alertManager) + alertIssuer: alertManager, + criticalEventLogExporterFactory: deviceDataManager.criticalEventLogExportManager) setWhitelistedDevices() diff --git a/Loop/Managers/SupportManager.swift b/Loop/Managers/SupportManager.swift index 18f3df912d..eb6a066874 100644 --- a/Loop/Managers/SupportManager.swift +++ b/Loop/Managers/SupportManager.swift @@ -40,6 +40,7 @@ public final class SupportManager { private let pluginManager: PluginManager private let staticSupportTypes: [SupportUI.Type] private let staticSupportTypesByIdentifier: [String: SupportUI.Type] + private let criticalEventLogExporterFactory: CriticalEventLogExporterFactory? lazy private var cancellables = Set() @@ -47,11 +48,13 @@ public final class SupportManager { deviceSupportDelegate: DeviceSupportDelegate, servicesManager: ServicesManager? = nil, staticSupportTypes: [SupportUI.Type]? = nil, - alertIssuer: AlertIssuer) { - + alertIssuer: AlertIssuer, + criticalEventLogExporterFactory: CriticalEventLogExporterFactory? = nil) { + self.alertIssuer = alertIssuer self.deviceSupportDelegate = deviceSupportDelegate self.pluginManager = pluginManager + self.criticalEventLogExporterFactory = criticalEventLogExporterFactory self.staticSupportTypes = [] staticSupportTypesByIdentifier = self.staticSupportTypes.reduce(into: [:]) { (map, type) in map[type.pluginIdentifier] = type @@ -217,7 +220,14 @@ extension SupportManager: SupportUIDelegate { public func openURL(url: URL) { UIApplication.shared.open(url) } - + + public func criticalEventLogExportView() -> AnyView { + guard let criticalEventLogExporterFactory else { + return AnyView(EmptyView()) + } + return AnyView(CriticalEventLogExportView(viewModel: CriticalEventLogExportViewModel(exporterFactory: criticalEventLogExporterFactory))) + } + public var pumpStatus: LoopKit.PumpManagerStatus? { deviceSupportDelegate.pumpManagerStatus } diff --git a/Loop/View Controllers/CommandResponseViewController.swift b/Loop/View Controllers/CommandResponseViewController.swift deleted file mode 100644 index e14c41c8a4..0000000000 --- a/Loop/View Controllers/CommandResponseViewController.swift +++ /dev/null @@ -1,37 +0,0 @@ -// -// CommandResponseViewController.swift -// Loop -// -// Created by Nate Racklyeft on 9/30/16. -// Copyright © 2016 LoopKit Authors. All rights reserved. -// - -import Foundation -import LoopKitUI - - -extension CommandResponseViewController { - typealias T = CommandResponseViewController - - static func generateDiagnosticReport(deviceManager: DeviceDataManager) -> T { - let date = Date() - let vc = T(command: { (completionHandler) in - deviceManager.generateDiagnosticReport { (report) in - DispatchQueue.main.async { - completionHandler([ - "Use the Share button above to save this diagnostic report to aid investigating your problem. Issues can be filed at https://github.com/LoopKit/Loop/issues.", - "Generated: \(date)", - "", - report, - "", - ].joined(separator: "\n\n")) - } - } - - return NSLocalizedString("Loading...", comment: "The loading message for the diagnostic report screen") - }) - vc.fileName = "Loop Report \(ISO8601DateFormatter.string(from: date, timeZone: .current, formatOptions: [.withSpaceBetweenDateAndTime, .withInternetDateTime])).md" - - return vc - } -} diff --git a/Loop/View Controllers/StatusTableViewController.swift b/Loop/View Controllers/StatusTableViewController.swift index eb91cc21d1..580d67eb8a 100644 --- a/Loop/View Controllers/StatusTableViewController.swift +++ b/Loop/View Controllers/StatusTableViewController.swift @@ -1628,7 +1628,6 @@ final class StatusTableViewController: LoopChartsTableViewController { pumpManagerSettingsViewModel: pumpViewModel, cgmManagerSettingsViewModel: cgmViewModel, servicesViewModel: servicesViewModel, - criticalEventLogExportViewModel: CriticalEventLogExportViewModel(exporterFactory: deviceManager.criticalEventLogExportManager), therapySettings: { [weak self] in self?.deviceManager.loopManager.therapySettings ?? TherapySettings() }, sensitivityOverridesEnabled: FeatureFlags.sensitivityOverridesEnabled, initialDosingEnabled: deviceManager.loopManager.settings.dosingEnabled, @@ -2224,30 +2223,6 @@ extension StatusTableViewController: SettingsViewModelDelegate { settings.automaticDosingStrategy = strategy } } - - func didTapIssueReport() { - // TODO: this dismiss here is temporary, until we know exactly where - // we want this screen to belong in the navigation flow - dismiss(animated: true) { - let vc = CommandResponseViewController.generateDiagnosticReport(deviceManager: self.deviceManager) - vc.title = NSLocalizedString("Issue Report", comment: "The view controller title for the issue report screen") - self.show(vc, sender: nil) - } - } - - func generateDiagnosticReport() async -> String { - await withCheckedContinuation { continuation in - deviceManager.generateDiagnosticReport { continuation.resume(returning: $0) } - } - } - - var pumpModel: String? { - deviceManager.pumpManager.map { $0.status.device.model ?? "Unknown" } - } - - var cgmModel: String? { - deviceManager.cgmManager.map { $0.cgmManagerStatus.device?.model ?? "Unknown" } - } } // MARK: - Services delegation diff --git a/Loop/View Models/SettingsViewModel.swift b/Loop/View Models/SettingsViewModel.swift index 672dfa449e..4ce2c1b12f 100644 --- a/Loop/View Models/SettingsViewModel.swift +++ b/Loop/View Models/SettingsViewModel.swift @@ -52,11 +52,7 @@ public typealias PumpManagerViewModel = DeviceViewModel public protocol SettingsViewModelDelegate: AnyObject { func dosingEnabledChanged(_: Bool) func dosingStrategyChanged(_: AutomaticDosingStrategy) - func didTapIssueReport() - func generateDiagnosticReport() async -> String var closedLoopDescriptiveText: String? { get } - var pumpModel: String? { get } - var cgmModel: String? { get } } public class SettingsViewModel: ObservableObject { @@ -69,40 +65,10 @@ public class SettingsViewModel: ObservableObject { private weak var delegate: SettingsViewModelDelegate? - func didTapIssueReport() { - delegate?.didTapIssueReport() - } - - var generateDiagnosticReport: (() async -> String)? { - guard let delegate else { - return nil - } - return { [weak delegate] in await delegate?.generateDiagnosticReport() ?? "" } - } - - @MainActor - var issueReportContext: [String: IssueReportContextValue] { - let buildDetails = BuildDetails.default - var context: [String: IssueReportContextValue] = [ - "appVersion": .string(Bundle.main.shortVersionString), - "buildNumber": .string(Bundle.main.version), - "customizations": .strings(buildDetails.customizations), - "deviceModel": .string(UIDevice.current.modelIdentifier), - "osVersion": .string(UIDevice.current.systemVersion), - ] - context["branch"] = (buildDetails.workspaceGitBranch ?? buildDetails.gitBranch).map { .string($0) } - context["workspaceRevision"] = buildDetails.workspaceGitRevision.map { .string($0) } - context["loopRevision"] = buildDetails.gitRevision.map { .string($0) } - context["pumpModel"] = delegate?.pumpModel.map { .string($0) } - context["cgmModel"] = delegate?.cgmModel.map { .string($0) } - return context - } - var availableSupports: [SupportUI] let pumpManagerSettingsViewModel: PumpManagerViewModel let cgmManagerSettingsViewModel: CGMManagerViewModel let servicesViewModel: ServicesViewModel - let criticalEventLogExportViewModel: CriticalEventLogExportViewModel let therapySettings: () -> TherapySettings let sensitivityOverridesEnabled: Bool let isOnboardingComplete: Bool @@ -139,7 +105,6 @@ public class SettingsViewModel: ObservableObject { pumpManagerSettingsViewModel: PumpManagerViewModel, cgmManagerSettingsViewModel: CGMManagerViewModel, servicesViewModel: ServicesViewModel, - criticalEventLogExportViewModel: CriticalEventLogExportViewModel, therapySettings: @escaping () -> TherapySettings, sensitivityOverridesEnabled: Bool, initialDosingEnabled: Bool, @@ -156,7 +121,6 @@ public class SettingsViewModel: ObservableObject { self.pumpManagerSettingsViewModel = pumpManagerSettingsViewModel self.cgmManagerSettingsViewModel = cgmManagerSettingsViewModel self.servicesViewModel = servicesViewModel - self.criticalEventLogExportViewModel = criticalEventLogExportViewModel self.therapySettings = therapySettings self.sensitivityOverridesEnabled = sensitivityOverridesEnabled self.closedLoopPreference = initialDosingEnabled @@ -204,7 +168,6 @@ extension SettingsViewModel { pumpManagerSettingsViewModel: DeviceViewModel(), cgmManagerSettingsViewModel: DeviceViewModel(), servicesViewModel: ServicesViewModel.preview, - criticalEventLogExportViewModel: CriticalEventLogExportViewModel(exporterFactory: MockCriticalEventLogExporterFactory()), therapySettings: { TherapySettings() }, sensitivityOverridesEnabled: false, initialDosingEnabled: true, diff --git a/Loop/Views/SendIssueReportView.swift b/Loop/Views/SendIssueReportView.swift deleted file mode 100644 index 5eb2ca73ee..0000000000 --- a/Loop/Views/SendIssueReportView.swift +++ /dev/null @@ -1,254 +0,0 @@ -// -// SendIssueReportView.swift -// Loop -// -// Copyright © 2026 LoopKit Authors. All rights reserved. -// - -import PhotosUI -import SwiftUI - -struct SendIssueReportView: View { - let context: [String: IssueReportContextValue] - let generateDiagnosticReport: (() async -> String)? - let exportLocally: () -> Void - - @Environment(\.dismiss) private var dismiss - - @State private var title = "" - @State private var description = "" - @State private var isAnonymous = true - @State private var contact = IssueReport.Contact() - @State private var includeDiagnosticReport = true - @State private var photoSelection: [PhotosPickerItem] = [] - @State private var screenshots: [Screenshot] = [] - @State private var isSending = false - @State private var sentReportID: String? - @State private var sendError: IssueReportSubmitterError? - @State private var showingError = false - - private static let maxDescriptionLength = 20_000 - private static let maxScreenshots = 8 - private static let maxAttachmentBytes = 10_000_000 - - private struct Screenshot: Identifiable { - let id = UUID() - let image: UIImage - let attachment: IssueReport.Attachment - } - - var body: some View { - Form { - Section(footer: Text(String(format: NSLocalizedString("%1$d of %2$d characters", comment: "Issue report description length (1: used)(2: limit)"), description.count, Self.maxDescriptionLength))) { - TextField(NSLocalizedString("Title (optional)", comment: "Placeholder for the issue report title"), text: $title) - ZStack(alignment: .topLeading) { - if description.isEmpty { - Text(NSLocalizedString("Describe what you saw and what you expected to happen", comment: "Placeholder for the issue report description")) - .foregroundColor(Color(.placeholderText)) - .padding(.top, 8) - .padding(.leading, 4) - } - TextEditor(text: $description) - .frame(minHeight: 160) - } - } - - screenshotsSection - - Section(footer: Text(isAnonymous ? - NSLocalizedString("The report won't include your name, contact details or anything else that identifies you.", comment: "Footer for an anonymous issue report") : - NSLocalizedString("Fill in any of these so developers can follow up with you.", comment: "Footer for issue report contact details")) - ) { - Toggle(NSLocalizedString("Submit Anonymously", comment: "Toggle for submitting an issue report without contact details"), isOn: $isAnonymous) - if !isAnonymous { - TextField(NSLocalizedString("Name", comment: "Issue report contact name placeholder"), text: binding(\.name)) - .textContentType(.name) - TextField(NSLocalizedString("Email", comment: "Issue report contact email placeholder"), text: binding(\.email)) - .textContentType(.emailAddress) - .keyboardType(.emailAddress) - .textInputAutocapitalization(.never) - TextField(NSLocalizedString("Zulip Name", comment: "Issue report contact Zulip placeholder"), text: binding(\.zulip)) - .textInputAutocapitalization(.never) - TextField(NSLocalizedString("GitHub Username", comment: "Issue report contact GitHub placeholder"), text: binding(\.github)) - .textInputAutocapitalization(.never) - .autocorrectionDisabled() - } - } - - if generateDiagnosticReport != nil { - Section(footer: Text(NSLocalizedString("Attaches Loop's issue report as a text file. It contains health data such as recent glucose, insulin, carbs and your therapy settings.", comment: "Footer for the include diagnostic report toggle"))) { - Toggle(NSLocalizedString("Include Diagnostic Report", comment: "Toggle for attaching the diagnostic report to an issue report"), isOn: $includeDiagnosticReport) - } - } - - Section(header: Text(NSLocalizedString("Also Sent", comment: "Header for the build and device details sent with an issue report")), - footer: Text(NSLocalizedString("Reports go to the LoopKit development team and are visible only to them. Your IP address is used only to limit how often reports can be sent and is never stored.", comment: "Privacy footer for issue reports"))) - { - ForEach(context.keys.sorted(), id: \.self) { key in - HStack { - Text(key) - Spacer() - Text(Self.displayValue(context[key])) - .foregroundColor(.secondary) - .multilineTextAlignment(.trailing) - } - .font(.footnote) - } - } - - Section(footer: Text(NSLocalizedString("Opens Loop's diagnostic report so you can save it or share it yourself. Nothing is sent to the developers.", comment: "Footer for exporting the issue report locally"))) { - Button(NSLocalizedString("Export Locally Instead", comment: "Button to open the diagnostic report for local export instead of submitting"), action: exportLocally) - } - } - .navigationTitle(NSLocalizedString("Report Issue", comment: "Title of the issue report screen")) - .navigationBarTitleDisplayMode(.inline) - .toolbar { - ToolbarItem(placement: .confirmationAction) { - if isSending { - ProgressView() - } else { - Button(NSLocalizedString("Submit", comment: "Button to submit an issue report to the developers")) { - send() - } - .disabled(!canSend) - } - } - } - .disabled(isSending) - .onChange(of: photoSelection) { _, items in - loadScreenshots(items) - } - .alert(NSLocalizedString("Report Submitted", comment: "Title of the alert after an issue report was submitted"), isPresented: Binding(get: { sentReportID != nil }, set: { if !$0 { sentReportID = nil } })) { - Button(NSLocalizedString("Copy ID", comment: "Button to copy the issue report ID")) { - UIPasteboard.general.string = sentReportID - dismiss() - } - Button(NSLocalizedString("Done", comment: "Button to close the issue report sent alert"), role: .cancel) { - dismiss() - } - } message: { - Text(String(format: NSLocalizedString("Thank you. Your report ID is %1$@. Mention it if you discuss the problem on Zulip or GitHub.", comment: "Message after an issue report was sent (1: report ID)"), sentReportID ?? "")) - } - .alert(NSLocalizedString("Unable to Submit Report", comment: "Title of the alert when an issue report fails"), isPresented: $showingError, presenting: sendError) { error in - if error.isRetryable { - Button(NSLocalizedString("Try Again", comment: "Button to retry sending an issue report")) { - send() - } - } - Button(NSLocalizedString("OK", comment: "Button to close the issue report error alert"), role: .cancel) {} - } message: { error in - Text(error.localizedDescription) - } - } - - private var screenshotsSection: some View { - Section(footer: Text(String(format: NSLocalizedString("Up to %1$d screenshots or photos.", comment: "Footer for issue report screenshots (1: limit)"), Self.maxScreenshots))) { - if !screenshots.isEmpty { - ScrollView(.horizontal) { - HStack { - ForEach(screenshots) { screenshot in - Image(uiImage: screenshot.image) - .resizable() - .scaledToFit() - .frame(height: 120) - .clipShape(RoundedRectangle(cornerRadius: 6)) - } - } - } - } - PhotosPicker(selection: $photoSelection, maxSelectionCount: Self.maxScreenshots, matching: .images) { - Text(screenshots.isEmpty ? - NSLocalizedString("Add Screenshots", comment: "Button to choose screenshots for an issue report") : - NSLocalizedString("Change Screenshots", comment: "Button to change the screenshots on an issue report")) - } - } - } - - private var trimmedDescription: String { - description.trimmingCharacters(in: .whitespacesAndNewlines) - } - - private var canSend: Bool { - !trimmedDescription.isEmpty && description.count <= Self.maxDescriptionLength - } - - private func binding(_ keyPath: WritableKeyPath) -> Binding { - Binding(get: { contact[keyPath: keyPath] ?? "" }, set: { contact[keyPath: keyPath] = $0 }) - } - - private func loadScreenshots(_ items: [PhotosPickerItem]) { - Task { - var loaded: [Screenshot] = [] - for (index, item) in items.enumerated() { - guard let data = try? await item.loadTransferable(type: Data.self), let screenshot = Self.screenshot(from: data, index: index + 1) else { - continue - } - loaded.append(screenshot) - } - screenshots = loaded - } - } - - // The server accepts only PNG and JPEG, so anything else (HEIC from the camera) is converted - private static func screenshot(from data: Data, index: Int) -> Screenshot? { - guard let image = UIImage(data: data) else { - return nil - } - if data.starts(with: [0x89, 0x50, 0x4E, 0x47]), data.count <= maxAttachmentBytes { - return Screenshot(image: image, attachment: .init(filename: "screenshot-\(index).png", contentType: "image/png", data: data)) - } - for quality in [0.8, 0.5, 0.3] { - if let jpeg = image.jpegData(compressionQuality: quality), jpeg.count <= maxAttachmentBytes { - return Screenshot(image: image, attachment: .init(filename: "screenshot-\(index).jpg", contentType: "image/jpeg", data: jpeg)) - } - } - return nil - } - - private static func displayValue(_ value: IssueReportContextValue?) -> String { - switch value { - case .string(let string): return string - case .strings(let strings): return strings.isEmpty ? "–" : strings.joined(separator: ", ") - case nil: return "" - } - } - - private func send() { - isSending = true - Task { - var attachments = screenshots.map(\.attachment) - if includeDiagnosticReport, let generateDiagnosticReport { - let report = await generateDiagnosticReport() - // Stay under the server's per-file limit; decoding repairs a character cut in half - let text = String(decoding: report.utf8.prefix(Self.maxAttachmentBytes - 4), as: UTF8.self) - attachments.append(.init(filename: "diagnostic-report.txt", contentType: "text/plain; charset=utf-8", data: Data(text.utf8))) - } - let report = IssueReport( - title: title.isEmpty ? nil : String(title.prefix(200)), - description: trimmedDescription, - contact: isAnonymous ? nil : Self.trimmed(contact), - context: context, - attachments: attachments - ) - do { - sentReportID = try await IssueReportSubmitter().submit(report) - } catch let error as IssueReportSubmitterError { - sendError = error - showingError = true - } catch { - sendError = .network(error) - showingError = true - } - isSending = false - } - } - - private static func trimmed(_ contact: IssueReport.Contact) -> IssueReport.Contact? { - func clean(_ value: String?) -> String? { - let value = value?.trimmingCharacters(in: .whitespacesAndNewlines) ?? "" - return value.isEmpty ? nil : value - } - let result = IssueReport.Contact(name: clean(contact.name), email: clean(contact.email), zulip: clean(contact.zulip), github: clean(contact.github)) - return [result.name, result.email, result.zulip, result.github].allSatisfy({ $0 == nil }) ? nil : result - } -} diff --git a/Loop/Views/SettingsView.swift b/Loop/Views/SettingsView.swift index b0f2567f18..9f9e3aa069 100644 --- a/Loop/Views/SettingsView.swift +++ b/Loop/Views/SettingsView.swift @@ -457,21 +457,9 @@ extension SettingsView { private var supportSection: some View { Section(header: SectionHeader(label: NSLocalizedString("Support", comment: "The title of the support section in settings"))) { - NavigationLink(destination: SendIssueReportView( - context: viewModel.issueReportContext, - generateDiagnosticReport: viewModel.generateDiagnosticReport, - exportLocally: viewModel.didTapIssueReport - )) { - Text(NSLocalizedString("Report Issue", comment: "The title text for the issue report menu item")) - } - ForEach(pluginMenuItems.filter( { $0.section == .support })) { $0.view } - - NavigationLink(destination: CriticalEventLogExportView(viewModel: viewModel.criticalEventLogExportViewModel)) { - Text(NSLocalizedString("Export Critical Event Logs", comment: "The title of the export critical event logs in support")) - } } }