iOS/Sources/Extensions/Widgets/Script/Control/ControlScript.swift

35 lines
1.4 KiB
Swift

import Foundation
import Shared
import SwiftUI
import WidgetKit
@available(iOS 18, *)
struct ControlScript: ControlWidget {
var body: some ControlWidgetConfiguration {
AppIntentControlConfiguration(
kind: WidgetsKind.controlScript.rawValue,
provider: ControlScriptsValueProvider()
) { template in
ControlWidgetButton(action: {
let intent = ScriptAppIntent()
intent.script = .init(
id: template.intentScriptEntity.id,
entityId: template.intentScriptEntity.entityId,
serverId: template.intentScriptEntity.serverId,
serverName: template.intentScriptEntity.serverName,
displayString: template.intentScriptEntity.displayString,
iconName: template.icon.id
)
intent.showConfirmationNotification = template.showConfirmationNotification
return intent
}()) {
// ControlWidget can only display SF Symbol
Label(template.intentScriptEntity.displayString, systemImage: template.icon.id)
}
.tint(.init(uiColor: Asset.Colors.haPrimary.color))
}
.displayName(.init(stringLiteral: L10n.Widgets.Controls.Script.displayName))
.description(.init(stringLiteral: L10n.Widgets.Controls.Script.description))
}
}