If you look at the definition of AppShortcutsProvider, you see it a {get} and it uses @AppShortcutsBuilder for special formatting of the shortcuts. So, you'll have to eternalize your conditional definition of appshortcuts.
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
public protocol AppShortcutsProvider {
@AppShortcutsBuilder static var appShortcuts: [AppShortcut] { get }
/// The background color of the tile that Shortcuts displays for each of the app's App Shortcuts.
static var shortcutTileColor: ShortcutTileColor { get }
}
Here's one way to accomplish this:
struct EventManagerShortcuts: AppShortcutsProvider {
static var shortcutTileColor: ShortcutTileColor = .lime
// Max 10 shortcut actions per App. We need to make them dynamic by role and condition.
static var appShortcuts: [AppShortcut] {
return EventManagerShortcuts().createAppShortcuts()
}
private func createAppShortcuts() ->[AppShortcut] {
var appshortcuts = [AppShortcut]()
// Access the ViewModel
let viewModel = HomePage()
// Filter the objects we want to show as Shortcuts
let activeHomePageElements = viewModel.homePageElements
.filter({
$0.systemState != .idle &&
$0.userState != .idle
})
//. use std syntax for the loop to create shortcuts
for element in activeHomePageElements {
switch element.action {
case .AssignAgenda:
let NextMeetingShortcutPhrases : [AppShortcutPhrase<NextMeetingShortcut>] = [
"Start a business event with \(.applicationName)",
"\(.applicationName) business meeting",
"Event for \(.applicationName)",
"Start a Salesforce event with \(.applicationName)"
]
let nextMeetingShortcut = AppShortcut(intent: NextMeetingShortcut(),
phrases: NextMeetingShortcutPhrases,
// shortcutsUIButton(style: .darkOutline)
// shortcutTileColor: Color.green,
shortTitle: "Next Business Meeting",
systemImageName: "person.3")
appshortcuts.append(nextMeetingShortcut)
case .PrepareEvents:
break
............ Etc.
}
}
return appshortcuts
}
}