Skip to content

Commit

Permalink
fix shortcut key detections
Browse files Browse the repository at this point in the history
  • Loading branch information
erikng committed Feb 12, 2024
1 parent 4a5f06b commit 3070823
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions Nudge/UI/Main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,13 @@ class AppDelegate: NSObject, NSApplicationDelegate {
private func detectBannedShortcutKeys(with event: NSEvent) -> Bool {
guard NSApplication.shared.isActive else { return false }
switch event.modifierFlags.intersection(.deviceIndependentFlagsMask) {
// Disable CMD + W - closes the Nudge window and breaks it
case [.command] where event.charactersIgnoringModifiers == "w":
LogManager.warning("Nudge detected an attempt to close the application via CMD + W shortcut key.", logger: utilsLog)
// Disable CMD + H - Hides Nudge
case [.command] where event.charactersIgnoringModifiers == "h":
LogManager.warning("Nudge detected an attempt to hide the application via CMD + H shortcut key.", logger: utilsLog)
return true
// Disable CMD + M - Minimizes Nudge
case [.command] where event.charactersIgnoringModifiers == "m":
LogManager.warning("Nudge detected an attempt to minimize the application via CMD + M shortcut key.", logger: utilsLog)
return true
// Disable CMD + N - closes the Nudge window and breaks it
case [.command] where event.charactersIgnoringModifiers == "n":
Expand All @@ -303,26 +307,27 @@ class AppDelegate: NSObject, NSApplicationDelegate {
case [.command] where event.charactersIgnoringModifiers == "q":
LogManager.warning("Nudge detected an attempt to quit the application via CMD + Q shortcut key.", logger: utilsLog)
return true
// Disable CMD + M - Minimizes Nudge
case [.command] where event.charactersIgnoringModifiers == "m":
LogManager.warning("Nudge detected an attempt to minimize the application via CMD + M shortcut key.", logger: utilsLog)
return true
// Disable CMD + H - Hides Nudge
case [.command] where event.charactersIgnoringModifiers == "h":
LogManager.warning("Nudge detected an attempt to hide the application via CMD + H shortcut key.", logger: utilsLog)
return true
// Disable CMD + Option + Esc (Force Quit Applications)
case [.command, .option] where event.charactersIgnoringModifiers == "\u{1b}": // Escape key
LogManager.warning("Nudge detected an attempt to open Force Quit Applications via CMD + Option + Esc.", logger: utilsLog)
// Disable CMD + W - closes the Nudge window and breaks it
case [.command] where event.charactersIgnoringModifiers == "w":
LogManager.warning("Nudge detected an attempt to close the application via CMD + W shortcut key.", logger: utilsLog)
return true
// Disable CMD + Option + M - Minimizes Nudge
case [.command, .option] where event.charactersIgnoringModifiers == "µ":
case [.command, .option] where event.charactersIgnoringModifiers == "m":
LogManager.warning("Nudge detected an attempt to minimise the application via CMD + Option + M shortcut key.", logger: utilsLog)
return true
// Disable CMD + Option + N - Add tabs to Nudge window
case [.command, .option] where event.charactersIgnoringModifiers == "~":
case [.command, .option] where event.charactersIgnoringModifiers == "n":
LogManager.warning("Nudge detected an attempt to add tabs to the application via CMD + Option + N shortcut key.", logger: utilsLog)
return true
// Disable CMD + Option + W - Close Window
case [.command, .option] where event.charactersIgnoringModifiers == "w":
LogManager.warning("Nudge detected an attempt to add tabs to the application via CMD + Option + W shortcut key.", logger: utilsLog)
return true
// Disable CMD + Option + Esc (Force Quit Applications)
case [.command, .option] where event.charactersIgnoringModifiers == "\u{1b}": // Escape key
// This doesn't work since Apple allows that shortcut to bypass the application's memory.
LogManager.warning("Nudge detected an attempt to open Force Quit Applications via CMD + Option + Esc.", logger: utilsLog)
return true
default:
// Don't care about any other shortcut keys
return false
Expand Down

1 comment on commit 3070823

@bradtchapman
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested with latest pre-release build. Confirmed that the shortcut key detection works, and Nudge can no longer be manipulated with Opt-Cmd-W, -M, or -N.

Please sign in to comment.