From 1a3df617f2259b98d9be68e5e0737a7bc54eac74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Menu?= Date: Wed, 28 Aug 2024 16:21:21 +0200 Subject: [PATCH 1/2] Make some deprecated APIs unavailable --- Sources/Navigator/EditingAction.swift | 2 +- Sources/Navigator/TTS/AVTTSEngine.swift | 2 +- Sources/Shared/Publication/Link.swift | 24 ++++--------------- Sources/Shared/Publication/Manifest.swift | 12 ++-------- Sources/Shared/Publication/Properties.swift | 2 +- Sources/Shared/Publication/Publication.swift | 3 +-- .../Toolkit/Data/Resource/Resource.swift | 4 ++-- .../Shared/Toolkit/Media/AudioSession.swift | 4 ++-- .../Shared/Toolkit/Media/NowPlayingInfo.swift | 2 +- 9 files changed, 15 insertions(+), 40 deletions(-) diff --git a/Sources/Navigator/EditingAction.swift b/Sources/Navigator/EditingAction.swift index d9ae52300..d7738f4a6 100644 --- a/Sources/Navigator/EditingAction.swift +++ b/Sources/Navigator/EditingAction.swift @@ -31,7 +31,7 @@ public struct EditingAction: Hashable { /// Search Web. public static let lookup = EditingAction(kind: .native(["lookup", "_lookup:", "define:", "_define:"])) - @available(*, deprecated, message: "lookup and define were merged", renamed: "lookup") + @available(*, unavailable, message: "lookup and define were merged", renamed: "lookup") public static let define = lookup /// Translate the text selection. diff --git a/Sources/Navigator/TTS/AVTTSEngine.swift b/Sources/Navigator/TTS/AVTTSEngine.swift index c93d355dc..145323a83 100644 --- a/Sources/Navigator/TTS/AVTTSEngine.swift +++ b/Sources/Navigator/TTS/AVTTSEngine.swift @@ -47,7 +47,7 @@ public class AVTTSEngine: NSObject, TTSEngine, AVSpeechSynthesizerDelegate, Logg synthesizer.delegate = self } - @available(*, deprecated, message: "The audio session is now configured through the `PublicationSpeechSynthesizer`") + @available(*, unavailable, message: "The audio session is now configured through the `PublicationSpeechSynthesizer`") public convenience init( audioSessionConfig: AudioSession.Configuration? = nil, delegate: AVTTSEngineDelegate? = nil diff --git a/Sources/Shared/Publication/Link.swift b/Sources/Shared/Publication/Link.swift index 9111c84c3..2ba3937f9 100644 --- a/Sources/Shared/Publication/Link.swift +++ b/Sources/Shared/Publication/Link.swift @@ -206,7 +206,7 @@ public struct Link: JSONEquatable, Hashable, Sendable { // MARK: Copy - @available(*, deprecated, message: "Make a mutable copy of the struct instead") + @available(*, unavailable, message: "Make a mutable copy of the struct instead") /// Makes a copy of the `Link`, after modifying some of its properties. public func copy( href: String? = nil, @@ -223,21 +223,7 @@ public struct Link: JSONEquatable, Hashable, Sendable { alternates: [Link]? = nil, children: [Link]? = nil ) -> Link { - Link( - href: href ?? self.href, - mediaType: mediaType ?? self.mediaType, - templated: templated ?? self.templated, - title: title ?? self.title, - rels: rels ?? self.rels, - properties: properties ?? self.properties, - height: height ?? self.height, - width: width ?? self.width, - bitrate: bitrate ?? self.bitrate, - duration: duration ?? self.duration, - languages: languages ?? self.languages, - alternates: alternates ?? self.alternates, - children: children ?? self.children - ) + fatalError() } /// Merges in the given additional other `properties`. @@ -246,11 +232,9 @@ public struct Link: JSONEquatable, Hashable, Sendable { } /// Makes a copy of this `Link` after merging in the given additional other `properties`. - @available(*, deprecated, message: "Use `addProperties` on a mutable copy") + @available(*, unavailable, message: "Use `addProperties` on a mutable copy") public func addingProperties(_ properties: [String: Any]) -> Link { - var copy = self - copy.addProperties(properties) - return copy + fatalError() } } diff --git a/Sources/Shared/Publication/Manifest.swift b/Sources/Shared/Publication/Manifest.swift index 3c2739418..c1c5e09f8 100644 --- a/Sources/Shared/Publication/Manifest.swift +++ b/Sources/Shared/Publication/Manifest.swift @@ -186,7 +186,7 @@ public struct Manifest: JSONEquatable, Hashable, Sendable { } /// Makes a copy of the `Manifest`, after modifying some of its properties. - @available(*, deprecated, message: "Make a mutable copy of the struct instead") + @available(*, unavailable, message: "Make a mutable copy of the struct instead") public func copy( context: [String]? = nil, metadata: Metadata? = nil, @@ -196,14 +196,6 @@ public struct Manifest: JSONEquatable, Hashable, Sendable { tableOfContents: [Link]? = nil, subcollections: [String: [PublicationCollection]]? = nil ) -> Manifest { - Manifest( - context: context ?? self.context, - metadata: metadata ?? self.metadata, - links: links ?? self.links, - readingOrder: readingOrder ?? self.readingOrder, - resources: resources ?? self.resources, - tableOfContents: tableOfContents ?? self.tableOfContents, - subcollections: subcollections ?? self.subcollections - ) + fatalError() } } diff --git a/Sources/Shared/Publication/Properties.swift b/Sources/Shared/Publication/Properties.swift index ca8a28621..dbbd159ad 100644 --- a/Sources/Shared/Publication/Properties.swift +++ b/Sources/Shared/Publication/Properties.swift @@ -50,7 +50,7 @@ public struct Properties: Hashable, Loggable, WarningLogger, Sendable { } /// Makes a copy of this `Properties` after merging in the given additional other `properties`. - @available(*, deprecated, message: "Use `add` on a mutable copy") + @available(*, unavailable, message: "Use `add` on a mutable copy") public func adding(_ properties: JSONDictionary.Wrapped) -> Properties { var copy = self copy.add(properties) diff --git a/Sources/Shared/Publication/Publication.swift b/Sources/Shared/Publication/Publication.swift index 2c8053ac9..c4640d22f 100644 --- a/Sources/Shared/Publication/Publication.swift +++ b/Sources/Shared/Publication/Publication.swift @@ -225,8 +225,7 @@ public class Publication: Closeable, Loggable { public init( manifest: Manifest, container: Container, - servicesBuilder: PublicationServicesBuilder = .init(), - setupPublication: ((Publication) -> Void)? = nil + servicesBuilder: PublicationServicesBuilder = .init() ) { self.manifest = manifest self.container = container diff --git a/Sources/Shared/Toolkit/Data/Resource/Resource.swift b/Sources/Shared/Toolkit/Data/Resource/Resource.swift index f9cca1846..58bd2261b 100644 --- a/Sources/Shared/Toolkit/Data/Resource/Resource.swift +++ b/Sources/Shared/Toolkit/Data/Resource/Resource.swift @@ -24,13 +24,13 @@ public extension Resource { @available(*, unavailable, message: "Use the async variant") var length: ResourceResult { fatalError() } - @available(*, deprecated, renamed: "sourceURL") + @available(*, unavailable, renamed: "sourceURL") var file: FileURL? { fatalError() } @available(*, unavailable, message: "Use the async variant") func read(range: Range?) -> ResourceResult { fatalError() } - @available(*, deprecated, message: "Use the async variant") + @available(*, unavailable, message: "Use the async variant") func stream(range: Range?, consume: @escaping (Data) -> Void, completion: @escaping (ReadResult) -> Void) -> Cancellable { fatalError() } diff --git a/Sources/Shared/Toolkit/Media/AudioSession.swift b/Sources/Shared/Toolkit/Media/AudioSession.swift index d91779abc..6d9ef070f 100644 --- a/Sources/Shared/Toolkit/Media/AudioSession.swift +++ b/Sources/Shared/Toolkit/Media/AudioSession.swift @@ -8,9 +8,9 @@ import AVFoundation import Foundation import UIKit -@available(*, deprecated, message: "Use `AudioSession` instead") +@available(*, unavailable, message: "Use `AudioSession` instead") public typealias _AudioSession = AudioSession -@available(*, deprecated, message: "Use `AudioSessionUser` instead") +@available(*, unavailable, message: "Use `AudioSessionUser` instead") public typealias _AudioSessionUser = AudioSessionUser /// An user of the `AudioSession`, for example a media player object. diff --git a/Sources/Shared/Toolkit/Media/NowPlayingInfo.swift b/Sources/Shared/Toolkit/Media/NowPlayingInfo.swift index 78db22191..0f45e09e3 100644 --- a/Sources/Shared/Toolkit/Media/NowPlayingInfo.swift +++ b/Sources/Shared/Toolkit/Media/NowPlayingInfo.swift @@ -8,7 +8,7 @@ import Foundation import MediaPlayer import UIKit -@available(*, deprecated, message: "Use `NowPlayingInfo` instead") +@available(*, unavailable, message: "Use `NowPlayingInfo` instead") public typealias _NowPlayingInfo = NowPlayingInfo /// Manages the Now Playing media item displayed on the lock screen. From c403de1b360b417eb6d772e04524497a817c4db9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Menu?= Date: Wed, 28 Aug 2024 16:49:36 +0200 Subject: [PATCH 2/2] Fix iOS 13 warnings --- .../LCPDialogViewController.swift | 7 ++++++- Sources/Navigator/EPUB/EPUBSpreadView.swift | 21 +++++++------------ .../Navigator/Toolkit/Extensions/UIView.swift | 8 +++++-- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/Sources/LCP/Authentications/LCPDialogViewController.swift b/Sources/LCP/Authentications/LCPDialogViewController.swift index 1ac326e85..d09bdecab 100644 --- a/Sources/LCP/Authentications/LCPDialogViewController.swift +++ b/Sources/LCP/Authentications/LCPDialogViewController.swift @@ -183,7 +183,12 @@ final class LCPDialogViewController: UIViewController { /// Makes sure the form contents is scrollable when the keyboard is visible. @objc func keyboardWillChangeFrame(_ note: Notification) { - guard let window = UIApplication.shared.keyWindow, let scrollView = scrollView, let scrollViewSuperview = scrollView.superview, let info = note.userInfo else { + guard + let window = view.window, + let scrollView = scrollView, + let scrollViewSuperview = scrollView.superview, + let info = note.userInfo + else { return } diff --git a/Sources/Navigator/EPUB/EPUBSpreadView.swift b/Sources/Navigator/EPUB/EPUBSpreadView.swift index c870004ef..94f075487 100644 --- a/Sources/Navigator/EPUB/EPUBSpreadView.swift +++ b/Sources/Navigator/EPUB/EPUBSpreadView.swift @@ -495,15 +495,7 @@ extension EPUBSpreadView: UIScrollViewDelegate { } } -extension EPUBSpreadView: WKUIDelegate { - func webView(_ webView: WKWebView, shouldPreviewElement elementInfo: WKPreviewElementInfo) -> Bool { - // Preview allowed only if the link is not internal - guard let url = elementInfo.linkURL?.httpURL else { - return true - } - return url.isRelative(to: viewModel.publicationBaseURL) - } -} +extension EPUBSpreadView: WKUIDelegate {} extension EPUBSpreadView: UIGestureRecognizerDelegate { func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRequireFailureOf otherGestureRecognizer: UIGestureRecognizer) -> Bool { @@ -517,19 +509,20 @@ private extension EPUBSpreadView { func updateActivityIndicator() { switch viewModel.theme { case .dark: - createActivityIndicator(style: .white) + createActivityIndicator(color: .white) default: - createActivityIndicator(style: .gray) + createActivityIndicator(color: .systemGray) } } - func createActivityIndicator(style: UIActivityIndicatorView.Style) { - guard activityIndicatorView?.style != style else { + func createActivityIndicator(color: UIColor) { + guard activityIndicatorView?.color != color else { return } activityIndicatorView?.removeFromSuperview() - let view = UIActivityIndicatorView(style: style) + let view = UIActivityIndicatorView(style: .medium) + view.color = color view.translatesAutoresizingMaskIntoConstraints = false addSubview(view) view.centerXAnchor.constraint(equalTo: centerXAnchor).isActive = true diff --git a/Sources/Navigator/Toolkit/Extensions/UIView.swift b/Sources/Navigator/Toolkit/Extensions/UIView.swift index 7d6e0e8a2..152f6ea4a 100644 --- a/Sources/Navigator/Toolkit/Extensions/UIView.swift +++ b/Sources/Navigator/Toolkit/Extensions/UIView.swift @@ -18,11 +18,15 @@ extension UIView { /// We use that instead of pinning the content directly to the safe area layout guides to avoid /// the view shifting when the status bar is toggled. var notchAreaInsets: UIEdgeInsets { - var windowSafeAreaInsets = window?.safeAreaInsets ?? safeAreaInsets + guard let window = window else { + return safeAreaInsets + } + + var windowSafeAreaInsets = window.safeAreaInsets // Trick to ignore the status bar on devices without notches (pre iPhone X). // Notch height is usually at least 44pts tall. - let statusBarSize = UIApplication.shared.statusBarFrame.size + let statusBarSize = window.windowScene?.statusBarManager?.statusBarFrame.size ?? .zero // The frame is in the coordinate space of the window, so it might be swapped in landscape. let statusBarHeight = min(statusBarSize.width, statusBarSize.height) if statusBarHeight < 44, windowSafeAreaInsets.top == statusBarHeight {