Skip to content

Screenshots, hung out to dry. A tiny native macOS app that hangs every screenshot on a line at the top of your screen.

Swift

Put back asks for ⌘Z once while another app holds it

Alejandro Buján4ecf9e343cc0
diff --git a/Sources/Tendedero/AppDelegate.swift b/Sources/Tendedero/AppDelegate.swift
index 8c8861c..a9a4e01 100644
--- a/Sources/Tendedero/AppDelegate.swift
+++ b/Sources/Tendedero/AppDelegate.swift
@@ -621,10 +621,19 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
/// ⌘Z stays the undo of the app you are in.
private var putBackKey: HotKey?
+ /// Set when another app holds ⌘Z, so it is not asked for again on every
+ /// tick, only the next time the pointer comes to the line.
+ private var putBackKeyRefused = false
+
private func holdPutBackKey(_ hold: Bool) {
- let hold = hold && line.canPutBack
- guard hold != (putBackKey != nil) else { return }
- putBackKey = hold ? HotKey(Shortcut.putBack) { [weak self] in self?.putBack() } : nil
+ guard hold && line.canPutBack else {
+ putBackKey = nil
+ putBackKeyRefused = false
+ return
+ }
+ guard putBackKey == nil, !putBackKeyRefused else { return }
+ putBackKey = HotKey(Shortcut.putBack) { [weak self] in self?.putBack() }
+ putBackKeyRefused = putBackKey == nil
}
/// From the menu the line is usually up, so it comes down for a moment
diff --git a/Sources/Tendedero/Line.swift b/Sources/Tendedero/Line.swift
index 9f1d832..df12c86 100644
--- a/Sources/Tendedero/Line.swift
+++ b/Sources/Tendedero/Line.swift
@@ -262,9 +262,6 @@ final class Line: ObservableObject {
}
}
- /// The oldest photo falling off a full line. Like the cross, a file from
- /// Tendedero's folder goes to the Trash, or nothing would ever take it out
- /// of that folder. If the Trash refuses it, it still leaves the line.
/// Moves along a line that holds more than fit, from a scroll gesture.
func scroll(by delta: CGFloat) {
let most = CGFloat(max(0, items.count - visibleCount)) * Layout.spacing
@@ -281,6 +278,9 @@ final class Line: ObservableObject {
scroll = 0
}
+ /// The oldest photo falling off a full line. Like the cross, a file from
+ /// Tendedero's folder goes to the Trash, or nothing would ever take it out
+ /// of that folder. If the Trash refuses it, it still leaves the line.
private func letGo(_ id: UUID) {
if isInInbox(id), trash(id, quietly: true, step: nil) { return }
drop(id, quietly: true)