HookGroup

public protocol HookGroup

A marker type which allows grouping and deferring the initialization of hooks.

Declaring a Group

In order to create a group, simply declare a type (usually a struct) which conforms to HookGroup.

Hooks are assigned to groups by setting the AnyHook.Group associatedtype to the desired group (usually using a typealias; see the example below). Every hook belongs to exactly one group. By default, all hooks are part of DefaultGroup.

Activating a Group

When a group is activated, it refers to the enabling of all of the hooks in that group. A group can be activated at most once.

The group DefaultGroup is automatically activated during Orion’s initialization sequence. Custom groups, on the other hand, are not activated automatically. You may choose to activate a custom group whatever you like (but at most once), or choose to not activate it at all.

In order to activate a group, create a new instance of the group’s type, and call activate() on it. Orion will then enable all of the hooks assigned to that group. The instance on which you called activate() will be saved by Orion and will become accessible to the group’s hooks via the AnyHook.group accessor. This means that you can add properties to your group’s type which can effectively be used as “arguments” that are passed during activation.

Example

The following is a snippet of a tweak which activates NewStuff on iOS 14 or higher, and OldStuff on older iOS versions. In the former case, a boolean argument is passed to indicate whether the device has a notch. The class names used in this tweak are for demonstrative purposes only; there’s no guarantee that classes with these names actually exist.

struct iOS14Stuff: HookGroup {
    let hasNotch: Bool
}

struct iOS13Stuff: HookGroup {}

class CallBarHook: ClassHook<UIView> {
    typealias Group = iOS14Stuff
    static let targetName = "SBCallBarView"
    // ...
}

class AppLibraryHook: ClassHook<UIView> {
    typealias Group = iOS14Stuff
    static let targetName =
        group.hasNotch ? "SBModernAppLibraryView" : "SBAppLibraryView"
    // ...
}

class CallScreenHook: ClassHook<UIView> {
    typealias Group = iOS13Stuff
    static let targetName = "SBCallScreenView"
    // ...
}

struct MyTweak: Tweak {
    init() {
        if #available(iOS 14, *) {
            let hasNotch = // ...
            iOS14Stuff(hasNotch: hasNotch).activate()
        } else {
            iOS13Stuff().activate()
        }
    }
}
  • Called after all of the hooks in the group have been activated.

    A default implementation is provided, which does nothing.

    Declaration

    Swift

    func groupDidActivate()
  • isActive Extension method

    Whether or not the group has been activated (by calling activate() on an instance of it) yet.

    Declaration

    Swift

    public static var isActive: Bool { get }
  • activate() Extension method

    Activates the group, enabling all hooks assigned to it.

    The instance on which this method is called will be saved and can henceforth be retrieved via the AnyHook.group property on any hook assigned to this group.

    Warning

    For any particular group type, this method can be called at most once.

    See

    HookGroup for more info on group activation.

    Declaration

    Swift

    public func activate()