Files
iOS/Sources/App/Scenes/SceneActivity.swift
Copilot 0c0c2533e5 Add scene support for AssistView on macOS (#3965)
## Summary
Enables AssistView to open in a dedicated window on macOS while
maintaining modal presentation on iOS/iPad.

**Implementation:**
- Added `.assist` case to `SceneActivity` enum with `ha.assist`
identifier
- Created `AssistSceneDelegate` extending `BasicSceneDelegate` to manage
Assist windows
- Updated `Info.plist` with Assist scene configuration
- Added `SceneManager.activateAnyScene(for:with:)` to pass parameters
via `NSUserActivity.userInfo`
- Modified `WebViewExternalMessageHandler.showAssist()` to branch on
`Current.isCatalyst`:
  - macOS: `SceneManager.activateAnyScene(for: .assist, with: userInfo)`
  - iOS/iPad: Existing modal presentation (unchanged)
- Window centering: Assist window opens centered on screen (600x600)
using `UIWindowScene.MacGeometryPreferences` (iOS 17+)
- Close button: Removed toolbar close button in scene mode since window
has native close button; modal presentation on iOS/iPad retains close
button

**Parameters passed via userInfo:**
- `server`: Server identifier string
- `pipelineId`: Pipeline ID string
- `autoStartRecording`: Boolean

## Screenshots

N/A - Scene system change, requires macOS build to screenshot

## Link to pull request in Documentation repository
Documentation: home-assistant/companion.home-assistant#

## Any other notes
Follows existing scene patterns from `SettingsSceneDelegate` and
`AboutSceneDelegate`. No breaking changes to iOS/iPad behavior. The
`showCloseButton` parameter in `AssistView` allows flexible control of
close button visibility - `false` for scene mode (window has native
controls), `true` for modal presentation.

<!-- START COPILOT CODING AGENT SUFFIX -->



<details>

<summary>Original prompt</summary>

> Turn AssistView into a scene, so it can be initiated in a new window
on macOS


</details>



<!-- START COPILOT CODING AGENT TIPS -->
---

💡 You can make Copilot smarter by setting up custom instructions,
customizing its development environment and configuring Model Context
Protocol (MCP) servers. Learn more [Copilot coding agent
tips](https://gh.io/copilot-coding-agent-tips) in the docs.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: bgoncal <5808343+bgoncal@users.noreply.github.com>
2025-11-12 17:16:50 +00:00

58 lines
1.6 KiB
Swift

import UIKit
enum SceneActivity: CaseIterable {
case webView
case settings
case about
case carPlay
case assist
init(activityIdentifier: String) {
self = Self.allCases.first(where: { $0.activityIdentifier == activityIdentifier }) ?? .webView
}
init(configurationName: String) {
self = Self.allCases.first(where: { $0.configurationName == configurationName }) ?? .webView
}
var activity: NSUserActivity {
.init(activityType: activityIdentifier)
}
func activity(with userInfo: [AnyHashable: Any]) -> NSUserActivity {
let activity = NSUserActivity(activityType: activityIdentifier)
activity.userInfo = userInfo
return activity
}
var activityIdentifier: String {
switch self {
case .settings: return "ha.settings"
case .webView: return "ha.webview"
case .about: return "ha.about"
case .carPlay: return "ha.carPlay"
case .assist: return "ha.assist"
}
}
var configurationName: String {
switch self {
case .webView: return "WebView"
case .settings: return "Settings"
case .about: return "About"
case .carPlay: return "CarPlay"
case .assist: return "Assist"
}
}
var configuration: UISceneConfiguration {
switch self {
case .webView, .settings, .about, .assist: return .init(
name: configurationName,
sessionRole: .windowApplication
)
case .carPlay: return .init(name: configurationName, sessionRole: .carTemplateApplication)
}
}
}