#442: a car's pick told the page `replaced`, and the page closed its player bar, so leaving the car with the episode playing left nothing on the phone to pause it. And when the car launched the app, the page loaded later and was never told anything played. Now the app sends `nowPlaying` (the item, its place, playing or not) on a car pick, at the page's `ready`, and on coming forward, and the page's bar takes it up and drives the phone's player. `replaced` is still handled for builds before this one. #443: Shows listed every feed with items, blogs included. Now only feeds with a downloaded file, and an episode only with a downloaded audio file: /media/{id} answers 404 before the download. #444: tests/native-bridge.ts read its failure count before the CarPlay checks, so those could fail and still exit 0. The count is read last now. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RqkrVARreS9wxzH5o2rF7N
This commit is contained in:
@@ -43,7 +43,12 @@ final class Bridge: NSObject, WKScriptMessageHandler {
|
||||
playback.onEnded = { [weak self] in self?.send(["t": "ended"]) }
|
||||
playback.onError = { [weak self] msg in self?.send(["t": "error", "message": msg]) }
|
||||
playback.onSlept = { [weak self] in self?.send(["t": "slept"]) }
|
||||
playback.onReplaced = { [weak self] in self?.send(["t": "replaced"]) }
|
||||
playback.onChosen = { [weak self] in self?.sendNowPlaying() }
|
||||
// Again on coming forward: a page frozen while the car chose may have missed it (#442).
|
||||
NotificationCenter.default.addObserver(forName: UIApplication.didBecomeActiveNotification, object: nil,
|
||||
queue: .main) { [weak self] _ in
|
||||
MainActor.assumeIsolated { self?.sendNowPlaying() }
|
||||
}
|
||||
Push.onToken = { [weak self] _ in self?.sendPush() }
|
||||
Offline.shared.onChange = { [weak self] in self?.sendKept() }
|
||||
Offline.shared.onFail = { [weak self] path, msg in
|
||||
@@ -57,6 +62,19 @@ final class Bridge: NSObject, WKScriptMessageHandler {
|
||||
"keeping": Offline.shared.downloading.sorted()])
|
||||
}
|
||||
|
||||
/// What is loaded, for the page's player bar to take up (#442): the car's pick, or an episode
|
||||
/// playing when the page loads, as when the app was opened from CarPlay. Without it the sound
|
||||
/// went on with no bar on the phone to pause it.
|
||||
private func sendNowPlaying() {
|
||||
guard let item = playback.current else { return }
|
||||
var m: [String: Any] = ["t": "nowPlaying", "feedId": item.feedId, "guid": item.guid, "enc": item.enc,
|
||||
"title": item.title, "feedTitle": item.feedTitle,
|
||||
"playing": playback.wantsToPlay, "cur": playback.currentTime]
|
||||
if let a = item.artwork { m["artwork"] = a }
|
||||
if let d = playback.duration ?? item.duration.map(Double.init) { m["dur"] = d }
|
||||
send(m)
|
||||
}
|
||||
|
||||
/// For the page to register with ipx (#433), at ready and whenever Apple gives a new one.
|
||||
private func sendPush() {
|
||||
guard let token = Push.token else { return }
|
||||
@@ -78,6 +96,7 @@ final class Bridge: NSObject, WKScriptMessageHandler {
|
||||
if let at = playback.sleepAt { send(["t": "sleep", "left": max(0, at.timeIntervalSinceNow)]) }
|
||||
sendKept()
|
||||
sendPush()
|
||||
sendNowPlaying()
|
||||
case "load":
|
||||
guard let path = m["url"] as? String, let url = Server.resolveForPlayer(path),
|
||||
let enc = m["enc"] as? Int,
|
||||
|
||||
@@ -13,6 +13,8 @@ struct CarEpisode: Decodable {
|
||||
let url: String
|
||||
let mime: String?
|
||||
let deadair: Double?
|
||||
/// Set once ipx has the file; `/media/{id}` answers 404 before that.
|
||||
let path: String?
|
||||
}
|
||||
|
||||
let guid: String
|
||||
@@ -23,10 +25,17 @@ struct CarEpisode: Decodable {
|
||||
let position: Double
|
||||
let enclosures: [Enclosure]
|
||||
|
||||
/// The file to play: the first that is not a video, which a car would only play the sound of
|
||||
/// with nothing to say so.
|
||||
/// The file to play: the first downloaded one that is sound (items.ts isPlayable, less video,
|
||||
/// which a car would play the sound of with nothing to say so). An item with none is not listed
|
||||
/// (#443): a post's picture or a file still to come is nothing a car can play.
|
||||
var audio: Enclosure? {
|
||||
enclosures.first { !($0.mime ?? "").lowercased().hasPrefix("video/") }
|
||||
enclosures.first { e in
|
||||
guard e.path != nil else { return false }
|
||||
let mime = (e.mime ?? "").lowercased()
|
||||
if !mime.isEmpty { return mime.hasPrefix("audio/") }
|
||||
let ext = URL(string: e.url)?.pathExtension.lowercased() ?? ""
|
||||
return ["mp3", "m4a", "m4b", "aac", "wav", "flac"].contains(ext)
|
||||
}
|
||||
}
|
||||
|
||||
/// Its title, or the file's name: a car's list cannot show the opening of a post as the
|
||||
@@ -66,6 +75,8 @@ struct CarFeed: Decodable {
|
||||
let image: String?
|
||||
let unread: Int?
|
||||
let entries: Int?
|
||||
/// Its files ipx has downloaded.
|
||||
let downloaded: Int?
|
||||
let group: String?
|
||||
|
||||
var name: String { title ?? id }
|
||||
@@ -166,13 +177,14 @@ final class CarScreen: NSObject, CPTabBarTemplateDelegate {
|
||||
}
|
||||
|
||||
/// Alphabetical, which a driver can find a show in without reading the whole list. Only
|
||||
/// shows with items: an OPML subscription's own row holds none, its feeds do.
|
||||
/// shows with files downloaded (#443): a blog has nothing a car can play, and an OPML
|
||||
/// subscription's own row holds no items, its feeds do.
|
||||
private func showFeeds() {
|
||||
guard !feeds.isEmpty else {
|
||||
unreachable(shows)
|
||||
return
|
||||
}
|
||||
let sorted = feeds.values.filter { ($0.entries ?? 0) > 0 }
|
||||
let sorted = feeds.values.filter { ($0.downloaded ?? 0) > 0 }
|
||||
.sorted { $0.name.localizedStandardCompare($1.name) == .orderedAscending }
|
||||
let rows: [CPListItem] = sorted.map { f in
|
||||
let n = f.unread ?? 0
|
||||
|
||||
@@ -29,8 +29,8 @@ final class Playback: NSObject {
|
||||
var onError: ((String) -> Void)?
|
||||
/// The sleep timer ran out and playback paused.
|
||||
var onSlept: (() -> Void)?
|
||||
/// Something the page did not choose is playing now: the car's pick (#420).
|
||||
var onReplaced: (() -> Void)?
|
||||
/// Something the page did not choose is loaded now: the car's pick (#420).
|
||||
var onChosen: (() -> Void)?
|
||||
|
||||
private let session: URLSession = {
|
||||
let cfg = URLSessionConfiguration.default
|
||||
@@ -55,6 +55,8 @@ final class Playback: NSObject {
|
||||
private(set) var sleepAt: Date?
|
||||
|
||||
var isPlaying: Bool { player?.timeControlStatus == .playing }
|
||||
/// Playing, or about to once it has buffered: what a player bar's button should say.
|
||||
var wantsToPlay: Bool { player.map { $0.timeControlStatus != .paused } ?? false }
|
||||
/// What is loaded, for the car's lists to mark.
|
||||
var current: Item? { item }
|
||||
var currentTime: Double { player?.currentTime().seconds ?? 0 }
|
||||
@@ -168,15 +170,15 @@ final class Playback: NSObject {
|
||||
}
|
||||
|
||||
/// An episode chosen away from the page, in the car (#420): played from where it got to, and
|
||||
/// the page told, whose player bar would otherwise go on as the old one, saving its place and
|
||||
/// marking it read by this one's clock.
|
||||
/// the page told before it plays, so its player bar shows this one, not the old one or none
|
||||
/// (#442), and the state that follows reaches it.
|
||||
func playChosen(_ item: Item, startAt: Double?) {
|
||||
if item == self.item {
|
||||
play()
|
||||
return
|
||||
}
|
||||
onReplaced?()
|
||||
load(item, startAt: startAt)
|
||||
onChosen?()
|
||||
play()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user