Skip to content

Development

RadicalMuffinMan edited this page Nov 25, 2026 · 9 revisions

Development

The project is one SolidJS codebase on SolidTV, whose renderer is a fork of LightningJS, shared across every platform while keeping platform-specific code isolated. Every screen draws into one WebGL canvas, with the video playing underneath it.

Project structure

moonfin/
├── src/
│   ├── index.jsx             # Boot: polyfills, strings, storage, the renderer and fonts, then the app
│   ├── App.jsx               # The shell: router, page stack, nav and overlays
│   ├── routes.js             # Every route
│   ├── app/                  # Navigation, the page stack, focus and the key map
│   ├── pages/                # Screens, one folder per area
│   ├── ui/                   # Theme, text and fonts, and the components under ui/components/
│   ├── state/                # Stores on signals: settings, auth, session, home rows, Watch Party...
│   ├── services/             # API and service modules
│   ├── utils/                # Helpers
│   ├── theme/                # Theme registry and theme specs
│   └── platform/             # tizen/, webos/, vega/ and xbox/: video, storage, keys and device profiles
├── public/                   # Fonts and their atlases, icons, images, workers, and translations under resources/
├── packaging/                # webOS appinfo.json and Tizen config.xml, icons, and each TV's service
├── scripts/                  # Packaging, the boot page, renderer patches, fonts, icons, checks, in-app updates (ota/)
├── vega/                     # Vega build script and the React Native shell -> .vpkg
├── xbox/                     # Xbox build script, the UWP host, the device probe and the console helper -> .msix
├── tools/                    # cdp.mjs and samsung.sh, for driving and inspecting the app on a TV
├── vite.config.js            # The modern and ES5 builds
└── package.json

Platform abstraction

Shared code in src/ never touches tizen.*, webapis.* or the webOS Luna bus directly. Platform-specific behavior is reached through runtime detection instead:

import { isTizen, isWebOS, isVega, isXbox, getPlatform } from './platform';

Services such as video, storage, and device profiles ask services/platformModule.js for their implementation, which dynamically imports it from src/platform/tizen/, webos/, vega/ or xbox/ for the platform getPlatform() reports. Anything that touches a native API belongs in one of those folders, not in the shared code.

Developer notes

  • SolidTV builds the interface: SolidJS components that the renderer draws into one WebGL canvas, with no DOM and no CSS. Its focus manager sends each key to the focused element and then up through its parents, each list owns its own arrows and Enter, and Vite builds the modern and ES5 bundles.
  • Plex servers go through services/plexApi.js, which answers the same library, playback and Live TV calls the app makes to Jellyfin, with services/plexMapper.js turning Plex's answers into the item shapes the screens read. services/plexTv.js handles the plex.tv sign in, Plex Home users and picking the best address for a server.
  • Silo servers go through services/siloApi.js, which answers the same methods the app calls on Jellyfin over Silo's native /api/v2, with services/siloMapper.js turning Silo's answers into Jellyfin's shapes and services/siloSeerr.js answering the Seerr screens from Silo's own requests. services/moonbaseEndpoint.js works out where a server's Moonbase lives: the server itself on Jellyfin and Emby, the plugin in Silo, or Moonbase for Plex beside a Plex server.
  • Tizen uses the AVPlay API for video and tizen.tvinputdevice for remote keys.
  • webOS uses a shared HTML5 video element with the audioTracks API, and Luna service calls for storage.
  • Vega (Fire TV) runs the app inside the Vega WebView (Chromium 144), hosted by a small React Native shell in vega/shell/. The shell writes what it knows about the device into window.__MOONFIN_VEGA__ before page code runs, forwards app state and keys as moonfin:vega events, and the page talks back through window.ReactNativeWebView.postMessage (see src/platform/vega/bridge.js). The WebView plays H.264, HEVC, VP9 and native HLS through the webOS player code, with no AV1, Dolby or DTS decoding, so those tracks are transcoded by the server. The page lives at file:///pkg/assets, whose null origin can't fetch a sibling file or start a Worker from one, so the build packs every image, JSON file and font into vega-files/*.js that vega/inject/package-files.js answers XHR and fetch from, and vega/inject/worker-shim.js starts the subtitle workers from blobs. A backgrounded app may keep no more than 150 MB and loses the decoder, so the player ends the session and leaves to the details page when the app goes to the background, and the shell can send the stop report itself from the session the page shares with it on every progress tick. The stick rasters on its GPU, so it keeps the high performance tier and draws at full resolution, and the whole app sits around 250 MB against Amazon's 420 MB foreground cap. A --debug build exposes Chrome DevTools on port 9229 (vega exec vda forward tcp:9229 tcp:9229).
  • Xbox runs the app in a WebView2 hosted by a small UWP app in xbox/shell/, served from the package at http://moonfin.internal. The host writes what it knows about the console into window.__MOONFIN_XBOX__ before page code runs, forwards app state, network changes and the media remote as moonfin:xbox events, and the page talks back through window.chrome.webview.postMessage (see src/platform/xbox/bridge.js). The controller arrives as the gamepad's own key codes, which src/platform/xbox/keys.js turns into the arrows, Enter and Escape the app knows. Video plays in the console's own player through FFmpegInteropX, behind a see-through WebView: src/platform/xbox/nativeVideo.js hands the player a real video element whose properties and events are routed over the bridge, so the shared webOS player code drives it unchanged and keeps drawing the controls and subtitles on top. The device probe under xbox/probe/ reports what a console can do, and xbox/console.cjs installs and drives a console through its Device Portal.
  • Packaged apps (.wgt, .ipk, .vpkg and .msix) bypass CORS restrictions that apply to the browser dev server, except that the Vega WebView does send a null origin, which stock Jellyfin and Emby accept. Plex servers only let Plex's own web app read their answers, so on Fire TV those requests go through the React Native shell instead.
  • Cross-origin cookies do not persist in either platform's webview, so API keys are used instead.
  • UI changes should be tested on real TV hardware when possible. Focus behavior, performance, and video in particular do not fully reproduce in a desktop browser.

Things that will save you some time

Behaviors that have each can cause a headache. Read them before your first change.

  • The oldest TVs run a 2014 browser. The ES5 bundle runs on Chrome 38, which is what webOS 3 is. Syntax gets compiled to ES5, but only the built-ins listed in vite.config.js and src/fastPolyfills.js are polyfilled, and missing DOM features aren't. KeyboardEvent.key doesn't exist there, which is why app/keys.js lists every key by its code, so add a key there before handling it. Set and Map aren't iterable (Array.from(set) gives []), and typed arrays have no slice. One token Chrome 38 can't parse stops the app, so CI parses every legacy file as ES5 (node scripts/check-legacy-js.mjs dist/webos-legacy).
  • Never use Solid stores. createStore and createMutable need Proxy, which Chrome 38 lacks. Use signals, or reactive() from state/reactive.js.
  • There's no CSS to style with. Colors, fonts and sizes come from the active theme through theme() in ui/theme.js. Text goes through fontFor() for server text and uiFont() for the app's own strings, which fall back to canvas text for scripts the font atlas doesn't cover.
  • Every dynamic child gets a container of its own. The renderer draws children in the order their nodes were created, not their place in the JSX, so a <For>, <Index> or <Show> that fills in later draws over the static siblings after it. Wrap it: <view><For .../></view>.
  • A key handler stops the key only by returning exactly true. Anything else, undefined included, lets it bubble up to the parents.
  • Give a scrolling view its own size. A <view> with no width or height takes its parent's size when it's created, and once it scrolls past that box the renderer stops drawing it and everything in it.
  • A node at alpha 0 never loads its texture. Start an image at 0.001 when it has to load before it fades in.
  • Older sets are limited by fill rate, not JavaScript. Every animated element, shadow and blur costs frames there, so check a change with General > Performance on Performance as well as High Quality.
  • Older LGs have little memory to spare. A webOS 3 set was measured with about 250 to 350 MB free while the app runs, and webOS closes the app with no error when it runs out, so don't read whole files into memory and let go of what a screen no longer shows.
  • Adding a font means running npm run fonts to rebuild the font atlases. A font cut from a variable font has to have its glyph overlap flags cleared first, or Chrome 38 refuses it and the text falls back to sans-serif.
  • The renderer is patched. npm install runs scripts/patch-renderer.mjs, which fits @solidtv/renderer 1.10.2 only and fails loudly when the renderer changes. An upgrade has to carry the patches, and nothing should work around them in a component.
  • Installed update loaders never change. App code that ships through in-app updates has to keep calling window.__moonfinOta the way services/versionChecker.js does now.
  • Every packaged file ships in updates except the boot page, the loader, the manifests, the service and the comic reader's worker (SHELL in scripts/ota/index.mjs). Show a packaged image through a node's src, and load any other packaged file (a font, a script, a sound, a worker, a DOM stylesheet's url()) through assetUrl() in utils/assetUrl.js, so a TV that took an update uses that update's copy.
  • A retail Samsung TV can still be inspected. sdb shell is locked down, but with the app closed, sdb shell 0 debug MoonfinApp.moonfin launches it with a debug port, and sdb forward tcp:9222 tcp:<port> opens that to Chrome DevTools at localhost:9222. The port changes every launch. TV=<tv ip> tools/samsung.sh MoonfinApp.moonfin does all of it in one go.

Translations

Moonfin is translated through Weblate. See the Smart-TV translation project rather than editing translation files by hand. Weblate writes them to public/resources/<lang>/strings.json, new English strings go in public/resources/strings.json, and translations reach sideloaded TVs with each in-app update.

Clone this wiki locally