IceCubes/IceCubesApp/App/Main/IceCubesApp+Scene.swift

112 lines
3.9 KiB
Swift
Raw Normal View History

2023-10-26 06:23:00 +02:00
import Env
import MediaUI
2023-11-01 18:58:44 +01:00
import Status
import SwiftUI
2023-10-26 06:23:00 +02:00
extension IceCubesApp {
var appScene: some Scene {
WindowGroup(id: "MainWindow") {
AppView(selectedTab: $selectedTab, appRouterPath: $appRouterPath)
2023-10-26 06:23:00 +02:00
.applyTheme(theme)
.onAppear {
setNewClientsInEnv(client: appAccountsManager.currentClient)
setupRevenueCat()
refreshPushSubs()
}
.environment(appAccountsManager)
.environment(appAccountsManager.currentClient)
.environment(quickLook)
.environment(currentAccount)
.environment(currentInstance)
.environment(userPreferences)
.environment(theme)
.environment(watcher)
.environment(pushNotificationsService)
.environment(\.isSupporter, isSupporter)
.sheet(item: $quickLook.selectedMediaAttachment) { selectedMediaAttachment in
MediaUIView(selectedAttachment: selectedMediaAttachment,
attachments: quickLook.mediaAttachments)
2023-11-01 18:58:44 +01:00
.presentationBackground(.ultraThinMaterial)
.presentationCornerRadius(16)
.withEnvironments()
2023-10-26 06:23:00 +02:00
}
.onChange(of: pushNotificationsService.handledNotification) { _, newValue in
if newValue != nil {
pushNotificationsService.handledNotification = nil
if appAccountsManager.currentAccount.oauthToken?.accessToken != newValue?.account.token.accessToken,
let account = appAccountsManager.availableAccounts.first(where:
{ $0.oauthToken?.accessToken == newValue?.account.token.accessToken })
{
appAccountsManager.currentAccount = account
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
selectedTab = .notifications
pushNotificationsService.handledNotification = newValue
}
} else {
selectedTab = .notifications
}
}
}
.withModelContainer()
}
.commands {
appMenu
}
.onChange(of: scenePhase) { _, newValue in
handleScenePhase(scenePhase: newValue)
}
.onChange(of: appAccountsManager.currentClient) { _, newValue in
setNewClientsInEnv(client: newValue)
if newValue.isAuth {
watcher.watch(streams: [.user, .direct])
}
}
}
2023-11-14 19:48:14 +01:00
@SceneBuilder
2023-10-26 06:23:00 +02:00
var otherScenes: some Scene {
2023-11-14 19:48:14 +01:00
WindowGroup(for: WindowDestinationEditor.self) { destination in
2023-10-26 06:23:00 +02:00
Group {
switch destination.wrappedValue {
case let .newStatusEditor(visibility):
2024-01-06 18:43:26 +01:00
StatusEditor.MainView(mode: .new(visibility: visibility))
2023-10-26 06:23:00 +02:00
case let .editStatusEditor(status):
2024-01-06 18:43:26 +01:00
StatusEditor.MainView(mode: .edit(status: status))
2023-10-26 06:23:00 +02:00
case let .quoteStatusEditor(status):
2024-01-06 18:43:26 +01:00
StatusEditor.MainView(mode: .quote(status: status))
2023-10-26 06:23:00 +02:00
case let .replyToStatusEditor(status):
2024-01-06 18:43:26 +01:00
StatusEditor.MainView(mode: .replyTo(status: status))
2024-01-03 13:40:53 +01:00
case let .mentionStatusEditor(account, visibility):
2024-01-06 18:43:26 +01:00
StatusEditor.MainView(mode: .mention(account: account, visibility: visibility))
2023-11-14 19:48:14 +01:00
case .none:
EmptyView()
}
}
.withEnvironments()
.withModelContainer()
.applyTheme(theme)
.frame(minWidth: 300, minHeight: 400)
}
.defaultSize(width: 600, height: 800)
.windowResizability(.contentMinSize)
2023-12-18 08:22:59 +01:00
2023-11-14 19:48:14 +01:00
WindowGroup(for: WindowDestinationMedia.self) { destination in
Group {
switch destination.wrappedValue {
2023-10-26 06:23:00 +02:00
case let .mediaViewer(attachments, selectedAttachment):
MediaUIView(selectedAttachment: selectedAttachment,
attachments: attachments)
case .none:
EmptyView()
}
}
.withEnvironments()
.withModelContainer()
.applyTheme(theme)
2023-11-14 19:48:14 +01:00
.frame(minWidth: 300, minHeight: 400)
2023-10-26 06:23:00 +02:00
}
2023-11-14 19:48:14 +01:00
.defaultSize(width: 1200, height: 1000)
.windowResizability(.contentMinSize)
2023-10-26 06:23:00 +02:00
}
}