-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppCommands.swift
74 lines (65 loc) · 1.98 KB
/
AppCommands.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//
// AppCommands.swift
// Blankie
//
// Created by Cody Bromley on 1/1/25.
//
import SwiftUI
struct AppCommands: Commands {
@Binding var showingAbout: Bool
@Binding var hasWindow: Bool
@ObservedObject private var appState = AppState.shared
var body: some Commands {
CommandGroup(replacing: .appInfo) {
Button("About Blankie") {
showingAbout = true
}
}
CommandGroup(replacing: .newItem) {
Button("New Window") {
if !hasWindow {
let controller = NSWindowController(
window: NSWindow(
contentRect: WindowDefaults.defaultFrame,
styleMask: WindowDefaults.styleMask,
backing: .buffered,
defer: false
)
)
if let window = controller.window {
WindowDefaults.configureWindow(window)
let contentView = WindowDefaults.defaultContentView(
showingAbout: $showingAbout,
showingShortcuts: .constant(false),
showingNewPresetPopover: .constant(false),
presetName: .constant("")
)
let hostingView = NSHostingView(rootView: contentView)
window.contentView = hostingView
controller.showWindow(nil)
hasWindow = true
}
}
}
.disabled(hasWindow)
.keyboardShortcut("n", modifiers: .command)
}
CommandGroup(after: .toolbar) {
Button(appState.hideInactiveSounds ? "Show All Sounds" : "Hide Inactive Sounds") {
withAnimation {
appState.hideInactiveSounds.toggle()
UserDefaults.standard.set(appState.hideInactiveSounds, forKey: "hideInactiveSounds")
}
}
.keyboardShortcut("h", modifiers: [.control, .command])
}
// Add Help menu command
CommandGroup(replacing: .help) {
Button("Blankie Help") {
if let url = URL(string: "https://blankie.rest/faq") {
NSWorkspace.shared.open(url)
}
}
}
}
}