From f098b9850bd74677f2c18b2f40d81d6d6e560fe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Pantale=C3=A3o=20Gon=C3=A7alves?= Date: Thu, 22 Feb 2024 09:57:24 +0100 Subject: [PATCH] Prevent crash on creating automation from a server controlled iOS Action (#2590) ## Summary When user tap on "Create automation" inside the action configuration screen the app was crashing because it was trying to save the action which was controlled server-side (created in yaml). This was fixed in this PR ## Screenshots ## Link to pull request in Documentation repository Documentation: home-assistant/companion.home-assistant# ## Any other notes --- Sources/App/Settings/ActionConfigurator.swift | 4 +++- .../SettingsDetailViewController.swift | 20 ++++++++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Sources/App/Settings/ActionConfigurator.swift b/Sources/App/Settings/ActionConfigurator.swift index 6f68743ca..b57b72f16 100644 --- a/Sources/App/Settings/ActionConfigurator.swift +++ b/Sources/App/Settings/ActionConfigurator.swift @@ -305,7 +305,9 @@ class ActionConfigurator: HAFormViewController, TypedRowControllerType { private func saveAndAutomate() { if form.validate().count == 0 { Current.Log.verbose("Category form is valid, calling dismiss callback!") - shouldSave = true + if !action.isServerControlled { + shouldSave = true + } shouldOpenAutomationEditor = true onDismissCallback?(self) } diff --git a/Sources/App/Settings/SettingsDetailViewController.swift b/Sources/App/Settings/SettingsDetailViewController.swift index 30d228e97..92f7cf995 100644 --- a/Sources/App/Settings/SettingsDetailViewController.swift +++ b/Sources/App/Settings/SettingsDetailViewController.swift @@ -716,6 +716,17 @@ class SettingsDetailViewController: HAFormViewController, TypedRowControllerType _ = vc.navigationController?.popViewController(animated: true) if let vc = vc as? ActionConfigurator { + defer { + if vc.shouldOpenAutomationEditor { + vc.navigationController?.dismiss(animated: true, completion: { + Current.sceneManager.webViewWindowControllerPromise.then(\.webViewControllerPromise) + .done { controller in + controller.openActionAutomationEditor(actionId: vc.action.ID) + } + }) + } + } + if vc.shouldSave == false { Current.Log.verbose("Not saving action to DB and returning early!") return @@ -734,15 +745,6 @@ class SettingsDetailViewController: HAFormViewController, TypedRowControllerType }.done { self?.updatePositions() }.cauterize() - - if vc.shouldOpenAutomationEditor { - vc.navigationController?.dismiss(animated: true, completion: { - Current.sceneManager.webViewWindowControllerPromise.then(\.webViewControllerPromise) - .done { controller in - controller.openActionAutomationEditor(actionId: vc.action.ID) - } - }) - } } }) }