Skip to content
Draft
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
20 changes: 20 additions & 0 deletions Sources/Pesty/AppController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ final class AppController: NSObject, NSApplicationDelegate {
private var settingsWindow: NSWindow?
private var pasteStackController: PasteStackWindowController?
private var keyMonitor: Any?
private var sharingPicker: NSSharingServicePicker?
private let copyToast = CopyToastController()

private(set) var previousApp: NSRunningApplication?
Expand Down Expand Up @@ -250,6 +251,25 @@ final class AppController: NSObject, NSApplicationDelegate {
copyToast.show()
}

func shareItem(_ item: ClipItem) {
let picker = NSSharingServicePicker(items: sharingItems(for: item))
sharingPicker = picker
guard let view = barController?.window?.contentView ?? NSApp.keyWindow?.contentView else { return }
let anchor = NSRect(x: view.bounds.midX, y: view.bounds.midY, width: 1, height: 1)
picker.show(relativeTo: anchor, of: view, preferredEdge: .maxY)
}

private func sharingItems(for item: ClipItem) -> [Any] {
if item.type == .image, let image = store.loadImage(for: item) {
return [image]
}
if item.type == .file {
let urls = item.fileURLs.compactMap(URL.init(string:)).filter(\.isFileURL)
if !urls.isEmpty { return urls }
}
return [item.text ?? item.colorHex ?? item.displayTitle]
}

func commandCopy() {
if store.source == .pasteStack, let entry = pasteSequence.selectedEntry {
copyItem(entry.item)
Expand Down
3 changes: 3 additions & 0 deletions Sources/Pesty/UI/ClipCardView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ struct ClipCardView: View {
}
}
Divider()
Button { AppController.shared.shareItem(item) } label: {
Label("Share", systemImage: "square.and.arrow.up")
}
Button("Delete", role: .destructive) { store.delete(item) }
}
}
Expand Down