Skip to content

Commit 453b52b

Browse files
- Removed old custom keyboard handling
1 parent ee40e75 commit 453b52b

File tree

3 files changed

+28
-155
lines changed

3 files changed

+28
-155
lines changed

Sources/WelcomeWindow/Views/WelcomeButton.swift

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,33 @@ public struct WelcomeButton: View {
3535
})
3636
.buttonStyle(WelcomeActionButtonStyle())
3737
.focused($isfocused)
38-
.modifier(FocusRingModifier(isFocused: isfocused, shape: .rect(cornerRadius: 8)))
38+
.modifier(FocusRingModifier(isFocused: isfocused, shape: buttonShape))
39+
}
40+
41+
private var buttonShape: some InsettableShape {
42+
if #available(macOS 26, *) {
43+
return .capsule
44+
} else {
45+
return .rect(cornerRadius: 8)
46+
}
3947
}
4048
}
4149

4250
struct WelcomeActionButtonStyle: ButtonStyle {
4351
func makeBody(configuration: Configuration) -> some View {
44-
configuration.label
45-
.contentShape(Rectangle())
46-
.padding(7)
47-
.frame(height: 36)
48-
.background(Color(.labelColor).opacity(configuration.isPressed ? 0.1 : 0.05))
49-
.clipShape(RoundedRectangle(cornerRadius: 8))
52+
@ViewBuilder var buttonBody: some View {
53+
let base = configuration.label
54+
.contentShape(Rectangle())
55+
.padding(7)
56+
.frame(height: 36)
57+
.background(Color(.labelColor).opacity(configuration.isPressed ? 0.1 : 0.05))
58+
59+
if #available(macOS 26, *) {
60+
base.clipShape(Capsule())
61+
} else {
62+
base.clipShape(RoundedRectangle(cornerRadius: 8))
63+
}
64+
}
65+
return buttonBody
5066
}
5167
}

Sources/WelcomeWindow/Views/WelcomeWindow.swift

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -36,40 +36,7 @@ public struct WelcomeWindow<RecentsView: View, SubtitleView: View>: Scene {
3636
}
3737

3838
public var body: some Scene {
39-
#if swift(>=5.9)
40-
if #available(macOS 15, *) {
41-
return Window("Welcome To \(Bundle.displayName)", id: DefaultSceneID.welcome) {
42-
WelcomeWindowView(
43-
iconImage: iconImage,
44-
title: title,
45-
subtitleView: subtitleView,
46-
buildActions: buildActions,
47-
onDrop: onDrop,
48-
customRecentsList: customRecentsList
49-
)
50-
.frame(width: 740, height: 460)
51-
.task {
52-
if let window = NSApp.findWindow(DefaultSceneID.welcome) {
53-
window.standardWindowButton(.closeButton)?.isHidden = true
54-
window.standardWindowButton(.miniaturizeButton)?.isHidden = true
55-
window.standardWindowButton(.zoomButton)?.isHidden = true
56-
window.hasShadow = true
57-
window.isMovableByWindowBackground = true
58-
}
59-
}
60-
}
61-
.windowStyle(.plain)
62-
.windowResizability(.contentSize)
63-
.defaultLaunchBehavior(.presented)
64-
} else {
65-
return legacyWindow
66-
}
67-
#else
68-
return legacyWindow
69-
#endif
70-
}
7139

72-
private var legacyWindow: some Scene {
7340
Window("Welcome To \(Bundle.displayName)", id: DefaultSceneID.welcome) {
7441
WelcomeWindowView(
7542
iconImage: iconImage,
@@ -79,20 +46,20 @@ public struct WelcomeWindow<RecentsView: View, SubtitleView: View>: Scene {
7946
onDrop: onDrop,
8047
customRecentsList: customRecentsList
8148
)
82-
.frame(width: 740, height: 432)
49+
.frame(width: 740, height: 460)
8350
.task {
8451
if let window = NSApp.findWindow(DefaultSceneID.welcome) {
85-
window.styleMask.insert(.borderless)
52+
window.styleMask.insert(.fullSizeContentView)
8653
window.standardWindowButton(.closeButton)?.isHidden = true
8754
window.standardWindowButton(.miniaturizeButton)?.isHidden = true
8855
window.standardWindowButton(.zoomButton)?.isHidden = true
89-
window.backgroundColor = .clear
56+
window.hasShadow = true
9057
window.isMovableByWindowBackground = true
9158
}
9259
}
9360
}
94-
.windowStyle(.hiddenTitleBar)
9561
.windowResizability(.contentSize)
62+
.windowStyle(.hiddenTitleBar)
9663
}
9764
}
9865

Sources/WelcomeWindow/Views/WelcomeWindowView.swift

Lines changed: 1 addition & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ public struct WelcomeWindowView<RecentsView: View, SubtitleView: View>: View {
1818

1919
@FocusState private var focusedField: FocusTarget?
2020

21-
@State private var eventMonitor: Any?
2221
@State private var recentProjects: [URL] = RecentsStore.recentProjectURLs()
2322
@State private var selection: Set<URL> = []
24-
@State private var actionCount: Int = 0
2523

2624
private let buildActions: (_ dismissWindow: @escaping () -> Void) -> WelcomeActions
2725
private let onDrop: ((_ url: URL, _ dismiss: @escaping () -> Void) -> Void)?
@@ -95,32 +93,10 @@ public struct WelcomeWindowView<RecentsView: View, SubtitleView: View>: View {
9593
selection = [recentProjects[0]]
9694
}
9795

98-
// Determine how many actions are defined
99-
switch actions {
100-
case .none:
101-
actionCount = 0
102-
case .one:
103-
actionCount = 1
104-
case .two:
105-
actionCount = 2
106-
case .three:
107-
actionCount = 3
108-
}
109-
11096
// Initial focus
11197
focusedField = .recentProjects
112-
113-
// Monitor key input
114-
self.eventMonitor = NSEvent.addLocalMonitorForEvents(matching: [.keyDown]) { event in
115-
return handleKeyDown(event)
116-
}
117-
}
118-
.onDisappear {
119-
if let monitor = eventMonitor {
120-
NSEvent.removeMonitor(monitor)
121-
eventMonitor = nil
122-
}
12398
}
99+
124100
.onDrop(of: [.fileURL], isTargeted: .constant(true)) { providers in
125101
NSApp.activate(ignoringOtherApps: true)
126102
providers.forEach {
@@ -135,90 +111,4 @@ public struct WelcomeWindowView<RecentsView: View, SubtitleView: View>: View {
135111
return true
136112
}
137113
}
138-
139-
// MARK: - Keyboard Handling
140-
141-
private func handleKeyDown(_ event: NSEvent) -> NSEvent? {
142-
143-
// cmd+W
144-
if event.modifierFlags.contains(.command), event.keyCode == 13 {
145-
dismissWindow()
146-
return nil
147-
}
148-
149-
switch event.keyCode {
150-
case 126: // Arrow Up
151-
if focusedField == .recentProjects {
152-
return handleArrowUp() ? nil : event
153-
}
154-
case 125: // Arrow Down
155-
if focusedField == .recentProjects {
156-
return handleArrowDown() ? nil : event
157-
}
158-
case 36, 76: // Return / Enter
159-
if focusedField == .recentProjects {
160-
return handleReturnKey() ? nil : event
161-
} else if focusedField == .dismissButton {
162-
dismissWindow()
163-
return nil
164-
}
165-
case 48: // Tab
166-
switchFocus()
167-
return nil
168-
default:
169-
break
170-
}
171-
return event
172-
}
173-
174-
private func handleArrowUp() -> Bool {
175-
guard let current = selection.first.flatMap({ recentProjects.firstIndex(of: $0) }) else {
176-
selection = Set(recentProjects.suffix(1))
177-
return true
178-
}
179-
if current > 0 {
180-
selection = [recentProjects[current - 1]]
181-
}
182-
return true
183-
}
184-
185-
private func handleArrowDown() -> Bool {
186-
guard let current = selection.first.flatMap({ recentProjects.firstIndex(of: $0) }) else {
187-
selection = Set(recentProjects.prefix(1))
188-
return true
189-
}
190-
if current < recentProjects.count - 1 {
191-
selection = [recentProjects[current + 1]]
192-
}
193-
return true
194-
}
195-
196-
private func handleReturnKey() -> Bool {
197-
guard let selected = selection.first else { return false }
198-
NSDocumentController.shared.openDocument(at: selected) {
199-
dismissWindow()
200-
}
201-
return true
202-
}
203-
204-
private func switchFocus() {
205-
let focusOrder: [FocusTarget] = {
206-
var order: [FocusTarget] = [.dismissButton]
207-
if actionCount >= 1 { order.append(.action1) }
208-
if actionCount >= 2 { order.append(.action2) }
209-
if actionCount >= 3 { order.append(.action3) }
210-
order.append(.recentProjects)
211-
return order
212-
}()
213-
214-
guard let current = focusedField,
215-
let currentIndex = focusOrder.firstIndex(of: current) else {
216-
focusedField = .dismissButton // start at dismiss
217-
return
218-
}
219-
220-
let nextIndex = (currentIndex + 1) % focusOrder.count
221-
focusedField = focusOrder[nextIndex]
222-
}
223-
224114
}

0 commit comments

Comments
 (0)