Screenshots, hung out to dry. A tiny native macOS app that hangs every screenshot on a line at the top of your screen.
Swift
Reduce screenshot memory usage during captures and copying (#21)
xkchokde32c27bd246
diff --git a/Sources/Tendedero/AppDelegate.swift b/Sources/Tendedero/AppDelegate.swiftindex ba0dc9b..800fa9c 100644--- a/Sources/Tendedero/AppDelegate.swift+++ b/Sources/Tendedero/AppDelegate.swift@@ -230,14 +230,16 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {}private func fly(_ id: UUID, from: CGRect) {- guard isPresent, isRevealed, let screen = panel.screen,+ guard isPresent, isRevealed, CaptureFlight.flightsInProgress < 2, let screen = panel.screen,let to = cardFrame(for: id),let item = line.items.first(where: { $0.id == id }) else {line.land(id)return}+ // Sharp enough while it starts out at the captured size, which a+ // full Retina screen would otherwise take at full resolution.let pixels = Int(max(from.width, from.height) * screen.backingScaleFactor)- guard let image = makeThumbnail(item.url, maxPixels: min(3000, max(400, pixels)))?+ guard let image = makeThumbnail(item.url, maxPixels: min(1500, max(400, pixels)))?.cgImage(forProposedRect: nil, context: nil, hints: nil) else {line.land(id)returndiff --git a/Sources/Tendedero/CaptureFlight.swift b/Sources/Tendedero/CaptureFlight.swiftindex 0916730..318ff0c 100644--- a/Sources/Tendedero/CaptureFlight.swift+++ b/Sources/Tendedero/CaptureFlight.swift@@ -51,6 +51,10 @@ final class CaptureFlight {private static var current: [CaptureFlight] = []+ /// Captures flying to the line right now. Each one holds a large image,+ /// so in a burst of captures only a couple fly and the rest drop in.+ static var flightsInProgress: Int { current.filter { !$0.falling }.count }+/// - Parameters:/// - from: the captured area, in screen coordinates./// - to: the card's frame on the line, in screen coordinates, unrotated.diff --git a/Sources/Tendedero/Line.swift b/Sources/Tendedero/Line.swiftindex 4b7ce87..ea532f9 100644--- a/Sources/Tendedero/Line.swift+++ b/Sources/Tendedero/Line.swift@@ -283,7 +283,9 @@ func isRecording(_ url: URL) -> Bool {["mov", "mp4"].contains(url.pathExtension.lowercased())}-func makeThumbnail(_ url: URL, maxPixels: Int = 480) -> NSImage? {+/// The default size covers a card at twice its size in points, as on a+/// Retina screen, and no more: every photo on the line keeps one in memory.+func makeThumbnail(_ url: URL, maxPixels: Int = 320) -> NSImage? {if isRecording(url) { return firstFrame(url, maxPixels: maxPixels) }guard let source = CGImageSourceCreateWithURL(url as CFURL, nil) else { return nil }let options: [CFString: Any] = [