Add an iPhone client sharing the macOS app's SwiftUI code

This commit is contained in:
Ian Gulliver
2026-10-21 22:00:54 -07:00
parent 57d660c57f
commit 9e81e9107d
46 changed files with 1625 additions and 287 deletions
+56 -5
View File
@@ -1,11 +1,9 @@
import AppKit
import ByreAPI
import SwiftUI
@MainActor
final class PaneFocus {
private let api: API
private weak var window: NSWindow?
private var paneFrame: CGRect = .zero
private var taskSheetFrame: CGRect = .zero
private var leadSheetFrame: CGRect = .zero
@@ -15,13 +13,57 @@ final class PaneFocus {
private(set) var drafting = false
private var sending: Task<Void, Never>?
private var observers: [NotificationCenter.ObservationToken] = []
#if os(macOS)
private weak var window: NSWindow?
private var responder: NSKeyValueObservation?
private var clicks: Any?
#endif
init(api: API) {
self.api = api
}
#if os(iOS)
func attach() {
if !observers.isEmpty {
return
}
let center = NotificationCenter.default
observers = [
center.addObserver(of: UIApplication.self, for: .didBecomeActive) { [weak self] _ in
self?.update()
},
center.addObserver(of: UIApplication.self, for: .willResignActive) { [weak self] _ in
self?.update()
},
]
}
let shown = Listeners<Void>()
func setShown(_ shown: Bool) {
inside = shown
update()
if shown {
self.shown.send(())
}
}
func detach() {
for o in observers {
NotificationCenter.default.removeObserver(o)
}
observers = []
}
private var active: Bool {
UIApplication.shared.applicationState == .active
}
#else
private var active: Bool {
(window?.isKeyWindow ?? false) && NSApp.isActive
}
func attach(_ window: NSWindow) {
if self.window === window {
return
@@ -73,9 +115,14 @@ final class PaneFocus {
clicks = nil
window = nil
}
#endif
var windowKey: Bool {
(window?.isKeyWindow ?? false) && NSApp.isActive
var taskVisible: Bool {
#if os(iOS)
active && inside
#else
active
#endif
}
func setFrame(_ frame: CGRect) {
@@ -123,6 +170,7 @@ final class PaneFocus {
}
}
#if os(macOS)
private func contentPoint(_ rect: CGRect, in view: NSView) -> CGPoint? {
guard let content = window?.contentView else {
return nil
@@ -157,9 +205,10 @@ final class PaneFocus {
self?.responderChanged()
}
}
#endif
private func update() {
let now = (window?.isKeyWindow ?? false) && NSApp.isActive && inside
let now = active && inside
let draft = !drafts.isEmpty
if now == focused && draft == drafting {
return
@@ -183,6 +232,7 @@ final class PaneFocus {
}
}
#if os(macOS)
struct WindowReader: NSViewRepresentable {
let found: (NSWindow) -> Void
@@ -212,3 +262,4 @@ final class WindowReaderView: NSView {
}
}
}
#endif