2021-09-25 08:18:22 +00:00
|
|
|
import Defaults
|
2021-06-09 20:51:23 +00:00
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
@main
|
2021-11-07 13:32:01 +00:00
|
|
|
struct YatteeApp: App {
|
2022-01-06 15:02:53 +00:00
|
|
|
static var version: String {
|
|
|
|
Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "unknown"
|
|
|
|
}
|
|
|
|
|
|
|
|
static var build: String {
|
|
|
|
Bundle.main.infoDictionary?["CFBundleVersion"] as? String ?? "unknown"
|
|
|
|
}
|
|
|
|
|
2021-10-24 09:16:04 +00:00
|
|
|
#if os(macOS)
|
|
|
|
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
|
2021-12-07 23:09:49 +00:00
|
|
|
@StateObject private var updater = UpdaterModel()
|
2022-01-02 19:41:04 +00:00
|
|
|
#elseif os(iOS)
|
|
|
|
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
|
2021-10-24 09:16:04 +00:00
|
|
|
#endif
|
|
|
|
|
2021-12-19 17:17:04 +00:00
|
|
|
@StateObject private var accounts = AccountsModel()
|
|
|
|
@StateObject private var comments = CommentsModel()
|
|
|
|
@StateObject private var instances = InstancesModel()
|
2021-11-08 23:14:28 +00:00
|
|
|
@StateObject private var menu = MenuModel()
|
2021-12-19 17:17:04 +00:00
|
|
|
@StateObject private var navigation = NavigationModel()
|
|
|
|
@StateObject private var player = PlayerModel()
|
2022-02-16 20:23:11 +00:00
|
|
|
@StateObject private var playerControls = PlayerControlsModel()
|
2021-12-19 17:17:04 +00:00
|
|
|
@StateObject private var playlists = PlaylistsModel()
|
|
|
|
@StateObject private var recents = RecentsModel()
|
|
|
|
@StateObject private var search = SearchModel()
|
|
|
|
@StateObject private var subscriptions = SubscriptionsModel()
|
|
|
|
@StateObject private var thumbnails = ThumbnailsModel()
|
2021-11-08 23:14:28 +00:00
|
|
|
|
2021-12-26 21:14:46 +00:00
|
|
|
let persistenceController = PersistenceController.shared
|
|
|
|
|
2021-06-09 20:51:23 +00:00
|
|
|
var body: some Scene {
|
|
|
|
WindowGroup {
|
|
|
|
ContentView()
|
2021-12-26 21:14:46 +00:00
|
|
|
.environment(\.managedObjectContext, persistenceController.container.viewContext)
|
2021-12-19 17:17:04 +00:00
|
|
|
.environmentObject(accounts)
|
|
|
|
.environmentObject(comments)
|
|
|
|
.environmentObject(instances)
|
|
|
|
.environmentObject(navigation)
|
|
|
|
.environmentObject(player)
|
2022-02-16 20:23:11 +00:00
|
|
|
.environmentObject(playerControls)
|
2021-12-19 17:17:04 +00:00
|
|
|
.environmentObject(playlists)
|
|
|
|
.environmentObject(recents)
|
|
|
|
.environmentObject(subscriptions)
|
|
|
|
.environmentObject(thumbnails)
|
2021-11-08 23:14:28 +00:00
|
|
|
.environmentObject(menu)
|
2021-12-19 17:17:04 +00:00
|
|
|
.environmentObject(search)
|
2022-01-06 15:35:45 +00:00
|
|
|
#if os(macOS)
|
|
|
|
.background(
|
|
|
|
HostingWindowFinder { window in
|
|
|
|
Windows.mainWindow = window
|
|
|
|
}
|
|
|
|
)
|
|
|
|
#else
|
|
|
|
.onReceive(
|
|
|
|
NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)
|
|
|
|
) { _ in
|
|
|
|
player.handleEnterForeground()
|
|
|
|
}
|
2021-12-19 17:17:04 +00:00
|
|
|
#endif
|
2021-12-24 19:20:05 +00:00
|
|
|
#if os(iOS)
|
|
|
|
.handlesExternalEvents(preferring: Set(["*"]), allowing: Set(["*"]))
|
2021-12-19 17:17:04 +00:00
|
|
|
#endif
|
2021-06-09 20:51:23 +00:00
|
|
|
}
|
2021-12-24 19:20:05 +00:00
|
|
|
#if os(iOS)
|
|
|
|
.handlesExternalEvents(matching: Set(["*"]))
|
|
|
|
#endif
|
2021-07-27 22:40:04 +00:00
|
|
|
#if !os(tvOS)
|
2021-11-08 16:29:35 +00:00
|
|
|
.commands {
|
|
|
|
SidebarCommands()
|
2021-12-07 23:09:49 +00:00
|
|
|
|
2021-11-08 16:29:35 +00:00
|
|
|
CommandGroup(replacing: .newItem, addition: {})
|
2021-12-07 23:09:49 +00:00
|
|
|
|
|
|
|
#if os(macOS)
|
|
|
|
CommandGroup(after: .appInfo) {
|
|
|
|
CheckForUpdatesView()
|
|
|
|
.environmentObject(updater)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-11-08 23:14:28 +00:00
|
|
|
MenuCommands(model: Binding<MenuModel>(get: { menu }, set: { _ in }))
|
2021-11-08 16:29:35 +00:00
|
|
|
}
|
2021-07-27 22:40:04 +00:00
|
|
|
#endif
|
2021-09-25 08:18:22 +00:00
|
|
|
|
|
|
|
#if os(macOS)
|
2021-12-19 17:17:04 +00:00
|
|
|
WindowGroup(player.windowTitle) {
|
|
|
|
VideoPlayerView()
|
2022-01-06 15:35:45 +00:00
|
|
|
.background(
|
|
|
|
HostingWindowFinder { window in
|
|
|
|
Windows.playerWindow = window
|
|
|
|
}
|
|
|
|
)
|
2021-12-19 17:17:04 +00:00
|
|
|
.onAppear { player.presentingPlayer = true }
|
|
|
|
.onDisappear { player.presentingPlayer = false }
|
2021-12-26 21:14:46 +00:00
|
|
|
.environment(\.managedObjectContext, persistenceController.container.viewContext)
|
2021-12-19 17:17:04 +00:00
|
|
|
.environment(\.navigationStyle, .sidebar)
|
|
|
|
.environmentObject(accounts)
|
|
|
|
.environmentObject(comments)
|
|
|
|
.environmentObject(instances)
|
|
|
|
.environmentObject(navigation)
|
|
|
|
.environmentObject(player)
|
2022-02-16 20:23:11 +00:00
|
|
|
.environmentObject(playerControls)
|
2021-12-19 17:17:04 +00:00
|
|
|
.environmentObject(playlists)
|
|
|
|
.environmentObject(recents)
|
|
|
|
.environmentObject(subscriptions)
|
|
|
|
.environmentObject(thumbnails)
|
2021-12-24 19:20:05 +00:00
|
|
|
.handlesExternalEvents(preferring: Set(["player", "*"]), allowing: Set(["player", "*"]))
|
2021-12-19 17:17:04 +00:00
|
|
|
}
|
2021-12-24 19:20:05 +00:00
|
|
|
.handlesExternalEvents(matching: Set(["player", "*"]))
|
2021-12-19 17:17:04 +00:00
|
|
|
|
2021-09-25 08:18:22 +00:00
|
|
|
Settings {
|
|
|
|
SettingsView()
|
2021-12-26 21:14:46 +00:00
|
|
|
.environment(\.managedObjectContext, persistenceController.container.viewContext)
|
2021-12-24 19:20:05 +00:00
|
|
|
.environmentObject(accounts)
|
|
|
|
.environmentObject(instances)
|
2021-12-26 21:14:46 +00:00
|
|
|
.environmentObject(player)
|
2022-02-16 20:23:11 +00:00
|
|
|
.environmentObject(playerControls)
|
2021-12-07 23:09:49 +00:00
|
|
|
.environmentObject(updater)
|
2021-09-25 08:18:22 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2021-06-09 20:51:23 +00:00
|
|
|
}
|