A native player bar, and the Glass look it sits in (#2)
The first native surface, and the one that settles how the rest will look. Glass.swift is not a port of the stylesheet. ipx's Glass is already an approximation of what UIKit gives away -- panels are a 70% colour under blur(24px) saturate(180%) with an inset top highlight, which is a material, and the palette names Apple's own colours in its own comments. So where the CSS had to write #409cff in dark and #0055aa in light, because no single blue clears AA over the wash, this asks for the system blue and gets both. Only the wash keeps its hex values: there the colour is the design and there is no system equivalent to ask for. PlayerBarView draws what Playback knows, and Playback is the same object the lock screen and the remote commands drive, so all of them agree without anything being kept in step by hand. Back 15 and forward 30 match the page and the lock screen, so every way of skipping moves by the same amount. Seeking waits for the finger to lift rather than sending a stream of seeks at a player still answering the last one. The page's own bar is hidden rather than left to sit under ours. Its play buttons still work -- they post to the host either way -- but two bars for one player would be two sets of buttons disagreeing about what is playing, and only one of them is what CarPlay will be driving. One test had to be rewritten rather than the code: it asserted that one of the fixture's two episodes had a file, which stops being true the moment the event test asks the daemon to scan. The daemon is shared and keeps what earlier tests did to it, so the assertion now asks what the downloaded filter means instead of how many things match it today. Thirteen pass, twice over the same accumulated state. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import SwiftUI
|
||||
import UIKit
|
||||
import WebKit
|
||||
|
||||
@@ -12,6 +13,7 @@ final class WebViewController: UIViewController, WKNavigationDelegate {
|
||||
private var playback: Playback!
|
||||
private var bridge: Bridge!
|
||||
|
||||
private var playerBar: UIHostingController<PlayerBarView>!
|
||||
private let banner = UIView()
|
||||
private let bannerText = UILabel()
|
||||
private var checkedBridge = false
|
||||
@@ -42,7 +44,6 @@ final class WebViewController: UIViewController, WKNavigationDelegate {
|
||||
pageAtTop = webView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor)
|
||||
NSLayoutConstraint.activate([
|
||||
pageAtTop,
|
||||
webView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
|
||||
webView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
|
||||
webView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
|
||||
])
|
||||
@@ -59,10 +60,32 @@ final class WebViewController: UIViewController, WKNavigationDelegate {
|
||||
Zoom.install(into: cfg.userContentController)
|
||||
|
||||
setUpBanner()
|
||||
setUpPlayerBar()
|
||||
|
||||
if ServerSettings.isConfigured { load() }
|
||||
}
|
||||
|
||||
// MARK: - the player bar
|
||||
|
||||
/// Ours, below the page, with the page's own bar hidden. Two bars for one player would be
|
||||
/// two sets of buttons disagreeing about what is playing, and only one of them is the thing
|
||||
/// CarPlay and the lock screen are driving.
|
||||
private func setUpPlayerBar() {
|
||||
playerBar = UIHostingController(rootView: PlayerBarView(playback: playback))
|
||||
playerBar.view.backgroundColor = .clear
|
||||
playerBar.view.translatesAutoresizingMaskIntoConstraints = false
|
||||
addChild(playerBar)
|
||||
view.addSubview(playerBar.view)
|
||||
playerBar.didMove(toParent: self)
|
||||
|
||||
NSLayoutConstraint.activate([
|
||||
playerBar.view.topAnchor.constraint(equalTo: webView.bottomAnchor),
|
||||
playerBar.view.leadingAnchor.constraint(equalTo: view.leadingAnchor),
|
||||
playerBar.view.trailingAnchor.constraint(equalTo: view.trailingAnchor),
|
||||
playerBar.view.bottomAnchor.constraint(equalTo: view.bottomAnchor),
|
||||
])
|
||||
}
|
||||
|
||||
// MARK: - how big the page is drawn
|
||||
|
||||
/// The page is sized for a phone and for a browser window, and on a Mac -- where the window
|
||||
@@ -112,7 +135,16 @@ final class WebViewController: UIViewController, WKNavigationDelegate {
|
||||
+ "s.textContent=\(css.debugDescription)})()"
|
||||
}
|
||||
|
||||
/// The page's own player bar, hidden. It is still what the play buttons drive -- they
|
||||
/// post to the host either way -- but the bar itself is ours now.
|
||||
static let hidePageBar = "(function(){var s=document.createElement('style');"
|
||||
+ "s.textContent='#player{display:none!important}';"
|
||||
+ "(document.head||document.documentElement).appendChild(s)})()"
|
||||
|
||||
static func install(into controller: WKUserContentController) {
|
||||
controller.addUserScript(WKUserScript(source: hidePageBar,
|
||||
injectionTime: .atDocumentEnd,
|
||||
forMainFrameOnly: true))
|
||||
controller.addUserScript(WKUserScript(source: script(current),
|
||||
injectionTime: .atDocumentEnd,
|
||||
forMainFrameOnly: true))
|
||||
|
||||
Reference in New Issue
Block a user