Files
iOS/Sources/Extensions/Widgets/OpenEntity/ControlOpenEntity/OpenEntityAppIntent.swift
Bruno Pantaleão Gonçalves 8c46161ff0 Replace usage of UIApplication.shared by URLOpener class (#3961)
<!-- 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>
2025-11-12 15:41:49 +01:00

41 lines
1.3 KiB
Swift

import AppIntents
import Foundation
import Shared
import SwiftUI
// AppIntent that open app needs to have it's target the widget extension AND app target!
@available(iOS 17, *)
struct OpenEntityAppIntent: AppIntent {
static var title: LocalizedStringResource = .init(
"widgets.controls.open_entity.configuration.title",
defaultValue: "Open Entity"
)
static var openAppWhenRun: Bool = true
@Parameter(
title: .init("widgets.controls.open_entity.configuration.parameter.entity", defaultValue: "Entity")
)
var entity: HAAppEntityAppIntentEntity?
func perform() async throws -> some IntentResult {
guard let entity else { return .result() }
#if !WIDGET_EXTENSION
if Domain(entityId: entity.entityId) == .camera, let url = AppConstants.openCameraDeeplinkURL(
entityId: entity.entityId,
serverId: entity.serverId
) {
DispatchQueue.main.async {
URLOpener.shared.open(url, options: [:], completionHandler: nil)
}
} else if let url =
AppConstants.openEntityDeeplinkURL(entityId: entity.entityId, serverId: entity.serverId) {
DispatchQueue.main.async {
URLOpener.shared.open(url, options: [:], completionHandler: nil)
}
}
#endif
return .result()
}
}