Skip to content

Commit

Permalink
added shortcut ability to toggle notch open
Browse files Browse the repository at this point in the history
  • Loading branch information
freepicheep authored and theboringhumane committed Nov 13, 2024
1 parent 0890fbe commit 3a90344
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions boringNotch/Shortcuts/ShortcutConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ extension KeyboardShortcuts.Name {
static let decreaseBacklight = Self("decreaseBacklight", default: .init(.f1, modifiers: [.command]))
static let increaseBacklight = Self("increaseBacklight", default: .init(.f2, modifiers: [.command]))
static let toggleSneakPeek = Self("toggleSneakPeek", default: .init(.h, modifiers: [.command, .shift]))
static let toggleNotchOpen = Self("toggleNotchOpen", default: .init(.i, modifiers: [.command, .shift]))
}
21 changes: 21 additions & 0 deletions boringNotch/boringNotchApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
var whatsNewWindow: NSWindow?
var timer: Timer?
let calenderManager = CalendarManager()
var closeNotchWorkItem: DispatchWorkItem?
private var previousScreens: [NSScreen]?
@Environment(\.openWindow) var openWindow

Expand Down Expand Up @@ -126,6 +127,26 @@ class AppDelegate: NSObject, NSApplicationDelegate {
)
}

KeyboardShortcuts.onKeyDown(for: .toggleNotchOpen) { [weak self] in
guard let self = self else { return }
switch self.vm.notchState {
case .closed:
self.vm.open()
self.closeNotchWorkItem?.cancel()

let workItem = DispatchWorkItem {
self.vm.close()
}
self.closeNotchWorkItem = workItem

DispatchQueue.main.asyncAfter(deadline: .now() + 3.0, execute: workItem)
case .open:
self.closeNotchWorkItem?.cancel()
self.closeNotchWorkItem = nil
self.vm.close()
}
}

window = BoringNotchWindow(
contentRect: NSRect(x: 0, y: 0, width: sizing.size.opened.width! + 20, height: sizing.size.opened.height! + 30),
styleMask: [.borderless, .nonactivatingPanel, .utilityWindow, .hudWindow],
Expand Down
3 changes: 3 additions & 0 deletions boringNotch/components/Settings/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,9 @@ struct Shortcuts: View {
.foregroundStyle(.secondary)
.font(.caption)
}
Section {
KeyboardShortcuts.Recorder("Toggle Notch Open:", name: .toggleNotchOpen)
}
}
.tint(Defaults[.accentColor])
.navigationTitle("Shortcuts")
Expand Down

0 comments on commit 3a90344

Please sign in to comment.