From 10270b02ee3a4963e9cbef9aff779890a14950e0 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Sat, 27 Aug 2022 22:16:41 +0200 Subject: [PATCH] On Mac, copy debug log to pasteboard, do not share UIActivityViewController is lame. --- Passepartout/App/Constants/Theme.swift | 4 +++ Passepartout/App/Views/DebugLogView.swift | 34 +++++++++++++++++++---- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/Passepartout/App/Constants/Theme.swift b/Passepartout/App/Constants/Theme.swift index 3088b0ec..0b2cc805 100644 --- a/Passepartout/App/Constants/Theme.swift +++ b/Passepartout/App/Constants/Theme.swift @@ -168,6 +168,10 @@ extension View { var themeShareImage: String { "square.and.arrow.up" } + + var themeCopyImage: String { + "doc.on.doc" + } var themeCloseImage: String { "xmark" diff --git a/Passepartout/App/Views/DebugLogView.swift b/Passepartout/App/Views/DebugLogView.swift index ecda6acb..3eda357e 100644 --- a/Passepartout/App/Views/DebugLogView.swift +++ b/Passepartout/App/Views/DebugLogView.swift @@ -58,7 +58,15 @@ struct DebugLogView: View { }.onAppear { refreshLog(scrollingToLatestWith: scrollProxy) } - }.toolbar { + } + #if targetEnvironment(macCatalyst) + .toolbar { + Button(action: copyDebugLog) { + themeCopyImage.asSystemImage + }.disabled(logLines.isEmpty) + } + #else + .toolbar { if !isSharing { Button(action: shareDebugLog) { themeShareImage.asSystemImage @@ -67,6 +75,7 @@ struct DebugLogView: View { ProgressView() } }.sheet(isPresented: $isSharing, content: sharingActivityView) + #endif .edgesIgnoringSafeArea([.leading, .trailing]) .onReceive(timer, perform: refreshLog) .navigationTitle(L10n.DebugLog.title) @@ -93,7 +102,9 @@ struct DebugLogView: View { private func refreshLog(_: Date) { refreshLog(scrollingToLatestWith: nil) } +} +extension DebugLogView { private func shareDebugLog() { guard !logLines.isEmpty else { assertionFailure("Log is empty, why could it share?") @@ -101,16 +112,15 @@ struct DebugLogView: View { } isSharing = true } -} - -extension DebugLogView { + private func sharingActivityView() -> some View { ActivityView(activityItems: sharingItems) } private var sharingItems: [Any] { let raw = logLines.joined(separator: "\n") - let data = DebugLog(content: raw).decoratedData(appName, appVersion) + let data = DebugLog(content: raw) + .decoratedData(appName, appVersion) let path = NSTemporaryDirectory().appending(shareFilename) let url = URL(fileURLWithPath: path) @@ -125,6 +135,20 @@ extension DebugLogView { } } +extension DebugLogView { + private func copyDebugLog() { + guard !logLines.isEmpty else { + assertionFailure("Log is empty, why could it copy?") + return + } + let raw = logLines.joined(separator: "\n") + let content = DebugLog(content: raw) + .decoratedString(appName, appVersion) + + Utils.copyToPasteboard(content) + } +} + extension DebugLogView { private func scrollToLatestUpdate(_ proxy: ScrollViewProxy) { proxy.maybeScrollTo(logLines.count - 1, anchor: .bottomLeading)