fix: fix keyboard input detection bug on look away reminder

This commit is contained in:
Michael Freno
2026-01-10 10:18:41 -05:00
parent cb689a4cbc
commit 4aa1d29c65
4 changed files with 18 additions and 7 deletions

View File

@@ -161,7 +161,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
private func showReminderWindow(_ content: AnyView) { private func showReminderWindow(_ content: AnyView) {
guard let screen = NSScreen.main else { return } guard let screen = NSScreen.main else { return }
let window = NSWindow( let window = KeyableWindow(
contentRect: screen.frame, contentRect: screen.frame,
styleMask: [.borderless, .fullSizeContentView], styleMask: [.borderless, .fullSizeContentView],
backing: .buffered, backing: .buffered,
@@ -181,6 +181,7 @@ private func showReminderWindow(_ content: AnyView) {
windowController.showWindow(nil) windowController.showWindow(nil)
// Make sure the window is brought to front and made key for key events // Make sure the window is brought to front and made key for key events
window.makeKeyAndOrderFront(nil) window.makeKeyAndOrderFront(nil)
NSApp.activate(ignoringOtherApps: true)
reminderWindowController = windowController reminderWindowController = windowController
} }
@@ -272,4 +273,15 @@ private func showReminderWindow(_ content: AnyView) {
self?.settingsWindowController = nil self?.settingsWindowController = nil
} }
} }
}
// Custom window class that can become key to receive keyboard events
class KeyableWindow: NSWindow {
override var canBecomeKey: Bool {
return true
}
override var canBecomeMain: Bool {
return true
}
} }

View File

@@ -59,7 +59,7 @@ struct AppSettings: Codable, Equatable, Hashable {
postureTimer: TimerConfiguration = TimerConfiguration( postureTimer: TimerConfiguration = TimerConfiguration(
enabled: true, intervalSeconds: 30 * 60), enabled: true, intervalSeconds: 30 * 60),
userTimers: [UserTimer] = [], userTimers: [UserTimer] = [],
subtleReminderSize: ReminderSize = .large, subtleReminderSize: ReminderSize = .medium,
hasCompletedOnboarding: Bool = false, hasCompletedOnboarding: Bool = false,
launchAtLogin: Bool = false, launchAtLogin: Bool = false,
playSounds: Bool = true playSounds: Bool = true
@@ -82,7 +82,7 @@ struct AppSettings: Codable, Equatable, Hashable {
blinkTimer: TimerConfiguration(enabled: false, intervalSeconds: 7 * 60), blinkTimer: TimerConfiguration(enabled: false, intervalSeconds: 7 * 60),
postureTimer: TimerConfiguration(enabled: true, intervalSeconds: 30 * 60), postureTimer: TimerConfiguration(enabled: true, intervalSeconds: 30 * 60),
userTimers: [], userTimers: [],
subtleReminderSize: .large, subtleReminderSize: .medium,
hasCompletedOnboarding: false, hasCompletedOnboarding: false,
launchAtLogin: false, launchAtLogin: false,
playSounds: true playSounds: true

View File

@@ -30,7 +30,7 @@ struct OnboardingContainerView: View {
@State private var postureEnabled = true @State private var postureEnabled = true
@State private var postureIntervalMinutes = 30 @State private var postureIntervalMinutes = 30
@State private var launchAtLogin = false @State private var launchAtLogin = false
@State private var subtleReminderSize: ReminderSize = .large @State private var subtleReminderSize: ReminderSize = .medium
@State private var isAnimatingOut = false @State private var isAnimatingOut = false
@Environment(\.dismiss) private var dismiss @Environment(\.dismiss) private var dismiss

View File

@@ -51,7 +51,6 @@ struct SettingsOnboardingView: View {
.padding() .padding()
.glassEffect(.regular, in: .rect(cornerRadius: 12)) .glassEffect(.regular, in: .rect(cornerRadius: 12))
// Subtle Reminder Size Configuration
VStack(alignment: .leading, spacing: 12) { VStack(alignment: .leading, spacing: 12) {
Text("Subtle Reminder Size") Text("Subtle Reminder Size")
.font(.headline) .font(.headline)
@@ -134,7 +133,7 @@ struct SettingsOnboardingView: View {
if !AppStoreDetector.isAppStoreVersion { if !AppStoreDetector.isAppStoreVersion {
Button(action: { Button(action: {
if let url = URL(string: "https://buymeacoffee.com/placeholder") { if let url = URL(string: "https://buymeacoffee.com/mikefreno") {
NSWorkspace.shared.open(url) NSWorkspace.shared.open(url)
} }
}) { }) {
@@ -198,7 +197,7 @@ struct SettingsOnboardingView: View {
#Preview("Settings Onboarding - Launch Disabled") { #Preview("Settings Onboarding - Launch Disabled") {
SettingsOnboardingView( SettingsOnboardingView(
launchAtLogin: .constant(false), launchAtLogin: .constant(false),
subtleReminderSize: .constant(.large), subtleReminderSize: .constant(.medium),
isOnboarding: true isOnboarding: true
) )
} }