Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 40 additions & 27 deletions openHAB/OpenHABRootViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,6 @@ class OpenHABRootViewController: UIViewController {
self.modalDismissed(to: .settings)
}
case let .sitemap(sitemap):
Preferences.shared.modifyActiveHome { homePreferences in
homePreferences.defaultSitemap = sitemap
}
SideMenuManager.default.rightMenuNavigationController?.dismiss(animated: true) {
self.modalDismissed(to: .sitemap(sitemap))
}
Expand Down Expand Up @@ -466,21 +463,21 @@ class OpenHABRootViewController: UIViewController {
logger.info("handleNotificationInternal: \(action ?? "<none>")")

guard let action else { return }
let actionParts = action.split(separator: ":")
let cmd = actionParts.dropFirst().joined(separator: ":")

let cmd = action.split(separator: ":").dropFirst().joined(separator: ":")

switch true {
case action.hasPrefix("ui"):
switch actionParts[0] {
case "ui":
uiCommandAction(cmd)
case action.hasPrefix("command"):
case "command":
sendCommandAction(cmd)
case action.hasPrefix("http"):
case "http":
httpCommandAction(action)
case action.hasPrefix("app"):
case "app":
appCommandAction(cmd)
case action.hasPrefix("rule"):
case "rule":
ruleCommandAction(cmd)
case action.hasPrefix("device"):
case "device":
deviceAction(cmd)
default:
return
Expand All @@ -503,20 +500,28 @@ class OpenHABRootViewController: UIViewController {
let path = String(firstMatch.1)
logger.info("navigateCommandAction path: \(path)")
if path.starts(with: "/basicui/app?") {
logger.info("Navigating to sitemap target")
let defaultSitemap = Preferences.shared.currentHomePreferences.defaultSitemap
guard let urlComponents = URLComponents(string: path) else {
logger.warning("No parameters for specifying sitemap or widget to navigate to")
if currentView != sitemapViewController {
switchView(target: .sitemap(defaultSitemap))
}
return
}
let queryItems = urlComponents.queryItems
let sitemap = queryItems?.first { $0.name == "sitemap" }?.value
let widgetId = queryItems?.first { $0.name == "w" }?.value
if currentView != sitemapViewController {
switchView(target: .sitemap(""))
switchView(target: .sitemap(sitemap ?? defaultSitemap))
}
if let urlComponents = URLComponents(string: path) {
let queryItems = urlComponents.queryItems
let sitemap = queryItems?.first { $0.name == "sitemap" }?.value
let subview = queryItems?.first { $0.name == "w" }?.value
if let sitemap {
Task {
await sitemapViewController.pushSitemap(name: sitemap, path: subview)
}
if let sitemap {
Task { @MainActor in
await sitemapViewController.pushSitemap(name: sitemap, path: widgetId)
}
}
} else {
logger.info("Navigating to webview target")
if currentView != webViewController {
switchView(target: .webview)
}
Expand Down Expand Up @@ -653,10 +658,13 @@ class OpenHABRootViewController: UIViewController {
private func ruleCommandAction(_ command: String) {
let components = command.split(separator: ":", maxSplits: 2)

guard components.count == 2 else { return }
guard !components.isEmpty else {
logger.warning("No rule to execute found in action")
return
}

let uuid = String(components[0])
let propertiesString = String(components[1])
let propertiesString = if components.count > 1 { String(components[1]) } else { "" }

let propertyPairs = propertiesString.split(separator: ",")
var properties: [String: String] = [:]
Expand Down Expand Up @@ -731,7 +739,10 @@ class OpenHABRootViewController: UIViewController {
let targetView: OpenHABViewController

switch target {
case .sitemap:
case let .sitemap(sitemap):
Preferences.shared.modifyActiveHome { preferences in
preferences.defaultSitemap = sitemap
}
targetView = sitemapViewController
case .webview:
targetView = webViewController
Expand Down Expand Up @@ -763,10 +774,12 @@ class OpenHABRootViewController: UIViewController {

private func switchToSavedView() {
if Preferences.shared.currentHomePreferences.demomode {
switchView(target: .sitemap(""))
switchView(target: .sitemap("demo"))
} else {
logger.info("OpenHABRootViewController switchToSavedView \(Preferences.shared.currentHomePreferences.defaultView == "sitemap" ? "sitemap" : "web")")
switchView(target: Preferences.shared.currentHomePreferences.defaultView == "sitemap" ? .sitemap("") : .webview)
let defaultView = Preferences.shared.currentHomePreferences.defaultView
let defaultSitemap = Preferences.shared.currentHomePreferences.defaultSitemap
logger.info("OpenHABRootViewController switchToSavedView \(defaultView == "sitemap" ? "sitemap/\(defaultSitemap)" : "web")")
switchView(target: defaultView == "sitemap" ? .sitemap(defaultSitemap) : .webview)
}
}

Expand Down
8 changes: 8 additions & 0 deletions openHAB/OpenHABSitemapViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,11 @@ extension OpenHABSitemapViewController {
return
}

guard name != pageId || path != nil else {
logger.info("pushSitemap: Already at the required sitemap")
return
}

logger.info("pushSitemap: pushing page")

guard let baseUrl = URL(string: activeConnection.configuration.url) else {
Expand All @@ -461,6 +466,9 @@ extension OpenHABSitemapViewController {
return
}

if let pageId = path {
newViewController.pageId = pageId
}
newViewController.pageUrl = url.absoluteString
newViewController.openHABRootUrl = activeConnection.configuration.url
navigationController?.pushViewController(newViewController, animated: true)
Expand Down