Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom "About Application" window with Mac Catalyst

Change the "About Application" window for Mac Catalyst? How is it done?

like image 493
Bosse Nilsson Avatar asked Oct 21 '25 15:10

Bosse Nilsson


1 Answers

Something like this:

#if targetEnvironment(macCatalyst)
extension AppDelegate {
override func buildMenu(with builder: UIMenuBuilder) {
    guard builder.system == .main else { return }

    // override about button
    builder.replaceChildren(ofMenu: .about) { (oldChildren) -> [UIMenuElement] in
        let menuElement = oldChildren.first
        if let uiCommand = menuElement as? UICommand {
            let aboutUICommand = UICommand(title: uiCommand.title,
            action: #selector(aboutApp(_:)))
            return [aboutUICommand]
        } else {
            return oldChildren
        }
    }
}

override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
        return super.canPerformAction(action, withSender: sender)
}

override func target(forAction action: Selector, withSender sender: Any?) -> Any? {
    if action == #selector(aboutApp) {
        return self
    } else {
        return nil
    }
}

@objc func aboutApp(_ selector: Any?) {
    guard let aboutTVC = AboutViewController.createInstance() else { return; }
    rootViewController?.present(aboutTVC, animated: true, completion: nil)
} 
} 
#endif
like image 199
Balki Avatar answered Oct 23 '25 06:10

Balki