Skip to content

A Plex client for Samsung TVs that doesn't suck.

JavaScript

Fixes #1 and #7.

rfaile31387f37c478f39
diff --git a/app/css/app.css b/app/css/app.css
index 91c3a5d..8c995bd 100644
--- a/app/css/app.css
+++ b/app/css/app.css
@@ -111,7 +111,18 @@ html.playing .ambience { display: none; }
font: 500 17px/1 var(--body); letter-spacing: 0.06em; color: rgba(255, 255, 255, 0.86);
}
-.nav { display: flex; align-items: center; margin-left: 72px; }
+/* A fixed clip with a sliding track: many libraries scroll instead of overflowing. */
+.nav {
+ flex: 1 1 auto; min-width: 0; height: 88px; margin: 0 40px 0 72px;
+ display: flex; align-items: center; overflow: hidden;
+}
+.nav.more-right { -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 64px), transparent); }
+.nav.more-left { -webkit-mask-image: linear-gradient(to right, transparent, #000 64px); }
+.nav.more-left.more-right { -webkit-mask-image: linear-gradient(to right, transparent, #000 64px, #000 calc(100% - 64px), transparent); }
+.nav-track {
+ position: relative; display: flex; align-items: center; flex-shrink: 0; width: max-content;
+ transition: transform 220ms var(--ease); will-change: transform;
+}
.nav-item {
position: relative; display: flex; align-items: center; justify-content: center;
height: 52px; padding: 0 24px; margin-right: 6px; border-radius: 26px;
@@ -129,7 +140,7 @@ html.playing .ambience { display: none; }
.nav-icon { width: 52px; padding: 0; }
.nav-icon svg { width: 28px; height: 28px; display: block; }
.nav-sep { width: 2px; height: 28px; margin: 0 14px 0 8px; border-radius: 1px; background: rgba(255, 247, 230, 0.18); }
-.topbar-who { margin-left: auto; font: 500 22px var(--body); color: var(--dim); white-space: nowrap; }
+.topbar-who { margin-left: auto; flex-shrink: 0; font: 500 22px var(--body); color: var(--dim); white-space: nowrap; }
/* ---------- home ---------- */
@@ -217,7 +228,7 @@ html.playing .ambience { display: none; }
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
-html.fast .row-track, html.fast .rows-track, html.fast .grid-track, html.fast .ring {
+html.fast .row-track, html.fast .rows-track, html.fast .grid-track, html.fast .ring, html.fast .nav-track {
transition-duration: 110ms;
}
diff --git a/app/js/app.js b/app/js/app.js
index 4095d52..aca9c4a 100644
--- a/app/js/app.js
+++ b/app/js/app.js
@@ -1,7 +1,7 @@
// Boot: restore the session and go straight to Home when we can; otherwise sign in.
import { DEV, DEV_HOST, DEV_PLEX_URL, VERSION } from './config.js';
import * as router from './router.js';
-import { registerKeys } from './platform/tizen.js';
+import { isTizen, registerKeys } from './platform/tizen.js';
import { session, reconnect, signOut } from './session.js';
import { HomeScreen } from './screens/home.js';
import { LoginScreen } from './screens/login.js';
@@ -34,6 +34,18 @@ async function verify() {
}
}
+// The UI is laid out for the TV's fixed 1920×1080 viewport. In a desktop
+// browser, zoom it to fit the window and center it. zoom (not a transform)
+// re-renders text and images at the window's real resolution.
+function fitWindow() {
+ const root = document.documentElement;
+ const s = Math.min(innerWidth / 1920, innerHeight / 1080);
+ root.style.position = 'relative'; // so the margins below move #app too
+ root.style.zoom = s;
+ root.style.marginLeft = Math.max(0, (innerWidth - 1920 * s) / 2 / s) + 'px';
+ root.style.marginTop = Math.max(0, (innerHeight - 1080 * s) / 2 / s) + 'px';
+}
+
function start() {
// A release build installed over a dev build must not inherit its LAN shortcut.
if (!DEV && session.token === 'lan-dev') {
@@ -60,6 +72,10 @@ export function boot() {
if (DEV) window.__ss = { router, session, nav };
log('boot', VERSION, navigator.userAgent);
registerKeys();
+ if (!isTizen) {
+ fitWindow();
+ window.addEventListener('resize', fitWindow);
+ }
router.init(document.getElementById('app'));
initHud(() => (router.top() && router.top().name) || '');
window.addEventListener('samsucks:restart', start);
diff --git a/app/js/screens/home.js b/app/js/screens/home.js
index 3898ec9..694cad0 100644
--- a/app/js/screens/home.js
+++ b/app/js/screens/home.js
@@ -12,6 +12,7 @@ import { openItem, playItem, openLibrary, openSearch, openSettings } from '../na
import { error, log } from '../util/log.js';
const ROWS_TOP = 600;
+const NAV_PAD = 80; // wider than the 64px edge fade in app.css
function slimHub(hub) {
// Keep the cache small: only fields the home screen renders.
@@ -50,7 +51,9 @@ export function HomeScreen() {
const brandText = h('div', 'brand-text', brand);
h('img', 'brand-wordmark', brandText).src = 'img/wordmark.png';
h('div', 'brand-by', brandText).textContent = 'by rfaile313';
+ // The nav is a clip with a sliding track, so any number of libraries fits.
const navEl = h('nav', 'nav', top);
+ const navTrack = h('div', 'nav-track', navEl);
const who = h('div', 'topbar-who', top);
setText(who, session.server ? session.server.name : '');
@@ -71,26 +74,47 @@ export function HomeScreen() {
let zone = 'rows';
let navItems = [];
let navIndex = 0;
+ let navScroll = 0;
let loadedAt = 0;
let heroTimer = 0;
let artTimer = 0;
let reportedPaint = false;
function buildNav(sections) {
- navEl.innerHTML = '';
+ navTrack.innerHTML = '';
navItems = [{ label: 'Home', id: 'home' }]
.concat(sections.map(s => ({ label: s.title, id: 'section', section: s })))
.concat([{ label: 'Search', id: 'search', icon: icons.search }, { label: 'Settings', id: 'settings', icon: icons.gear }]);
+ navIndex = Math.min(navIndex, navItems.length - 1);
navItems.forEach((n, i) => {
- if (n.icon && !navItems[i - 1].icon) h('i', 'nav-sep', navEl);
- n.el = h('div', 'nav-item' + (n.icon ? ' nav-icon' : ''), navEl);
+ if (n.icon && !navItems[i - 1].icon) h('i', 'nav-sep', navTrack);
+ n.el = h('div', 'nav-item' + (n.icon ? ' nav-icon' : ''), navTrack);
if (n.icon) n.el.innerHTML = n.icon;
else h('span', '', n.el).textContent = n.label;
});
renderNav();
}
+ // Slide the track just enough to keep the focused item clear of the edge fades.
+ function scrollNav() {
+ const room = navEl.clientWidth;
+ if (!room) return; // hidden screen: nothing to measure
+ const max = Math.max(0, navTrack.offsetWidth - room);
+ const n = navItems[navIndex];
+ if (zone === 'nav' && n) {
+ const left = n.el.offsetLeft;
+ const right = left + n.el.offsetWidth;
+ if (left - NAV_PAD < navScroll) navScroll = left - NAV_PAD;
+ else if (right + NAV_PAD > navScroll + room) navScroll = right + NAV_PAD - room;
+ }
+ navScroll = Math.round(Math.max(0, Math.min(max, navScroll)));
+ setTransform(navTrack, 'translateX(' + (-navScroll) + 'px)');
+ toggleClass(navEl, 'more-left', navScroll > 0);
+ toggleClass(navEl, 'more-right', navScroll < max - 1);
+ }
+
function renderNav() {
+ scrollNav(); // measure before the class writes below dirty the style
navItems.forEach((n, i) => {
toggleClass(n.el, 'focus', zone === 'nav' && i === navIndex);
toggleClass(n.el, 'current', n.id === 'home');
@@ -194,6 +218,8 @@ export function HomeScreen() {
} else {
buildNav([]);
}
+ // Inter swaps in after first paint and changes the label widths.
+ if (document.fonts) document.fonts.ready.then(renderNav);
load();
function activateNav(n) {
@@ -207,6 +233,7 @@ export function HomeScreen() {
name: 'home',
onShow() {
ambience.restore();
+ renderNav(); // widths can't be measured while the screen was hidden
// Coming back from playback: progress and Continue Watching changed.
if (Date.now() - loadedAt > 5000) load();
},