Skip to content

Commit

Permalink
Add URL to error screen and improve UI in dark mode (#3349)
Browse files Browse the repository at this point in the history
<!-- 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. -->
![CleanShot 2025-01-21 at 21 32
22@2x](https://github.com/user-attachments/assets/a42b28fe-2125-429c-88fb-7453f41773f2)

## 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. -->
  • Loading branch information
bgoncal authored Jan 21, 2025
1 parent 68cbff4 commit b3aa00a
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 9 deletions.
4 changes: 3 additions & 1 deletion Sources/App/Resources/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@
"connection.error.details.button.discord" = "Ask in Discord";
"connection.error.details.button.doc" = "Read documentation";
"connection.error.details.button.github" = "Report issue in GitHub";
"connection.error.details.button.search_github" = "Search in GitHub";
"connection.error.details.label.code" = "Code";
"connection.error.details.label.description" = "Description";
"connection.error.details.label.domain" = "Domain";
Expand Down Expand Up @@ -1107,4 +1108,5 @@ Home Assistant is free and open source home automation software with a focus on
"widgets.sensors.description" = "Display state of sensors";
"widgets.sensors.not_configured" = "No Sensors Configured";
"widgets.sensors.title" = "Sensors";
"yes_label" = "Yes";
"yes_label" = "Yes";
"url_label" = "URL";
18 changes: 17 additions & 1 deletion Sources/App/WebView/ConnectionErrorDetailsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ struct ConnectionErrorDetailsView: View {
makeRow(title: L10n.Connection.Error.Details.Label.description, body: error.localizedDescription)
makeRow(title: L10n.Connection.Error.Details.Label.domain, body: (error as NSError).domain)
makeRow(title: L10n.Connection.Error.Details.Label.code, body: "\((error as NSError).code)")
if let urlError = error as? URLError {
makeRow(title: L10n.urlLabel, body: urlError.failingURL?.absoluteString ?? "")
}
}
.padding(.vertical)
documentationLink
Expand Down Expand Up @@ -57,13 +60,26 @@ struct ConnectionErrorDetailsView: View {
)
}

@ViewBuilder
private var githubLink: some View {
ExternalLinkButton(
icon: Image("github.fill"),
title: L10n.Connection.Error.Details.Button.github,
url: ExternalLink.githubReportIssue,
tint: .black
tint: .init(uiColor: .init(dynamicProvider: { trait in
trait.userInterfaceStyle == .dark ? .white : .black
}))
)
if let searchURL = ExternalLink.githubSearchIssue(domain: (error as NSError).domain) {
ExternalLinkButton(
icon: Image("github.fill"),
title: L10n.Connection.Error.Details.Button.searchGithub,
url: searchURL,
tint: .init(uiColor: .init(dynamicProvider: { trait in
trait.userInterfaceStyle == .dark ? .white : .black
}))
)
}
}
}

Expand Down
26 changes: 19 additions & 7 deletions Sources/Shared/DesignSystem/Components/ExternalLinkButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,28 @@ public struct ExternalLinkButton: View {
}
.frame(maxWidth: 600)
.padding()
.background(Color(.systemGray6))
.background(Color(uiColor: .secondarySystemBackground))
.clipShape(RoundedRectangle(cornerRadius: 12))
}
}

#Preview {
ExternalLinkButton(
icon: Image(systemName: "xmark"),
title: "Go there",
url: URL(string: "https://google.com")!,
tint: .blue
)
VStack {}
.sheet(isPresented: .constant(true)) {
VStack {
ExternalLinkButton(
icon: Image(systemName: "xmark"),
title: "Go there",
url: URL(string: "https://google.com")!,
tint: .blue
)
ExternalLinkButton(
icon: Image(systemName: "xmark"),
title: "Go there",
url: URL(string: "https://google.com")!,
tint: .blue
)
.preferredColorScheme(.dark)
}
}
}
3 changes: 3 additions & 0 deletions Sources/Shared/ExternalLink.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ public enum ExternalLink {
public static var companionAppDocs = URL(string: "https://companion.home-assistant.io")!
public static var discord = URL(string: "https://discord.com/channels/330944238910963714/1284965926336335993")!
public static var githubReportIssue = URL(string: "https://github.com/home-assistant/iOS/issues/new/choose")!
public static func githubSearchIssue(domain: String) -> URL? {
URL(string: "https://github.com/home-assistant/iOS/search?q=\(domain)&type=issues")
}
}
4 changes: 4 additions & 0 deletions Sources/Shared/Resources/Swiftgen/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public enum L10n {
public static var retryLabel: String { return L10n.tr("Localizable", "retry_label") }
/// Success
public static var successLabel: String { return L10n.tr("Localizable", "success_label") }
/// URL
public static var urlLabel: String { return L10n.tr("Localizable", "url_label") }
/// Username
public static var usernameLabel: String { return L10n.tr("Localizable", "username_label") }
/// Yes
Expand Down Expand Up @@ -768,6 +770,8 @@ public enum L10n {
public static var doc: String { return L10n.tr("Localizable", "connection.error.details.button.doc") }
/// Report issue in GitHub
public static var github: String { return L10n.tr("Localizable", "connection.error.details.button.github") }
/// Search in GitHub
public static var searchGithub: String { return L10n.tr("Localizable", "connection.error.details.button.search_github") }
}
public enum Label {
/// Code
Expand Down

0 comments on commit b3aa00a

Please sign in to comment.