fix: Rendering not correctly forced when tab changed in certain circumstances (#1817)
- Closes #1811 - Closes #1769
This commit is contained in:
@@ -157,7 +157,7 @@ export class CameraManager {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async reset(): Promise<void> {
|
public async destroy(): Promise<void> {
|
||||||
await this._store.reset();
|
await this._store.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ export class CardElementManager {
|
|||||||
// reconnection, to ensure the state subscription/unsubscription works
|
// reconnection, to ensure the state subscription/unsubscription works
|
||||||
// correctly for triggers.
|
// correctly for triggers.
|
||||||
this._api.getInitializationManager().uninitialize(InitializationAspect.CAMERAS);
|
this._api.getInitializationManager().uninitialize(InitializationAspect.CAMERAS);
|
||||||
this._api.getCameraManager().reset();
|
this._api.getCameraManager().destroy();
|
||||||
|
|
||||||
this._element.removeEventListener(
|
this._element.removeEventListener(
|
||||||
'mousemove',
|
'mousemove',
|
||||||
|
|||||||
@@ -141,6 +141,7 @@ export class ConfigManager {
|
|||||||
!isEqual(previousConfig?.cameras_global, this._overriddenConfig?.cameras_global))
|
!isEqual(previousConfig?.cameras_global, this._overriddenConfig?.cameras_global))
|
||||||
) {
|
) {
|
||||||
this._api.getInitializationManager().uninitialize(InitializationAspect.CAMERAS);
|
this._api.getInitializationManager().uninitialize(InitializationAspect.CAMERAS);
|
||||||
|
this._api.getCameraManager().destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
|||||||
@@ -159,6 +159,9 @@ export class CardController
|
|||||||
public getCameraManager(): CameraManager {
|
public getCameraManager(): CameraManager {
|
||||||
return this._cameraManager;
|
return this._cameraManager;
|
||||||
}
|
}
|
||||||
|
public createCameraManager(): void {
|
||||||
|
this._cameraManager = new CameraManager(this);
|
||||||
|
}
|
||||||
|
|
||||||
public getCameraURLManager(): CameraURLManager {
|
public getCameraURLManager(): CameraURLManager {
|
||||||
return this._cameraURLManager;
|
return this._cameraURLManager;
|
||||||
@@ -236,6 +239,9 @@ export class CardController
|
|||||||
public getMicrophoneManager(): MicrophoneManager {
|
public getMicrophoneManager(): MicrophoneManager {
|
||||||
return this._microphoneManager;
|
return this._microphoneManager;
|
||||||
}
|
}
|
||||||
|
public createMicrophoneManager(): void {
|
||||||
|
this._microphoneManager = new MicrophoneManager(this);
|
||||||
|
}
|
||||||
|
|
||||||
public getQueryStringManager(): QueryStringManager {
|
public getQueryStringManager(): QueryStringManager {
|
||||||
return this._queryStringManager;
|
return this._queryStringManager;
|
||||||
|
|||||||
@@ -92,16 +92,25 @@ export class InitializationManager {
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
!(await this._initializer.initializeMultipleIfNecessary({
|
!(await this._initializer.initializeMultipleIfNecessary({
|
||||||
[InitializationAspect.CAMERAS]: async () =>
|
[InitializationAspect.CAMERAS]: async () => {
|
||||||
await this._api.getCameraManager().initializeCamerasFromConfig(),
|
// Recreate the camera manager to guarantee an immediate re-render.
|
||||||
|
// See: https://github.com/dermotduffy/frigate-hass-card/issues/1811
|
||||||
|
// See: https://github.com/dermotduffy/frigate-hass-card/issues/1769
|
||||||
|
this._api.createCameraManager();
|
||||||
|
return await this._api.getCameraManager().initializeCamerasFromConfig();
|
||||||
|
},
|
||||||
|
|
||||||
// Connecting the microphone (if configured) is considered mandatory to
|
// Connecting the microphone (if configured) is considered mandatory to
|
||||||
// avoid issues with some cameras that only allow 2-way audio on the
|
// avoid issues with some cameras that only allow 2-way audio on the
|
||||||
// first stream initialized. See:
|
// first stream initialized.
|
||||||
// https://github.com/dermotduffy/frigate-hass-card/issues/1235
|
// See: https://github.com/dermotduffy/frigate-hass-card/issues/1235
|
||||||
...(this._api.getMicrophoneManager().shouldConnectOnInitialization() && {
|
...(this._api.getMicrophoneManager().shouldConnectOnInitialization() && {
|
||||||
[InitializationAspect.MICROPHONE_CONNECT]: async () =>
|
[InitializationAspect.MICROPHONE_CONNECT]: async () => {
|
||||||
await this._api.getMicrophoneManager().connect(),
|
// Recreate the microphone manager to guarantee an immediate
|
||||||
|
// re-render.
|
||||||
|
this._api.createMicrophoneManager();
|
||||||
|
return await this._api.getMicrophoneManager().connect();
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
}))
|
}))
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ export interface CardConditionAPI {
|
|||||||
|
|
||||||
export interface CardConfigAPI {
|
export interface CardConfigAPI {
|
||||||
getAutomationsManager(): AutomationsManager;
|
getAutomationsManager(): AutomationsManager;
|
||||||
|
getCameraManager(): CameraManager;
|
||||||
getCardElementManager(): CardElementManager;
|
getCardElementManager(): CardElementManager;
|
||||||
getConditionsManager(): ConditionsManager;
|
getConditionsManager(): ConditionsManager;
|
||||||
getConfigManager(): ConfigManager;
|
getConfigManager(): ConfigManager;
|
||||||
@@ -93,6 +94,7 @@ export interface CardConfigAPI {
|
|||||||
getMediaLoadedInfoManager(): MediaLoadedInfoManager;
|
getMediaLoadedInfoManager(): MediaLoadedInfoManager;
|
||||||
getMediaPlayerManager(): MediaPlayerManager;
|
getMediaPlayerManager(): MediaPlayerManager;
|
||||||
getMessageManager(): MessageManager;
|
getMessageManager(): MessageManager;
|
||||||
|
getMicrophoneManager(): MicrophoneManager;
|
||||||
getStatusBarItemManager(): StatusBarItemManager;
|
getStatusBarItemManager(): StatusBarItemManager;
|
||||||
getStyleManager(): StyleManager;
|
getStyleManager(): StyleManager;
|
||||||
getViewManager(): ViewManager;
|
getViewManager(): ViewManager;
|
||||||
@@ -165,7 +167,12 @@ export interface CardHASSAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface CardInitializerAPI {
|
export interface CardInitializerAPI {
|
||||||
|
createCameraManager(): void;
|
||||||
getCameraManager(): CameraManager;
|
getCameraManager(): CameraManager;
|
||||||
|
|
||||||
|
createMicrophoneManager(): void;
|
||||||
|
getMicrophoneManager(): MicrophoneManager;
|
||||||
|
|
||||||
getCardElementManager(): CardElementManager;
|
getCardElementManager(): CardElementManager;
|
||||||
getConfigManager(): ConfigManager;
|
getConfigManager(): ConfigManager;
|
||||||
getDefaultManager(): DefaultManager;
|
getDefaultManager(): DefaultManager;
|
||||||
@@ -173,7 +180,6 @@ export interface CardInitializerAPI {
|
|||||||
getHASSManager(): HASSManager;
|
getHASSManager(): HASSManager;
|
||||||
getMediaPlayerManager(): MediaPlayerManager;
|
getMediaPlayerManager(): MediaPlayerManager;
|
||||||
getMessageManager(): MessageManager;
|
getMessageManager(): MessageManager;
|
||||||
getMicrophoneManager(): MicrophoneManager;
|
|
||||||
getQueryStringManager(): QueryStringManager;
|
getQueryStringManager(): QueryStringManager;
|
||||||
getResolvedMediaCache(): ResolvedMediaCache;
|
getResolvedMediaCache(): ResolvedMediaCache;
|
||||||
getViewManager(): ViewManager;
|
getViewManager(): ViewManager;
|
||||||
|
|||||||
@@ -1290,7 +1290,7 @@ describe('CameraManager', async () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should reset', async () => {
|
it('should destroy', async () => {
|
||||||
const api = createCardAPI();
|
const api = createCardAPI();
|
||||||
const engine = mock<CameraManagerEngine>();
|
const engine = mock<CameraManagerEngine>();
|
||||||
vi.mocked(api.getHASSManager().getHASS).mockReturnValue(createHASS());
|
vi.mocked(api.getHASSManager().getHASS).mockReturnValue(createHASS());
|
||||||
@@ -1300,7 +1300,7 @@ describe('CameraManager', async () => {
|
|||||||
|
|
||||||
expect(manager.getStore().getCameraCount()).toBe(1);
|
expect(manager.getStore().getCameraCount()).toBe(1);
|
||||||
|
|
||||||
await manager.reset();
|
await manager.destroy();
|
||||||
|
|
||||||
expect(manager.getStore().getCameraCount()).toBe(0);
|
expect(manager.getStore().getCameraCount()).toBe(0);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -282,6 +282,26 @@ describe('CardController', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('creaters ', () => {
|
||||||
|
it('createCameraManager', () => {
|
||||||
|
const controller = createController();
|
||||||
|
const original = controller.getCameraManager();
|
||||||
|
|
||||||
|
controller.createCameraManager();
|
||||||
|
|
||||||
|
expect(controller.getCameraManager()).not.toBe(original);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('createMicrophoneManager', () => {
|
||||||
|
const controller = createController();
|
||||||
|
const original = controller.getMicrophoneManager();
|
||||||
|
|
||||||
|
controller.createMicrophoneManager();
|
||||||
|
|
||||||
|
expect(controller.getMicrophoneManager()).not.toBe(original);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('handlers', () => {
|
describe('handlers', () => {
|
||||||
it('hostConnected', () => {
|
it('hostConnected', () => {
|
||||||
createController().hostConnected();
|
createController().hostConnected();
|
||||||
|
|||||||
Reference in New Issue
Block a user