Skip to content

Commit

Permalink
Fix shortcut action name. Fixes #505.
Browse files Browse the repository at this point in the history
  • Loading branch information
robbiet480 committed Feb 12, 2020
1 parent 7295449 commit 82062ad
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
20 changes: 12 additions & 8 deletions HomeAssistant/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -274,18 +274,22 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
return
}

let name = shortcutItem.localizedTitle
let actionPromise = api.HandleAction(actionID: shortcutItem.type, actionName: name,
source: .AppShortcut)

var promises = [actionPromise]
var action: Promise<Bool>?

if shortcutItem.type == "sendLocation" {
promises.append(api.GetAndSendLocation(trigger: .AppShortcut))
action = api.GetAndSendLocation(trigger: .AppShortcut)
} else if let userInfo = shortcutItem.userInfo, let name = userInfo["name"] as? String {
action = api.HandleAction(actionID: shortcutItem.type, actionName: name, source: .AppShortcut)
}

guard let actionPromise = action else {
Current.Log.error("Shortcut promises is nil!!! Shortcut type was \(shortcutItem.type)")
completionHandler(false)
return
}

when(fulfilled: promises).done { worked in
completionHandler(worked[0])
actionPromise.done { worked in
completionHandler(worked)
}.catch { error in
Current.Log.error("Received error from handleAction during App Shortcut: \(error)")
completionHandler(false)
Expand Down
4 changes: 3 additions & 1 deletion HomeAssistant/Classes/Action.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ public class Action: Object, Mappable, NSCoding {

#if os(iOS)
public var uiShortcut: UIApplicationShortcutItem {
return UIApplicationShortcutItem(type: self.ID, localizedTitle: self.Text)
return UIApplicationShortcutItem(type: self.ID, localizedTitle: self.Text,
localizedSubtitle: nil, icon: nil,
userInfo: ["name": self.Name as NSSecureCoding])
}
#endif
}
Expand Down

0 comments on commit 82062ad

Please sign in to comment.