From 2d52489da42ff2e5024dc25287790c63ac1c86c3 Mon Sep 17 00:00:00 2001 From: Dan Cunningham Date: Sat, 29 Jun 2024 19:45:17 -0700 Subject: [PATCH] Support http links in actions (#772) Signed-off-by: Dan Cunningham --- NotificationService/NotificationService.swift | 2 +- openHAB/OpenHABRootViewController.swift | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/NotificationService/NotificationService.swift b/NotificationService/NotificationService.swift index 80c7e071..dad6de49 100644 --- a/NotificationService/NotificationService.swift +++ b/NotificationService/NotificationService.swift @@ -34,7 +34,7 @@ class NotificationService: UNNotificationServiceExtension { let title = actionDict["title"] { var options: UNNotificationActionOptions = [] // navigate options need to bring the app forward - if action.hasPrefix("ui") { + if action.hasPrefix("ui") || action.hasPrefix("http") { options = [.foreground] } let notificationAction = UNNotificationAction( diff --git a/openHAB/OpenHABRootViewController.swift b/openHAB/OpenHABRootViewController.swift index efff473e..0f888451 100644 --- a/openHAB/OpenHABRootViewController.swift +++ b/openHAB/OpenHABRootViewController.swift @@ -198,9 +198,10 @@ class OpenHABRootViewController: UIViewController { let cmd = action.split(separator: ":").dropFirst().joined(separator: ":") if action.hasPrefix("ui") { uiCommandAction(cmd) - } - if action.hasPrefix("command") { + } else if action.hasPrefix("command") { sendCommandAction(cmd) + } else if action.hasPrefix("http") { + httpCommandAction(action) } } } @@ -253,6 +254,13 @@ class OpenHABRootViewController: UIViewController { } } + private func httpCommandAction(_ command: String) { + if let url = URL(string: command) { + let vc = SFSafariViewController(url: url) + present(vc, animated: true) + } + } + func showSideMenu() { os_log("OpenHABRootViewController showSideMenu", log: .viewCycle, type: .info) if let menu = SideMenuManager.default.rightMenuNavigationController {