Skip to content

Commit

Permalink
Merge pull request #1201 from TortugaPower/fix-widgets-ios17
Browse files Browse the repository at this point in the history
Fix crash for widgets on iOS 17
  • Loading branch information
GianniCarlo authored Oct 9, 2024
2 parents 4e66760 + 3a428ad commit 11ab829
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 29 deletions.
1 change: 1 addition & 0 deletions BookPlayer/Profile/Profile Screen/ProfileViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class ProfileViewModel: ProfileViewModelProtocol {
.store(in: &disposeBag)

NotificationCenter.default.publisher(for: .bookPaused, object: nil)
.receive(on: DispatchQueue.main)
.sink(receiveValue: { [weak self] _ in
self?.reloadListenedTime()
})
Expand Down
73 changes: 44 additions & 29 deletions BookPlayerWidgets/BookPlayerWidgets.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,57 @@ import WidgetKit
import BookPlayerKit
#endif

@main
struct BookPlayerBundle {
static func main() {
#if os(iOS)
struct BookPlayerWidgetUI_Previews: PreviewProvider {
static var previews: some View {
Group {
LastPlayedWidgetView(
entry: .init(
date: Date(),
items: [
.init(relativePath: "path1", title: "Test Book Title")
],
currentlyPlaying: nil
)
)
.previewContext(WidgetPreviewContext(family: .systemSmall))
}
if #available(iOSApplicationExtension 18.0, *) {
IOSWidgetsBundle18.main()
} else if #available(iOSApplicationExtension 16.1, *) {
IOSWidgetsBundle16.main()
} else {
IOSWidgetsBundle.main()
}
}
#elseif os(watchOS)
WatchWidgetsBundle.main()
#endif
}

@main
struct BookPlayerBundle: WidgetBundle {
@WidgetBundleBuilder
var body: some Widget {
#if os(iOS)
#if os(iOS)
struct IOSWidgetsBundle: WidgetBundle {
var body: some Widget {
LastPlayedWidget()
TimeListenedWidget()
}
}

@available(iOSApplicationExtension 16.1, *)
struct IOSWidgetsBundle16: WidgetBundle {
var body: some Widget {
LastPlayedWidget()
TimeListenedWidget()
SharedWidget()
SharedIconWidget()
}
}

@available(iOSApplicationExtension 18.0, *)
struct IOSWidgetsBundle18: WidgetBundle {
var body: some Widget {
LastPlayedWidget()
TimeListenedWidget()
if #available(iOSApplicationExtension 16.1, *) {
SharedWidget()
SharedIconWidget()
}
if #available(iOSApplicationExtension 18.0, *) {
PlayLastControlWidgetView()
}
#elseif os(watchOS)
SharedWidget()
SharedIconWidget()
#endif
PlayLastControlWidgetView()
}
}

#elseif os(watchOS)
struct WatchWidgetsBundle: WidgetBundle {
var body: some Widget {
SharedWidget()
SharedIconWidget()
}
}
#endif
}

0 comments on commit 11ab829

Please sign in to comment.