- Much improved API cleanliness and testability to allow further extensibility in future - Simplified code in `live` view This technically contains a small change in how overrides work in the `live` view. Since that change is _closer_ to the documentation, and since this is likely to be rarely used, this is not considered a breaking change. Previously, overrides for a given live camera would always render _as if_ that camera was selected, vs was actually selected. Now, overrides will only apply in the live view when the camera is _actually_ selected. If this is an issue for you in practice, lets discuss.
57 lines
1.4 KiB
TypeScript
57 lines
1.4 KiB
TypeScript
import { MediaLoadedInfo } from '../types';
|
|
import { log } from '../utils/debug';
|
|
import { isValidMediaLoadedInfo } from '../utils/media-info';
|
|
import { CardMediaLoadedAPI } from './types';
|
|
|
|
export class MediaLoadedInfoManager {
|
|
protected _api: CardMediaLoadedAPI;
|
|
protected _current: MediaLoadedInfo | null = null;
|
|
protected _lastKnown: MediaLoadedInfo | null = null;
|
|
|
|
constructor(api: CardMediaLoadedAPI) {
|
|
this._api = api;
|
|
}
|
|
|
|
public initialize(): void {
|
|
this.clear();
|
|
}
|
|
|
|
public set(mediaLoadedInfo: MediaLoadedInfo): void {
|
|
if (!isValidMediaLoadedInfo(mediaLoadedInfo)) {
|
|
return;
|
|
}
|
|
|
|
log(
|
|
this._api.getConfigManager().getCardWideConfig(),
|
|
`Advanced Camera Card media load: `,
|
|
mediaLoadedInfo,
|
|
);
|
|
|
|
this._current = mediaLoadedInfo;
|
|
this._lastKnown = mediaLoadedInfo;
|
|
|
|
this._api.getConditionStateManager().setState({ mediaLoadedInfo: mediaLoadedInfo });
|
|
|
|
// Fresh media information may change how the card is rendered.
|
|
this._api.getStyleManager().setExpandedMode();
|
|
this._api.getCardElementManager().update();
|
|
}
|
|
|
|
public get(): MediaLoadedInfo | null {
|
|
return this._current;
|
|
}
|
|
|
|
public getLastKnown(): MediaLoadedInfo | null {
|
|
return this._lastKnown;
|
|
}
|
|
|
|
public clear(): void {
|
|
this._current = null;
|
|
this._api.getConditionStateManager().setState({ mediaLoadedInfo: null });
|
|
}
|
|
|
|
public has(): boolean {
|
|
return !!this._current;
|
|
}
|
|
}
|