Improve windows handling on macOS

This commit is contained in:
Arkadiusz Fal
2022-01-06 16:35:45 +01:00
parent 3baa7a6893
commit 8a74938b98
7 changed files with 91 additions and 59 deletions

View File

@@ -14,7 +14,7 @@ struct OpenURLHandler {
}
#if os(macOS)
guard url.host != OpenWindow.player.location else {
guard url.host != Windows.player.location else {
return
}
#endif
@@ -28,7 +28,7 @@ struct OpenURLHandler {
}
#if os(macOS)
OpenWindow.main.open()
Windows.main.open()
#endif
accounts.api.video(id).load().onSuccess { response in

View File

@@ -47,12 +47,18 @@ struct YatteeApp: App {
.environmentObject(thumbnails)
.environmentObject(menu)
.environmentObject(search)
#if !os(macOS)
.onReceive(
NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)
) { _ in
player.handleEnterForeground()
}
#if os(macOS)
.background(
HostingWindowFinder { window in
Windows.mainWindow = window
}
)
#else
.onReceive(
NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)
) { _ in
player.handleEnterForeground()
}
#endif
#if os(iOS)
.handlesExternalEvents(preferring: Set(["*"]), allowing: Set(["*"]))
@@ -81,6 +87,11 @@ struct YatteeApp: App {
#if os(macOS)
WindowGroup(player.windowTitle) {
VideoPlayerView()
.background(
HostingWindowFinder { window in
Windows.playerWindow = window
}
)
.onAppear { player.presentingPlayer = true }
.onDisappear { player.presentingPlayer = false }
.environment(\.managedObjectContext, persistenceController.container.viewContext)