1 // Copyright 2015-present 650 Industries. All rights reserved.
2 
3 @objc
4 public protocol DevMenuCallableProvider {
5   @objc
6   optional func registerCallable() -> DevMenuExportedCallable?
7 }
8 
9 @objc
10 public class DevMenuExportedCallable: NSObject {
11   @objc
12   public let id: String
13 
14   @objc
15   init(withId id: String) {
16     self.id = id
17   }
18 }
19 
20 @objc
21 public class DevMenuExportedFunction: DevMenuExportedCallable {
22   @objc
23   public var function: ([String : Any]?) -> Void
24 
25   @objc
26   public init(withId id: String, withFunction function: @escaping ([String : Any]?) -> Void) {
27     self.function = function
28     super.init(withId: id)
29   }
30 
31   public func call(args: [String : Any]?) {
32     function(args)
33   }
34 }
35 
36 @objc
37 public class DevMenuExportedAction: DevMenuExportedCallable {
38   @objc
39   public var action: () -> Void
40 
41   @objc
42   public private(set) var keyCommand: UIKeyCommand? = nil
43 
44   @objc
45   public var isAvailable: () -> Bool = { true }
46 
47   @objc
48   public init(withId id: String, withAction action: @escaping  () -> Void) {
49     self.action = action
50     super.init(withId: id)
51   }
52 
53   public func call() {
54     action()
55   }
56 
57   @objc
58   public func registerKeyCommand(input: String, modifiers: UIKeyModifierFlags) {
59     keyCommand = UIKeyCommand(input: input, modifierFlags: modifiers, action: #selector(DevMenuUIResponderExtensionProtocol.EXDevMenu_handleKeyCommand(_:)))
60   }
61 }
62