Skip to content

fix(ui): hide disabled media browser buttons when empty - #3387

Open
JamBalaya56562 wants to merge 3 commits into
motioneye-project:devfrom
JamBalaya56562:codex/hide-disabled-media-browser-buttons
Open

fix(ui): hide disabled media browser buttons when empty#3387
JamBalaya56562 wants to merge 3 commits into
motioneye-project:devfrom
JamBalaya56562:codex/hide-disabled-media-browser-buttons

Conversation

@JamBalaya56562

@JamBalaya56562 JamBalaya56562 commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

What

Hide a media-browser button (Pictures / Movies) in the camera overlay when its capture mode is disabled and there are no existing files of that type to browse.

Fixes #2731.

Re-created after the previous PR (#3383) was accidentally closed when its branch was deleted during a rebase. This branch carries the change @Marijn0 requested in that review.

Why

The overlay showed the media-browser buttons even when the corresponding capture feature was disabled, which is inconsistent with the camera settings. Simply hiding on the config flag (the first approach) would also cut off access to media recorded before the user disabled capture — per @Marijn0's review, the button should disappear only when it truly has nothing to show.

How

  • Simple MJPEG cameras still hide both buttons (unchanged).
  • Otherwise, when a capture mode is disabled, an async check hits the existing list endpoint (…/list/?with_stat=false) and the button is hidden only if mediaList comes back empty. Enabled modes issue no request; on error / while unsure the button stays visible (no flicker for the case that still has media).

Validation

  • Change is limited to motioneye/static/js/main.js (+22/-0); node --check passes.
  • No JS test framework in the repo. Manual E2E (needs a live motion+camera): disable Still images on a camera with old pictures → Pictures button stays; with none → it hides after load; same for Movies; simple MJPEG still hides both.

Screenshots

Setup used for the comparison: one JPEG network camera, Still Images and Movies both disabled, and no media files stored for the camera. (Same camera/config on both servers; only the motionEye code differs.)

Before (current dev) After (this PR)
before after
The Pictures and Movies buttons are shown in the camera overlay even though both capture modes are disabled and there is nothing to browse. The Pictures and Movies buttons are hidden, because the …/list/?with_stat=false&limit=1 check found no existing media. The other overlay buttons are unaffected.

JamBalaya56562 and others added 2 commits July 1, 2026 07:45
Per @Marijn0's review: hiding a media-browser button purely on the
capture-mode flag also cut off access to media recorded before the mode
was disabled. Now, when a capture mode is disabled, the button is hidden
only after an async check of the existing list endpoint (with_stat=false)
finds no files of that type. Enabled modes issue no request, and simple
MJPEG cameras still hide both buttons.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Comment on lines +4722 to +4731
function hideMediaButtonIfEmpty(cameraId, mediaType, button) {
/* the list endpoint returns {mediaList: [...]} (empty when there are no
* files); with_stat=false keeps the request cheap. On error the button is
* left visible (safe default - don't hide when we are unsure). */
ajax('GET', basePath + mediaType + '/' + cameraId + '/list/?with_stat=false', null, function (data) {
if (data && data.mediaList && !data.mediaList.length) {
button.hide();
}
});
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m not sure we should call the media list endpoint just to decide whether to hide a button. Even with with_stat=false, this can still be resource-intensive for users with lots of saved files. Unfortunately, I don’t see an easy alternative solution either.

@JamBalaya56562 JamBalaya56562 Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, agreed that calling the full media list just to decide whether to hide the button would be too expensive for large media directories.

I addressed this in c23c3d8 by turning that request into a bounded existence check instead of a full listing:

  • the UI now calls /list/?with_stat=false&limit=1 for the hide-button check;
  • the picture/movie list handlers parse an optional positive limit query parameter;
  • local media listing stops walking as soon as the requested number of matching files is found, so limit=1 returns after the first actual media file;
  • the limit is also respected across recursive subdirectories;
  • remote camera list requests forward with_stat=false and limit=1 only when explicitly requested, while the default request remains unchanged for compatibility with older remote motionEye instances.

I also added tests for the early-stop behavior, handler query parsing, recursive limit handling, and remote query forwarding.

Tested with WSL/Linux:

pytest tests/test_mediafiles.py tests/test_remote.py tests/test_handlers/test_media_list_limit.py -q
65 passed, 123 subtests passed

pytest tests -q
146 passed, 10 warnings, 123 subtests passed

@JamBalaya56562
JamBalaya56562 force-pushed the codex/hide-disabled-media-browser-buttons branch from 09efcef to c23c3d8 Compare July 2, 2026 00:16
@JamBalaya56562
JamBalaya56562 requested a review from Marijn0 July 13, 2026 11:22
@Marijn0
Marijn0 requested a review from MichaIng July 14, 2026 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants