Files
raucao d846735b1e Crossfade the wallpaper only on intentional changes
Use a new bundled image for both the welcome screen and the dashboard
fallback, and crossfade into the first feed photo only when arriving from
the welcome screen or when the wallpaper changes after the first paint (a
live rotation or a manual pick). A plain open shows the resolved photo
outright, with no transition.

- wallpaper.gjs: three layers (bundled base, last settled photo, current
  photo). The current photo fades in on load and the previous one stays
  beneath for a crossfade; the photo layer renders only from the cached
  displayUrl, so a change fades instead of flashing the bundled base.
  Reduced motion settles instantly.
- photos.js: keep the last-known-good wallpaper on a cache miss or fetch
  error; add a one-shot timer that rotates at the day/week boundary while
  the dashboard stays open; expose animateEntry for the welcome entry.
- routes/index.js: set photos.animateEntry from the transition origin. A
  strict-mode route template's `this` is not the controller, so a
  controller property never reached the component.
- config/nostr.js: alias the welcome and fallback URLs to one image.

Tests and docs updated.
2026-11-10 15:18:13 +04:00

123 lines
3.8 KiB
Plaintext

import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
import { on } from '@ember/modifier';
import { service } from '@ember/service';
function prefersReducedMotion() {
return (
typeof window !== 'undefined' &&
typeof window.matchMedia === 'function' &&
window.matchMedia('(prefers-reduced-motion: reduce)').matches
);
}
// Full-bleed wallpaper. Pass @photo for route-specific images (the welcome
// screen); otherwise the selected feed photo is used.
//
// Three stacked layers, bottom to top: a bundled base that is always painted so
// a failed or slow load never leaves a blank page, the last settled photo
// (shown only while a photo is selected), and the current photo. The current
// photo only crossfades for an intentional change — arriving from the welcome
// screen (photos.animateEntry) or any change after the first paint (a rotation
// or a manual pick). The initial paint on a plain open is shown outright, with
// no transition.
//
// `displayUrl` is only ever a cached object URL, so a fade runs once the photo
// is cached rather than mid-fetch. Keeping the previous photo as a layer lets
// consecutive photos crossfade instead of flashing the bundled base.
export default class WallpaperComponent extends Component {
@service photos;
// The src of the last photo that finished fading in. It stays visible beneath
// the incoming photo for the crossfade.
@tracked baseSrc = null;
// The src whose image has finished loading and is currently fading in.
@tracked loadedSrc = null;
get photo() {
return this.args.photo ?? this.photos.currentWallpaper;
}
get src() {
return this.photo?.displayUrl ?? null;
}
get fallbackSrc() {
return this.photos.fallbackPhoto.displayUrl;
}
// Animate only intentional changes: the welcome -> dashboard entry
// (photos.animateEntry) and any change after the first photo is on screen.
// The initial paint is shown outright.
get shouldAnimate() {
return this.photos.animateEntry || this.baseSrc !== null;
}
get isLoaded() {
return this.src !== null && this.loadedSrc === this.src;
}
@action
handleLoad() {
this.loadedSrc = this.src;
// Settle immediately when there is nothing to transition — the initial
// paint, or reduced motion — so the base is ready for the next change and
// no transitionend is awaited.
if (!this.shouldAnimate || prefersReducedMotion()) {
this.baseSrc = this.src;
}
}
@action
handleTransitionEnd(event) {
if (event.propertyName === 'opacity' && this.isLoaded) {
this.baseSrc = this.src;
}
}
<template>
<div
class="pointer-events-none fixed inset-0 -z-10 overflow-hidden bg-gray-900"
data-test-wallpaper-container
>
<img
src={{this.fallbackSrc}}
alt=""
aria-hidden="true"
draggable="false"
class="absolute inset-0 h-full w-full object-cover"
/>
{{#if this.src}}
{{#if this.baseSrc}}
<img
src={{this.baseSrc}}
alt=""
aria-hidden="true"
draggable="false"
data-test-wallpaper-base
class="absolute inset-0 h-full w-full object-cover"
/>
{{/if}}
<img
src={{this.src}}
alt=""
aria-hidden="true"
draggable="false"
data-test-wallpaper
{{on "load" this.handleLoad}}
{{on "transitionend" this.handleTransitionEnd}}
class="absolute inset-0 h-full w-full object-cover transition-opacity duration-700 ease-in-out motion-reduce:transition-none
{{if
(or this.isLoaded (not this.shouldAnimate))
'opacity-100'
'opacity-0'
}}"
/>
{{/if}}
</div>
</template>
}