From 02a469fb437629ecb48f5af94b3b5f19c2736af1 Mon Sep 17 00:00:00 2001 From: Dermot Duffy Date: Tue, 2 Apr 2024 13:03:00 -0700 Subject: [PATCH] Only show download button in media viewer. --- src/components-lib/menu-button-controller.ts | 10 ++++++-- .../menu-button-controller.test.ts | 23 +++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/components-lib/menu-button-controller.ts b/src/components-lib/menu-button-controller.ts index 6d0a7f73..388763a9 100644 --- a/src/components-lib/menu-button-controller.ts +++ b/src/components-lib/menu-button-controller.ts @@ -131,7 +131,9 @@ export class MenuButtonController { .getAllDependentCameras(selectedCameraID, 'substream'); if (selectedCameraID && substreamCameraIDs && view.is('live')) { - const substreams = [...substreamCameraIDs].filter((cameraID) => cameraID !== selectedCameraID); + const substreams = [...substreamCameraIDs].filter( + (cameraID) => cameraID !== selectedCameraID, + ); const streams = [selectedCameraID, ...substreams]; if (streams.length === 2) { @@ -258,7 +260,11 @@ export class MenuButtonController { }); } - if (mediaCapabilities?.canDownload && !this._isBeingCasted()) { + if ( + view.isViewerView() && + mediaCapabilities?.canDownload && + !this._isBeingCasted() + ) { buttons.push({ icon: 'mdi:download', ...config.menu.buttons.download, diff --git a/tests/components-lib/menu-button-controller.test.ts b/tests/components-lib/menu-button-controller.test.ts index 305233f5..c6887c37 100644 --- a/tests/components-lib/menu-button-controller.test.ts +++ b/tests/components-lib/menu-button-controller.test.ts @@ -726,6 +726,7 @@ describe('MenuButtonController', () => { createMediaCapabilities({ canDownload: true }), ); const view = createView({ + view: 'media', queryResults: new MediaQueriesResults({ results: [new ViewMedia('clip', 'camera-1')], selectedIndex: 0, @@ -772,6 +773,28 @@ describe('MenuButtonController', () => { expect.arrayContaining([expect.objectContaining({ title: 'Download' })]), ); }); + + it('not in a non-media view', () => { + const cameraManager = createCameraManager(); + vi.mocked(cameraManager.getMediaCapabilities).mockReturnValue( + createMediaCapabilities({ canDownload: true }), + ); + const view = createView({ + view: 'live', + queryResults: new MediaQueriesResults({ + results: [new ViewMedia('clip', 'camera-1')], + selectedIndex: 0, + }), + }); + const buttons = calculateButtons(controller, { + cameraManager: cameraManager, + view: view, + }); + + expect(buttons).not.toEqual( + expect.arrayContaining([expect.objectContaining({ title: 'Download' })]), + ); + }); }); it('should have camera UI button', () => {