mirror of
https://github.com/passepartoutvpn/passepartout-apple.git
synced 2025-01-18 22:49:10 +00:00
On Mac, copy debug log to pasteboard, do not share
UIActivityViewController is lame.
This commit is contained in:
parent
e29f0bbd83
commit
10270b02ee
@ -169,6 +169,10 @@ extension View {
|
||||
"square.and.arrow.up"
|
||||
}
|
||||
|
||||
var themeCopyImage: String {
|
||||
"doc.on.doc"
|
||||
}
|
||||
|
||||
var themeCloseImage: String {
|
||||
"xmark"
|
||||
}
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user