Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ios/KeepMac/KeepMacApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ struct NoteCommands: Commands {

Divider()

Button("Copy Text") {
if let note { MacPasteboard.copy(note.body) }
}
.disabled(note == nil)

Button("Copy Share Link") {
if let note { Task { await store.copyShareLink(note) } }
}
Expand Down
1 change: 1 addition & 0 deletions ios/KeepMac/MacRootView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ struct MacRootView: View {
}
}
Divider()
Button("Copy Text") { MacPasteboard.copy(note.body) }
Button("Copy Share Link") { Task { await store.copyShareLink(note) } }
if note.shareToken != nil {
Button("Stop Sharing") { Task { await store.unshare(note) } }
Expand Down
14 changes: 10 additions & 4 deletions ios/KeepMac/ShareLink.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import AppKit

@MainActor
enum MacPasteboard {
static func copy(_ string: String) {
let pasteboard = NSPasteboard.general
pasteboard.clearContents()
pasteboard.setString(string, forType: .string)
}
}

/// Mac-side share helper: makes sure the public link exists, then puts it on
/// the pasteboard. Lives in the Mac target because of NSPasteboard.
extension NotesStore {
func copyShareLink(_ note: Note) async {
guard let token = (await share(note))?.shareToken else { return }
let url = Config.baseURL.appendingPathComponent("p/\(token)")
let pasteboard = NSPasteboard.general
pasteboard.clearContents()
pasteboard.setString(url.absoluteString, forType: .string)
MacPasteboard.copy(Config.baseURL.appendingPathComponent("p/\(token)").absoluteString)
}
}
Loading