From 4dc1c2bc4f6e71ae5b617973cc866ed15bd8e799 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Pantale=C3=A3o?= <5808343+bgoncal@users.noreply.github.com> Date: Mon, 2 Dec 2024 12:01:33 +0100 Subject: [PATCH 1/2] Add "no url available" warning --- .../Resources/en.lproj/Localizable.strings | 4 +++- Sources/App/WebView/WebViewController.swift | 23 +++++++++++++++++++ .../Shared/Resources/Swiftgen/Strings.swift | 11 +++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/Sources/App/Resources/en.lproj/Localizable.strings b/Sources/App/Resources/en.lproj/Localizable.strings index c2fea40b7..6b296857e 100644 --- a/Sources/App/Resources/en.lproj/Localizable.strings +++ b/Sources/App/Resources/en.lproj/Localizable.strings @@ -1054,4 +1054,6 @@ 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"; \ No newline at end of file +"network.error.no_active_url.title" = "No URL available to load"; +"network.error.no_active_url.body" = "Open companion app settings and check your server settings, internal URL will only be used if local network is defined (SSID), if you are using VPN try setting your external URL as the same as internal URL."; +"yes_label" = "Yes"; diff --git a/Sources/App/WebView/WebViewController.swift b/Sources/App/WebView/WebViewController.swift index 0a2831622..fdaee063c 100644 --- a/Sources/App/WebView/WebViewController.swift +++ b/Sources/App/WebView/WebViewController.swift @@ -598,6 +598,26 @@ final class WebViewController: UIViewController, WKNavigationDelegate, WKUIDeleg sidebarGestureRecognizer.isEnabled = server.info.version >= .externalBusCommandSidebar } + private func showNoActiveURLError() { + Current.Log.info("Showing noActiveURLError") + var config = swiftMessagesConfig() + let view = MessageView.viewFromNib(layout: .messageView) + view.configureContent( + title: L10n.Network.Error.NoActiveUrl.title, + body: L10n.Network.Error.NoActiveUrl.body, + iconImage: nil, + iconText: nil, + buttonImage: MaterialDesignIcons.cogIcon.image(ofSize: CGSize(width: 30, height: 30), color: Asset.Colors.haPrimary.color), + buttonTitle: nil, + buttonTapHandler: { [weak self] _ in + self?.showSettingsViewController() + SwiftMessages.hide() + } + ) + + SwiftMessages.show(config: config, view: view) + } + @objc private func connectionInfoDidChange() { DispatchQueue.main.async { [self] in loadActiveURLIfNeeded() @@ -608,6 +628,7 @@ final class WebViewController: UIViewController, WKNavigationDelegate, WKUIDeleg @objc private func loadActiveURLIfNeeded() { guard let webviewURL = server.info.connection.webviewURL() else { Current.Log.info("not loading, no url") + showNoActiveURLError() return } @@ -645,6 +666,8 @@ final class WebViewController: UIViewController, WKNavigationDelegate, WKUIDeleg } else { webView.load(URLRequest(url: webviewURL)) } + } else { + showNoActiveURLError() } } diff --git a/Sources/Shared/Resources/Swiftgen/Strings.swift b/Sources/Shared/Resources/Swiftgen/Strings.swift index 7345dd6f2..9c720943a 100644 --- a/Sources/Shared/Resources/Swiftgen/Strings.swift +++ b/Sources/Shared/Resources/Swiftgen/Strings.swift @@ -1156,6 +1156,17 @@ public enum L10n { public static var close: String { return L10n.tr("Localizable", "navBar.close") } } + public enum Network { + public enum Error { + public enum NoActiveUrl { + /// Open companion app settings and check your server settings, internal URL will only be used if local network is defined (SSID), if you are using VPN try setting your external URL as the same as internal URL. + public static var body: String { return L10n.tr("Localizable", "network.error.no_active_url.body") } + /// No URL available to load + public static var title: String { return L10n.tr("Localizable", "network.error.no_active_url.title") } + } + } + } + public enum Nfc { /// Tag Read public static var genericTagRead: String { return L10n.tr("Localizable", "nfc.generic_tag_read") } From be8855567f5c892e9ee38de3860765c04e765cb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Pantale=C3=A3o?= <5808343+bgoncal@users.noreply.github.com> Date: Mon, 2 Dec 2024 13:00:34 +0100 Subject: [PATCH 2/2] lint --- Sources/App/WebView/WebViewController.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sources/App/WebView/WebViewController.swift b/Sources/App/WebView/WebViewController.swift index fdaee063c..a075ea26a 100644 --- a/Sources/App/WebView/WebViewController.swift +++ b/Sources/App/WebView/WebViewController.swift @@ -607,7 +607,10 @@ final class WebViewController: UIViewController, WKNavigationDelegate, WKUIDeleg body: L10n.Network.Error.NoActiveUrl.body, iconImage: nil, iconText: nil, - buttonImage: MaterialDesignIcons.cogIcon.image(ofSize: CGSize(width: 30, height: 30), color: Asset.Colors.haPrimary.color), + buttonImage: MaterialDesignIcons.cogIcon.image( + ofSize: CGSize(width: 30, height: 30), + color: Asset.Colors.haPrimary.color + ), buttonTitle: nil, buttonTapHandler: { [weak self] _ in self?.showSettingsViewController()