IceCubes/IceCubesAppIntents/TabIntent.swift

90 lines
2.3 KiB
Swift
Raw Normal View History

2024-05-02 11:37:38 +02:00
import AppIntents
2024-05-04 13:19:19 +02:00
import Foundation
2024-05-02 11:37:38 +02:00
enum TabEnum: String, AppEnum, Sendable {
case timeline, notifications, mentions, explore, messages, settings
case trending, federated, local
case profile
case bookmarks
case favorites
case post
case followedTags
case lists
case links
2024-05-04 13:19:19 +02:00
static var typeDisplayName: LocalizedStringResource { "Tab" }
2024-05-02 11:37:38 +02:00
static let typeDisplayRepresentation: TypeDisplayRepresentation = "Tab"
2024-05-04 13:19:19 +02:00
nonisolated static var caseDisplayRepresentations: [TabEnum: DisplayRepresentation] {
2024-05-02 11:37:38 +02:00
[.timeline: .init(title: "Home Timeline"),
.trending: .init(title: "Trending Timeline"),
.federated: .init(title: "Federated Timeline"),
.local: .init(title: "Local Timeline"),
.notifications: .init(title: "Notifications"),
.mentions: .init(title: "Mentions"),
.explore: .init(title: "Explore & Trending"),
.messages: .init(title: "Private Messages"),
.settings: .init(title: "Settings"),
.profile: .init(title: "Profile"),
.bookmarks: .init(title: "Bookmarks"),
.favorites: .init(title: "Favorites"),
.followedTags: .init(title: "Followed Tags"),
.lists: .init(title: "Lists"),
.links: .init(title: "Trending Links"),
2024-05-04 13:19:19 +02:00
.post: .init(title: "New post")]
2024-05-02 11:37:38 +02:00
}
2024-05-04 13:19:19 +02:00
2024-05-02 11:37:38 +02:00
var toAppTab: Tab {
switch self {
case .timeline:
2024-05-04 13:19:19 +02:00
.timeline
2024-05-02 11:37:38 +02:00
case .notifications:
2024-05-04 13:19:19 +02:00
.notifications
2024-05-02 11:37:38 +02:00
case .mentions:
2024-05-04 13:19:19 +02:00
.mentions
2024-05-02 11:37:38 +02:00
case .explore:
2024-05-04 13:19:19 +02:00
.explore
2024-05-02 11:37:38 +02:00
case .messages:
2024-05-04 13:19:19 +02:00
.messages
2024-05-02 11:37:38 +02:00
case .settings:
2024-05-04 13:19:19 +02:00
.settings
2024-05-02 11:37:38 +02:00
case .trending:
2024-05-04 13:19:19 +02:00
.trending
2024-05-02 11:37:38 +02:00
case .federated:
2024-05-04 13:19:19 +02:00
.federated
2024-05-02 11:37:38 +02:00
case .local:
2024-05-04 13:19:19 +02:00
.local
2024-05-02 11:37:38 +02:00
case .profile:
2024-05-04 13:19:19 +02:00
.profile
2024-05-02 11:37:38 +02:00
case .bookmarks:
2024-05-04 13:19:19 +02:00
.bookmarks
2024-05-02 11:37:38 +02:00
case .favorites:
2024-05-04 13:19:19 +02:00
.favorites
2024-05-02 11:37:38 +02:00
case .post:
2024-05-04 13:19:19 +02:00
.post
2024-05-02 11:37:38 +02:00
case .followedTags:
2024-05-04 13:19:19 +02:00
.followedTags
2024-05-02 11:37:38 +02:00
case .lists:
2024-05-04 13:19:19 +02:00
.lists
2024-05-02 11:37:38 +02:00
case .links:
2024-05-04 13:19:19 +02:00
.links
2024-05-02 11:37:38 +02:00
}
}
}
struct TabIntent: AppIntent {
static let title: LocalizedStringResource = "Open on a tab"
2024-05-05 13:12:19 +02:00
static let description: IntentDescription = "Open the app on a specific tab"
2024-05-02 11:37:38 +02:00
static let openAppWhenRun: Bool = true
2024-05-04 13:19:19 +02:00
2024-05-02 11:37:38 +02:00
@Parameter(title: "Selected tab")
var tab: TabEnum
2024-05-04 13:19:19 +02:00
2024-05-02 11:37:38 +02:00
@MainActor
func perform() async throws -> some IntentResult {
AppIntentService.shared.handledIntent = .init(intent: self)
return .result()
}
}