mirror of
https://github.com/home-assistant/iOS.git
synced 2026-02-05 23:04:20 -06:00
Added calls to syncNetworkInformation() at the start of various perform() methods for AppIntents and widget controls to ensure up-to-date connectivity data before executing actions. Also refactored ConnectivityWrapper to support async network info synchronization. <!-- 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. --> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
72 lines
2.2 KiB
Swift
72 lines
2.2 KiB
Swift
import AppIntents
|
|
import AudioToolbox
|
|
import Foundation
|
|
import Shared
|
|
|
|
@available(iOS 17.0, macOS 14.0, watchOS 10.0, *)
|
|
struct WidgetScriptsAppIntent: AppIntent, WidgetConfigurationIntent {
|
|
static let title: LocalizedStringResource = .init("widgets.scripts.description", defaultValue: "Run Scripts")
|
|
|
|
static var isDiscoverable: Bool = false
|
|
|
|
// ATTENTION: Unfortunately these sizes below can't be retrieved dynamically from widget family sizes.
|
|
// Check ``WidgetFamilySizes.swift`` as source of truth
|
|
@Parameter(
|
|
title: "Scripts",
|
|
size: [
|
|
.systemSmall: 3,
|
|
.systemMedium: 6,
|
|
.systemLarge: 12,
|
|
.systemExtraLarge: 20,
|
|
.accessoryInline: 1,
|
|
.accessoryCorner: 1,
|
|
.accessoryCircular: 1,
|
|
.accessoryRectangular: 2,
|
|
]
|
|
)
|
|
var scripts: [IntentScriptEntity]?
|
|
|
|
@Parameter(
|
|
title: LocalizedStringResource(
|
|
"app_intents.notify_when_run.title",
|
|
defaultValue: "Notify when run"
|
|
),
|
|
description: LocalizedStringResource(
|
|
"app_intents.notify_when_run.description",
|
|
defaultValue: "Shows notification after executed"
|
|
),
|
|
default: true
|
|
)
|
|
var showConfirmationDialog: Bool
|
|
|
|
static var parameterSummary: some ParameterSummary {
|
|
Summary()
|
|
}
|
|
|
|
func perform() async throws -> some IntentResult & ReturnsValue<Bool> {
|
|
await Current.connectivity.syncNetworkInformation()
|
|
guard let scripts else { return .result(value: false) }
|
|
for script in scripts {
|
|
let intent = ScriptAppIntent()
|
|
intent.script = .init(
|
|
id: script.id,
|
|
entityId: script.entityId,
|
|
serverId: script.serverId,
|
|
serverName: script.serverName,
|
|
displayString: script.displayString,
|
|
iconName: script.iconName
|
|
)
|
|
_ = try await intent.perform()
|
|
}
|
|
|
|
return .result(value: true)
|
|
}
|
|
}
|
|
|
|
@available(iOS 16.0, macOS 13.0, watchOS 9.0, tvOS 16.0, *)
|
|
private extension IntentDialog {
|
|
static var actionsParameterConfiguration: Self {
|
|
.init(stringLiteral: L10n.AppIntents.WidgetAction.actionsParameterConfiguration)
|
|
}
|
|
}
|