import Foundation
import ThreemaMacros
/// Provides list of available shortcut items
///
/// To add a new shortcut item:
/// 1. Add a new case to the `ActionType` enum
/// 2. Add the new case to the `items(for:)` method
enum UIApplicationShortcutItemProvider {
enum ActionType {
case newMessage
case myID
case scanQrCode
var localizedTitle: String {
switch self {
case .newMessage:
#localize("application_shortcut_item_new_message")
case .myID:
#localize("application_shortcut_item_my_id")
case .scanQrCode:
#localize("scan_qr_code_sentence")
}
}
var icon: String {
switch self {
case .newMessage:
"square.and.pencil"
case .myID:
"person.crop.rectangle.fill"
case .scanQrCode:
"qrcode.viewfinder"
}
}
var type: String {
switch self {
case .newMessage:
"ch.threema.newmessage"
case .myID:
"ch.threema.myid"
case .scanQrCode:
"ch.threema.scanid"
}
}
var item: UIApplicationShortcutItem {
.init(
type: type,
localizedTitle: localizedTitle,
localizedSubtitle: nil,
icon: UIApplicationShortcutIcon(systemImageName: icon)
)
}
}
/// This method will return an array of shortcut items that are displayed on the home screen.
///
/// - Parameter mdm: used for dynamic shortcut items
/// - Returns: an array of shortcut items
static func items(for mdm: MDMSetup) -> [UIApplicationShortcutItem] {
var items: [ActionType] = [.newMessage, .myID]
if !mdm.disableAddContact() {
items.append(.scanQrCode)
}
return items.map(\.item)
}
}
¤ Dauer der Verarbeitung: 0.9 Sekunden
¤
*© Formatika GbR, Deutschland