diff --git a/Gaze/Animations/look-away.json b/Gaze/Animations/look-away.json index b10467b..17937a6 100644 --- a/Gaze/Animations/look-away.json +++ b/Gaze/Animations/look-away.json @@ -2,7 +2,7 @@ "v": "5.7.4", "fr": 30, "ip": 0, - "op": 120, + "op": 150, "w": 200, "h": 200, "nm": "Look Away Animation", @@ -55,7 +55,7 @@ } ], "ip": 0, - "op": 120, + "op": 150, "st": 0, "bm": 0 }, @@ -97,13 +97,13 @@ "p": { "a": 1, "k": [ - {"t": 0, "s": [0, 0], "h": 1}, - {"t": 20, "s": [-15, 0], "h": 1}, - {"t": 40, "s": [0, 0], "h": 1}, - {"t": 60, "s": [15, 0], "h": 1}, - {"t": 80, "s": [0, 0], "h": 1}, - {"t": 100, "s": [0, -10], "h": 1}, - {"t": 120, "s": [0, 0], "h": 1} + {"t": 0, "s": [0, 0], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}}, + {"t": 25, "s": [-25, 0], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}}, + {"t": 50, "s": [0, 0], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}}, + {"t": 75, "s": [25, 0], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}}, + {"t": 100, "s": [0, 0], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}}, + {"t": 125, "s": [0, -15], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}}, + {"t": 150, "s": [0, 0]} ] }, "a": {"a": 0, "k": [0, 0]}, @@ -135,13 +135,13 @@ "p": { "a": 1, "k": [ - {"t": 0, "s": [0, 0], "h": 1}, - {"t": 20, "s": [-15, 0], "h": 1}, - {"t": 40, "s": [0, 0], "h": 1}, - {"t": 60, "s": [15, 0], "h": 1}, - {"t": 80, "s": [0, 0], "h": 1}, - {"t": 100, "s": [0, -10], "h": 1}, - {"t": 120, "s": [0, 0], "h": 1} + {"t": 0, "s": [0, 0], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}}, + {"t": 25, "s": [-25, 0], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}}, + {"t": 50, "s": [0, 0], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}}, + {"t": 75, "s": [25, 0], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}}, + {"t": 100, "s": [0, 0], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}}, + {"t": 125, "s": [0, -15], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}}, + {"t": 150, "s": [0, 0]} ] }, "a": {"a": 0, "k": [0, 0]}, @@ -154,7 +154,7 @@ } ], "ip": 0, - "op": 120, + "op": 150, "st": 0, "bm": 0 }, @@ -196,13 +196,13 @@ "p": { "a": 1, "k": [ - {"t": 0, "s": [0, 0], "h": 1}, - {"t": 20, "s": [-15, 0], "h": 1}, - {"t": 40, "s": [0, 0], "h": 1}, - {"t": 60, "s": [15, 0], "h": 1}, - {"t": 80, "s": [0, 0], "h": 1}, - {"t": 100, "s": [0, -10], "h": 1}, - {"t": 120, "s": [0, 0], "h": 1} + {"t": 0, "s": [0, 0], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}}, + {"t": 25, "s": [-25, 0], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}}, + {"t": 50, "s": [0, 0], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}}, + {"t": 75, "s": [25, 0], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}}, + {"t": 100, "s": [0, 0], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}}, + {"t": 125, "s": [0, -15], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}}, + {"t": 150, "s": [0, 0]} ] }, "a": {"a": 0, "k": [0, 0]}, @@ -234,13 +234,13 @@ "p": { "a": 1, "k": [ - {"t": 0, "s": [0, 0], "h": 1}, - {"t": 20, "s": [-15, 0], "h": 1}, - {"t": 40, "s": [0, 0], "h": 1}, - {"t": 60, "s": [15, 0], "h": 1}, - {"t": 80, "s": [0, 0], "h": 1}, - {"t": 100, "s": [0, -10], "h": 1}, - {"t": 120, "s": [0, 0], "h": 1} + {"t": 0, "s": [0, 0], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}}, + {"t": 25, "s": [-25, 0], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}}, + {"t": 50, "s": [0, 0], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}}, + {"t": 75, "s": [25, 0], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}}, + {"t": 100, "s": [0, 0], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}}, + {"t": 125, "s": [0, -15], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}}, + {"t": 150, "s": [0, 0]} ] }, "a": {"a": 0, "k": [0, 0]}, @@ -253,64 +253,7 @@ } ], "ip": 0, - "op": 120, - "st": 0, - "bm": 0 - }, - { - "ddd": 0, - "ind": 4, - "ty": 4, - "nm": "Smile", - "sr": 1, - "ks": { - "o": {"a": 0, "k": 100}, - "r": {"a": 0, "k": 0}, - "p": {"a": 0, "k": [100, 120, 0]}, - "a": {"a": 0, "k": [0, 0, 0]}, - "s": {"a": 0, "k": [100, 100, 100]} - }, - "ao": 0, - "shapes": [ - { - "ty": "gr", - "it": [ - { - "ty": "sh", - "ks": { - "a": 0, - "k": { - "i": [[0, 0], [-20, 10], [20, 10]], - "o": [[20, 10], [20, -10], [0, 0]], - "v": [[-30, 0], [0, 15], [30, 0]], - "c": false - } - }, - "nm": "Smile Path" - }, - { - "ty": "st", - "c": {"a": 0, "k": [0, 0.478, 1, 1]}, - "o": {"a": 0, "k": 100}, - "w": {"a": 0, "k": 4}, - "lc": 2, - "lj": 2, - "nm": "Stroke" - }, - { - "ty": "tr", - "p": {"a": 0, "k": [0, 0]}, - "a": {"a": 0, "k": [0, 0]}, - "s": {"a": 0, "k": [100, 100]}, - "r": {"a": 0, "k": 0}, - "o": {"a": 0, "k": 100} - } - ], - "nm": "Smile" - } - ], - "ip": 0, - "op": 120, + "op": 150, "st": 0, "bm": 0 } diff --git a/Gaze/Views/Reminders/LookAwayReminderView.swift b/Gaze/Views/Reminders/LookAwayReminderView.swift index 59a57c9..d193b43 100644 --- a/Gaze/Views/Reminders/LookAwayReminderView.swift +++ b/Gaze/Views/Reminders/LookAwayReminderView.swift @@ -7,6 +7,7 @@ import SwiftUI import Lottie +import AppKit struct LookAwayReminderView: View { let countdownSeconds: Int @@ -14,6 +15,7 @@ struct LookAwayReminderView: View { @State private var remainingSeconds: Int @State private var timer: Timer? + @State private var keyMonitor: Any? init(countdownSeconds: Int, onDismiss: @escaping () -> Void) { self.countdownSeconds = countdownSeconds @@ -85,17 +87,11 @@ struct LookAwayReminderView: View { } .onAppear { startCountdown() + setupKeyMonitor() } .onDisappear { timer?.invalidate() - } - .onKeyPress(.escape) { - dismiss() - return .handled - } - .onKeyPress(.space) { - dismiss() - return .handled + removeKeyMonitor() } } @@ -117,6 +113,26 @@ struct LookAwayReminderView: View { timer?.invalidate() onDismiss() } + + private func setupKeyMonitor() { + keyMonitor = NSEvent.addLocalMonitorForEvents(matching: .keyDown) { event in + if event.keyCode == 53 { // ESC key + dismiss() + return nil + } else if event.keyCode == 49 { // Space key + dismiss() + return nil + } + return event + } + } + + private func removeKeyMonitor() { + if let monitor = keyMonitor { + NSEvent.removeMonitor(monitor) + keyMonitor = nil + } + } } #Preview("Look Away Reminder") {