fix: keyboard response in lookaway overlay
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
"v": "5.7.4",
|
"v": "5.7.4",
|
||||||
"fr": 30,
|
"fr": 30,
|
||||||
"ip": 0,
|
"ip": 0,
|
||||||
"op": 120,
|
"op": 150,
|
||||||
"w": 200,
|
"w": 200,
|
||||||
"h": 200,
|
"h": 200,
|
||||||
"nm": "Look Away Animation",
|
"nm": "Look Away Animation",
|
||||||
@@ -55,7 +55,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"ip": 0,
|
"ip": 0,
|
||||||
"op": 120,
|
"op": 150,
|
||||||
"st": 0,
|
"st": 0,
|
||||||
"bm": 0
|
"bm": 0
|
||||||
},
|
},
|
||||||
@@ -97,13 +97,13 @@
|
|||||||
"p": {
|
"p": {
|
||||||
"a": 1,
|
"a": 1,
|
||||||
"k": [
|
"k": [
|
||||||
{"t": 0, "s": [0, 0], "h": 1},
|
{"t": 0, "s": [0, 0], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}},
|
||||||
{"t": 20, "s": [-15, 0], "h": 1},
|
{"t": 25, "s": [-25, 0], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}},
|
||||||
{"t": 40, "s": [0, 0], "h": 1},
|
{"t": 50, "s": [0, 0], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}},
|
||||||
{"t": 60, "s": [15, 0], "h": 1},
|
{"t": 75, "s": [25, 0], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}},
|
||||||
{"t": 80, "s": [0, 0], "h": 1},
|
{"t": 100, "s": [0, 0], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}},
|
||||||
{"t": 100, "s": [0, -10], "h": 1},
|
{"t": 125, "s": [0, -15], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}},
|
||||||
{"t": 120, "s": [0, 0], "h": 1}
|
{"t": 150, "s": [0, 0]}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"a": {"a": 0, "k": [0, 0]},
|
"a": {"a": 0, "k": [0, 0]},
|
||||||
@@ -135,13 +135,13 @@
|
|||||||
"p": {
|
"p": {
|
||||||
"a": 1,
|
"a": 1,
|
||||||
"k": [
|
"k": [
|
||||||
{"t": 0, "s": [0, 0], "h": 1},
|
{"t": 0, "s": [0, 0], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}},
|
||||||
{"t": 20, "s": [-15, 0], "h": 1},
|
{"t": 25, "s": [-25, 0], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}},
|
||||||
{"t": 40, "s": [0, 0], "h": 1},
|
{"t": 50, "s": [0, 0], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}},
|
||||||
{"t": 60, "s": [15, 0], "h": 1},
|
{"t": 75, "s": [25, 0], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}},
|
||||||
{"t": 80, "s": [0, 0], "h": 1},
|
{"t": 100, "s": [0, 0], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}},
|
||||||
{"t": 100, "s": [0, -10], "h": 1},
|
{"t": 125, "s": [0, -15], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}},
|
||||||
{"t": 120, "s": [0, 0], "h": 1}
|
{"t": 150, "s": [0, 0]}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"a": {"a": 0, "k": [0, 0]},
|
"a": {"a": 0, "k": [0, 0]},
|
||||||
@@ -154,7 +154,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"ip": 0,
|
"ip": 0,
|
||||||
"op": 120,
|
"op": 150,
|
||||||
"st": 0,
|
"st": 0,
|
||||||
"bm": 0
|
"bm": 0
|
||||||
},
|
},
|
||||||
@@ -196,13 +196,13 @@
|
|||||||
"p": {
|
"p": {
|
||||||
"a": 1,
|
"a": 1,
|
||||||
"k": [
|
"k": [
|
||||||
{"t": 0, "s": [0, 0], "h": 1},
|
{"t": 0, "s": [0, 0], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}},
|
||||||
{"t": 20, "s": [-15, 0], "h": 1},
|
{"t": 25, "s": [-25, 0], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}},
|
||||||
{"t": 40, "s": [0, 0], "h": 1},
|
{"t": 50, "s": [0, 0], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}},
|
||||||
{"t": 60, "s": [15, 0], "h": 1},
|
{"t": 75, "s": [25, 0], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}},
|
||||||
{"t": 80, "s": [0, 0], "h": 1},
|
{"t": 100, "s": [0, 0], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}},
|
||||||
{"t": 100, "s": [0, -10], "h": 1},
|
{"t": 125, "s": [0, -15], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}},
|
||||||
{"t": 120, "s": [0, 0], "h": 1}
|
{"t": 150, "s": [0, 0]}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"a": {"a": 0, "k": [0, 0]},
|
"a": {"a": 0, "k": [0, 0]},
|
||||||
@@ -234,13 +234,13 @@
|
|||||||
"p": {
|
"p": {
|
||||||
"a": 1,
|
"a": 1,
|
||||||
"k": [
|
"k": [
|
||||||
{"t": 0, "s": [0, 0], "h": 1},
|
{"t": 0, "s": [0, 0], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}},
|
||||||
{"t": 20, "s": [-15, 0], "h": 1},
|
{"t": 25, "s": [-25, 0], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}},
|
||||||
{"t": 40, "s": [0, 0], "h": 1},
|
{"t": 50, "s": [0, 0], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}},
|
||||||
{"t": 60, "s": [15, 0], "h": 1},
|
{"t": 75, "s": [25, 0], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}},
|
||||||
{"t": 80, "s": [0, 0], "h": 1},
|
{"t": 100, "s": [0, 0], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}},
|
||||||
{"t": 100, "s": [0, -10], "h": 1},
|
{"t": 125, "s": [0, -15], "i": {"x": 0.4, "y": 1}, "o": {"x": 0.6, "y": 0}},
|
||||||
{"t": 120, "s": [0, 0], "h": 1}
|
{"t": 150, "s": [0, 0]}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"a": {"a": 0, "k": [0, 0]},
|
"a": {"a": 0, "k": [0, 0]},
|
||||||
@@ -253,64 +253,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"ip": 0,
|
"ip": 0,
|
||||||
"op": 120,
|
"op": 150,
|
||||||
"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,
|
|
||||||
"st": 0,
|
"st": 0,
|
||||||
"bm": 0
|
"bm": 0
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
import Lottie
|
import Lottie
|
||||||
|
import AppKit
|
||||||
|
|
||||||
struct LookAwayReminderView: View {
|
struct LookAwayReminderView: View {
|
||||||
let countdownSeconds: Int
|
let countdownSeconds: Int
|
||||||
@@ -14,6 +15,7 @@ struct LookAwayReminderView: View {
|
|||||||
|
|
||||||
@State private var remainingSeconds: Int
|
@State private var remainingSeconds: Int
|
||||||
@State private var timer: Timer?
|
@State private var timer: Timer?
|
||||||
|
@State private var keyMonitor: Any?
|
||||||
|
|
||||||
init(countdownSeconds: Int, onDismiss: @escaping () -> Void) {
|
init(countdownSeconds: Int, onDismiss: @escaping () -> Void) {
|
||||||
self.countdownSeconds = countdownSeconds
|
self.countdownSeconds = countdownSeconds
|
||||||
@@ -85,17 +87,11 @@ struct LookAwayReminderView: View {
|
|||||||
}
|
}
|
||||||
.onAppear {
|
.onAppear {
|
||||||
startCountdown()
|
startCountdown()
|
||||||
|
setupKeyMonitor()
|
||||||
}
|
}
|
||||||
.onDisappear {
|
.onDisappear {
|
||||||
timer?.invalidate()
|
timer?.invalidate()
|
||||||
}
|
removeKeyMonitor()
|
||||||
.onKeyPress(.escape) {
|
|
||||||
dismiss()
|
|
||||||
return .handled
|
|
||||||
}
|
|
||||||
.onKeyPress(.space) {
|
|
||||||
dismiss()
|
|
||||||
return .handled
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,6 +113,26 @@ struct LookAwayReminderView: View {
|
|||||||
timer?.invalidate()
|
timer?.invalidate()
|
||||||
onDismiss()
|
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") {
|
#Preview("Look Away Reminder") {
|
||||||
|
|||||||
Reference in New Issue
Block a user