Skip to content

Commit

Permalink
Fix accessory mode behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
jdamcd committed Dec 6, 2023
1 parent 71d40da commit 7cc06ae
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.7.2
5.9
26 changes: 22 additions & 4 deletions macOS/Arrivals/ArrivalsApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,38 @@ import SwiftUI
@main
struct ArrivalsApp: App {
@NSApplicationDelegateAdaptor(AppDelegate.self) var delegate
@State private var settingsWindow: NSWindow?

var body: some Scene {
Settings {
SettingsView()
.onReceive(NotificationCenter.default.publisher(for: NSWindow.willCloseNotification)) { newValue in
// TODO: Not this
if (!newValue.description.contains("TUINSWindow")) {
NSApplication.accessoryMode()
.background(WindowAccessor(window: $settingsWindow))
.onReceive(NotificationCenter.default.publisher(for: NSWindow.willCloseNotification)) { notif in
if let window = notif.object as? NSWindow {
print("Window \(window.windowNumber) is closing. Settings is \(settingsWindow?.windowNumber ?? -1).")
if window.windowNumber == settingsWindow?.windowNumber {
NSApplication.accessoryMode()
}
}
}
}
}
}

struct WindowAccessor: NSViewRepresentable {
@Binding var window: NSWindow?

func makeNSView(context _: Context) -> NSView {
let view = NSView()
DispatchQueue.main.async {
self.window = view.window
}
return view
}

func updateNSView(_: NSView, context _: Context) {}
}

class PopoverState: ObservableObject {
@Published var isShown = false
}
Expand Down

0 comments on commit 7cc06ae

Please sign in to comment.