From df619d540b1ae3736120a1ed8689243bc0194a00 Mon Sep 17 00:00:00 2001 From: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com> Date: Tue, 12 Mar 2024 19:06:25 +0400 Subject: [PATCH] ios: save debug profile, event log buttons (#3899) --- apps/ios/Shared/SimpleXApp.swift | 2 +- .../Views/UserSettings/DeveloperView.swift | 23 +++++++++++++++++++ apps/ios/SimpleXChat/FileUtils.swift | 8 +++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/apps/ios/Shared/SimpleXApp.swift b/apps/ios/Shared/SimpleXApp.swift index 7d69466c07..cd347cf469 100644 --- a/apps/ios/Shared/SimpleXApp.swift +++ b/apps/ios/Shared/SimpleXApp.swift @@ -22,7 +22,7 @@ struct SimpleXApp: App { init() { DispatchQueue.global(qos: .background).sync { - haskell_init() + haskell_init(getAppEventLogPath().path, getAppDebugProfilePath().path) // hs_init(0, nil) } UserDefaults.standard.register(defaults: appDefaults) diff --git a/apps/ios/Shared/Views/UserSettings/DeveloperView.swift b/apps/ios/Shared/Views/UserSettings/DeveloperView.swift index 9b11c6d0f7..6337da6851 100644 --- a/apps/ios/Shared/Views/UserSettings/DeveloperView.swift +++ b/apps/ios/Shared/Views/UserSettings/DeveloperView.swift @@ -45,6 +45,11 @@ struct DeveloperView: View { } if developerTools { + Section { + exportDebugProfileButton() + exportEventLogButton() + } + Section { settingsRow("key") { Toggle("Post-quantum E2EE", isOn: $pqExperimentalEnabled) @@ -62,6 +67,24 @@ struct DeveloperView: View { } } + @ViewBuilder private func exportDebugProfileButton() -> some View { + let url = getAppDebugProfilePath() + settingsRow("square.and.arrow.up") { + Button("Export debugging profile") { + showShareSheet(items: [url]) + } + }.disabled(!FileManager.default.fileExists(atPath: url.path)) + } + + @ViewBuilder private func exportEventLogButton() -> some View { + let url = getAppEventLogPath() + settingsRow("square.and.arrow.up") { + Button("Export event log") { + showShareSheet(items: [url]) + } + }.disabled(!FileManager.default.fileExists(atPath: url.path)) + } + private func setPQExperimentalEnabled(_ enable: Bool) { do { try apiSetPQEncryption(enable) diff --git a/apps/ios/SimpleXChat/FileUtils.swift b/apps/ios/SimpleXChat/FileUtils.swift index 125600f3f3..0452be6926 100644 --- a/apps/ios/SimpleXChat/FileUtils.swift +++ b/apps/ios/SimpleXChat/FileUtils.swift @@ -192,6 +192,14 @@ public func getAppFilesDirectory() -> URL { getAppDirectory().appendingPathComponent("app_files", isDirectory: true) } +public func getAppDebugProfilePath() -> URL { + getAppDirectory().appendingPathComponent("simplex_debug_profile", isDirectory: false) +} + +public func getAppEventLogPath() -> URL { + getAppDirectory().appendingPathComponent("simplex_event_log", isDirectory: false) +} + public func getAppFilePath(_ fileName: String) -> URL { getAppFilesDirectory().appendingPathComponent(fileName) }