Compare commits

..
2 changed files with 9 additions and 21 deletions

No files matched your search

+3 -5
View File
@@ -44,9 +44,7 @@ final class TabletSidebarView: ExpoView {
let onPlaylistPress = EventDispatcher()
var playlists: [SidebarPlaylist] = []
private let selectionProxy = SidebarSelectionProxy()
/// Playlist rows by identifier. Typed loosely because stored properties
/// can't be gated to iOS 18, where `UITab` arrives; values are always `UITab`.
private var playlistTabs: [String: NSObject] = [:]
private var playlistTabs: [String: UITab] = [:]
private var coverImages: [String: UIImage] = [:]
private var coverTasks: [String: URLSessionDataTask] = [:]
var accountName = ""
@@ -203,7 +201,7 @@ extension TabletSidebarView {
var rows: [UITab] = []
for playlist in playlists {
let identifier = playlistTabPrefix + playlist.id
let tab = playlistTabs[identifier] as? UITab ?? UITab(
let tab = playlistTabs[identifier] ?? UITab(
title: playlist.title, image: nil, identifier: identifier,
viewControllerProvider: { _ in UIViewController() })
playlistTabs[identifier] = tab
@@ -235,7 +233,7 @@ extension TabletSidebarView {
guard let self else { return }
self.coverTasks[url] = nil
self.coverImages[url] = roundedIcon(image)
if let tab = self.playlistTabs[identifier] as? UITab { tab.image = self.coverImages[url] }
if let tab = self.playlistTabs[identifier] { tab.image = self.coverImages[url] }
}
}
coverTasks[url] = task
+6 -16
View File
@@ -1,18 +1,10 @@
// Serves covers of downloaded music when the network fails, so they show
// offline; any other cover falls back to the placeholder the server would send
// for a missing cover. Everything else, and every request that succeeds
// online, passes through untouched. Covers are saved by lib/downloads.ts.
// offline. Everything else, and every request that succeeds online, passes
// through untouched. Covers are saved by lib/downloads.ts.
const COVER_CACHE = "otunes-download-covers"
const PLACEHOLDER_CACHE = "otunes-placeholders"
const PLACEHOLDER_PATH = "/placeholder-album.svg"
const COVER_PATH = /^\/api\/(album|playlist|artist)\/[^/]+\/cover$/
const COVER_PATH = /^\/api\/(album|playlist)\/[^/]+\/cover$/
self.addEventListener("install", (event) => {
self.skipWaiting()
event.waitUntil(
caches.open(PLACEHOLDER_CACHE).then((cache) => cache.add(PLACEHOLDER_PATH))
)
})
self.addEventListener("install", () => self.skipWaiting())
self.addEventListener("activate", (event) =>
event.waitUntil(self.clients.claim())
)
@@ -27,11 +19,9 @@ function coverKey(url) {
return COVER_PATH.test(url.pathname) ? url.pathname : null
}
/** The saved cover, else the placeholder. */
async function savedCover(key) {
const saved = await (await caches.open(COVER_CACHE)).match(key)
if (saved) return saved
return (await caches.open(PLACEHOLDER_CACHE)).match(PLACEHOLDER_PATH)
const cache = await caches.open(COVER_CACHE)
return cache.match(key)
}
self.addEventListener("fetch", (event) => {