feat(ui): make ngrok URL clickable with copy button in Dashboard (#422)

Co-authored-by: Gopi Kori <gopi@bruviti.com>
This commit is contained in:
Gopi 2025-07-20 02:49:04 -07:00 committed by GitHub
parent 12e6c6d61c
commit 4bc2cdd653
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -441,10 +441,20 @@ private struct RemoteAccessStatusSection: View {
.font(.system(size: 10))
Text("ngrok")
.font(.callout)
Text("(\(status.publicUrl.replacingOccurrences(of: "https://", with: "")))")
.font(.caption)
.foregroundColor(.secondary)
.lineLimit(1)
if let url = URL(string: status.publicUrl) {
Link(status.publicUrl, destination: url)
.font(.caption)
.foregroundStyle(.blue)
.lineLimit(1)
} else {
Text(status.publicUrl)
.font(.caption)
.foregroundColor(.secondary)
.lineLimit(1)
}
NgrokURLCopyButton(url: status.publicUrl)
} else {
Image(systemName: "circle")
.foregroundColor(.gray)
@ -495,6 +505,43 @@ private struct RemoteAccessStatusSection: View {
}
}
// MARK: - Ngrok URL Copy Button
private struct NgrokURLCopyButton: View {
let url: String
@State private var showCopiedFeedback = false
@State private var feedbackTask: DispatchWorkItem?
var body: some View {
Button(action: {
NSPasteboard.general.clearContents()
NSPasteboard.general.setString(url, forType: .string)
// Cancel previous timer if exists
feedbackTask?.cancel()
withAnimation {
showCopiedFeedback = true
}
// Create new timer
let task = DispatchWorkItem {
withAnimation {
showCopiedFeedback = false
}
}
feedbackTask = task
DispatchQueue.main.asyncAfter(deadline: .now() + 2, execute: task)
}, label: {
Image(systemName: showCopiedFeedback ? "checkmark" : "doc.on.doc")
.foregroundColor(showCopiedFeedback ? .green : .accentColor)
})
.buttonStyle(.borderless)
.help("Copy URL")
.font(.caption)
}
}
// MARK: - Previews
#Preview("Dashboard Settings") {