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