mirror of
https://github.com/home-assistant/iOS.git
synced 2026-02-20 20:06:04 -06:00
<!-- Thank you for submitting a Pull Request and helping to improve Home Assistant. Please complete the following sections to help the processing and review of your changes. Please do not delete anything from this template. --> ## Summary <!-- Provide a brief summary of the changes you have made and most importantly what they aim to achieve --> ## Screenshots <!-- If this is a user-facing change not in the frontend, please include screenshots in light and dark mode. --> ## Link to pull request in Documentation repository <!-- Pull requests that add, change or remove functionality must have a corresponding pull request in the Companion App Documentation repository (https://github.com/home-assistant/companion.home-assistant). Please add the number of this pull request after the "#" --> Documentation: home-assistant/companion.home-assistant# ## Any other notes <!-- If there is any other information of note, like if this Pull Request is part of a bigger change, please include it here. -->
69 lines
2.0 KiB
Swift
69 lines
2.0 KiB
Swift
import AppIntents
|
|
import Foundation
|
|
import SFSafeSymbols
|
|
import Shared
|
|
import WidgetKit
|
|
|
|
@available(iOS 18, *)
|
|
struct ControlOpenPageItem {
|
|
let page: PageAppEntity
|
|
let icon: SFSymbolEntity
|
|
}
|
|
|
|
@available(iOS 18, *)
|
|
struct ControlOpenPageValueProvider: AppIntentControlValueProvider {
|
|
func currentValue(configuration: ControlOpenPageConfiguration) async throws -> ControlOpenPageItem {
|
|
item(configuration: configuration)
|
|
}
|
|
|
|
func placeholder(for configuration: ControlOpenPageConfiguration) -> ControlOpenPageItem {
|
|
item(configuration: configuration)
|
|
}
|
|
|
|
func previewValue(configuration: ControlOpenPageConfiguration) -> ControlOpenPageItem {
|
|
item(configuration: configuration)
|
|
}
|
|
|
|
private func item(configuration: ControlOpenPageConfiguration) -> ControlOpenPageItem {
|
|
.init(
|
|
page: configuration.page ?? placeholder().page,
|
|
icon: configuration.icon ?? placeholder().icon
|
|
)
|
|
}
|
|
|
|
private func placeholder() -> ControlOpenPageItem {
|
|
.init(
|
|
page: .init(
|
|
id: UUID().uuidString,
|
|
panel: .init(
|
|
icon: SFSymbol.rectangleAndPaperclip.rawValue,
|
|
title: L10n.Widgets.Controls.OpenPage.Configuration.Parameter.choosePage,
|
|
path: "",
|
|
component: "",
|
|
showInSidebar: false
|
|
),
|
|
serverId: UUID().uuidString
|
|
),
|
|
icon: .init(id: SFSymbol.rectangleAndPaperclip.rawValue)
|
|
)
|
|
}
|
|
}
|
|
|
|
@available(iOS 18.0, *)
|
|
struct ControlOpenPageConfiguration: ControlConfigurationIntent {
|
|
static var title: LocalizedStringResource = .init(
|
|
"widgets.controls.open_page.configuration.title",
|
|
defaultValue: "Page"
|
|
)
|
|
|
|
@Parameter(
|
|
title: .init("widgets.controls.open_page.configuration.parameter.page", defaultValue: "Page")
|
|
)
|
|
var page: PageAppEntity?
|
|
|
|
@Parameter(
|
|
title: .init("app_intents.scenes.icon.title", defaultValue: "Icon")
|
|
)
|
|
var icon: SFSymbolEntity?
|
|
}
|