IceCubes/IceCubesApp/App/IceCubesApp.swift

82 lines
2.5 KiB
Swift
Raw Normal View History

2022-12-01 09:05:26 +01:00
import SwiftUI
import Timeline
import Network
import KeychainSwift
2022-12-22 10:53:36 +01:00
import Env
2022-12-24 14:55:04 +01:00
import DesignSystem
2022-12-01 09:05:26 +01:00
@main
struct IceCubesApp: App {
2022-12-24 11:50:05 +01:00
enum Tab: Int {
case timeline, notifications, explore, account, settings, other
}
2022-12-17 13:37:46 +01:00
public static let defaultServer = "mastodon.social"
2022-12-24 14:55:04 +01:00
2022-12-01 09:05:26 +01:00
@StateObject private var appAccountsManager = AppAccountsManager()
2022-12-22 11:19:56 +01:00
@StateObject private var currentAccount = CurrentAccount()
2022-12-22 10:53:36 +01:00
@StateObject private var quickLook = QuickLook()
2022-12-24 14:55:04 +01:00
@StateObject private var theme = Theme()
2022-12-24 11:50:05 +01:00
@State private var selectedTab: Tab = .timeline
@State private var popToRootTab: Tab = .other
2022-12-01 09:05:26 +01:00
var body: some Scene {
WindowGroup {
2022-12-24 11:50:05 +01:00
TabView(selection: .init(get: {
selectedTab
}, set: { newTab in
if newTab == selectedTab {
/// Stupid hack to trigger onChange binding in tab views.
popToRootTab = .other
DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
popToRootTab = selectedTab
}
}
selectedTab = newTab
})) {
TimelineTab(popToRootTab: $popToRootTab)
2022-12-01 09:05:26 +01:00
.tabItem {
Label("Timeline", systemImage: "rectangle.on.rectangle")
2022-12-01 09:05:26 +01:00
}
2022-12-24 11:50:05 +01:00
.tag(Tab.timeline)
2022-12-20 15:37:51 +01:00
if appAccountsManager.currentClient.isAuth {
2022-12-24 11:50:05 +01:00
NotificationsTab(popToRootTab: $popToRootTab)
2022-12-20 15:37:51 +01:00
.tabItem {
Label("Notifications", systemImage: "bell")
}
2022-12-24 11:50:05 +01:00
.tag(Tab.notifications)
ExploreTab(popToRootTab: $popToRootTab)
.tabItem {
Label("Explore", systemImage: "magnifyingglass")
}
2022-12-24 11:50:05 +01:00
.tag(Tab.explore)
AccountTab(popToRootTab: $popToRootTab)
2022-12-20 16:08:09 +01:00
.tabItem {
Label("Profile", systemImage: "person.circle")
}
2022-12-24 11:50:05 +01:00
.tag(Tab.account)
2022-12-20 15:37:51 +01:00
}
2022-12-01 09:05:26 +01:00
SettingsTabs()
.tabItem {
Label("Settings", systemImage: "gear")
}
2022-12-24 11:50:05 +01:00
.tag(Tab.settings)
2022-12-01 09:05:26 +01:00
}
2022-12-24 14:55:04 +01:00
.tint(theme.tintColor)
2022-12-22 11:19:56 +01:00
.onChange(of: appAccountsManager.currentClient) { newClient in
currentAccount.setClient(client: newClient)
}
.onAppear {
currentAccount.setClient(client: appAccountsManager.currentClient)
}
2022-12-01 09:05:26 +01:00
.environmentObject(appAccountsManager)
.environmentObject(appAccountsManager.currentClient)
2022-12-22 10:53:36 +01:00
.environmentObject(quickLook)
2022-12-22 11:19:56 +01:00
.environmentObject(currentAccount)
2022-12-24 14:55:04 +01:00
.environmentObject(theme)
2022-12-22 11:19:56 +01:00
.quickLookPreview($quickLook.url, in: quickLook.urls)
2022-12-01 09:05:26 +01:00
}
}
}