Include mouse movements as interaction.

This commit is contained in:
Dermot Duffy
2022-04-09 21:48:19 -07:00
parent 3011b6b99a
commit ce9ef97aea
2 changed files with 26 additions and 16 deletions
+18 -5
View File
@@ -6,12 +6,13 @@ import {
html,
unsafeCSS,
} from 'lit';
import { HomeAssistant, LovelaceCardEditor, getLovelace } from 'custom-card-helpers';
import { StyleInfo, styleMap } from 'lit/directives/style-map.js';
import { customElement, property, query, state } from 'lit/decorators.js';
import { classMap } from 'lit/directives/class-map.js';
import { StyleInfo, styleMap } from 'lit/directives/style-map.js';
import { until } from 'lit/directives/until.js';
import { HomeAssistant, LovelaceCardEditor, getLovelace } from 'custom-card-helpers';
import screenfull from 'screenfull';
import { throttle } from 'lodash-es';
import { until } from 'lit/directives/until.js';
import { z } from 'zod';
import {
@@ -180,6 +181,10 @@ export class FrigateCard extends LitElement {
// A cache of resolved media URLs/mimetypes for use in the whole card.
protected _resolvedMediaCache = new ResolvedMediaCache();
// The mouse handler may be called continually, throttle it to at most once
// per second for performance reasons.
protected _boundMouseHandler = throttle(this._mouseHandler.bind(this), 1 * 1000);
/**
* Set the Home Assistant object.
*/
@@ -383,8 +388,7 @@ export class FrigateCard extends LitElement {
if (
this._getConfig().menu.buttons.download &&
(this._view?.isViewerView() || this._view?.is('timeline') &&
!!this._view?.media)
(this._view?.isViewerView() || (this._view?.is('timeline') && !!this._view?.media))
) {
buttons.push({
type: 'custom:frigate-card-menu-icon',
@@ -935,6 +939,13 @@ export class FrigateCard extends LitElement {
this._startInteractionTimer();
}
/**
* Handle mouse movements.
*/
protected _mouseHandler(): void {
this._startInteractionTimer();
}
/**
* Clear the user interaction ('screensaver') timer.
*/
@@ -1071,6 +1082,7 @@ export class FrigateCard extends LitElement {
if (screenfull.isEnabled) {
screenfull.on('change', this._fullscreenHandler.bind(this));
}
this.addEventListener('mousemove', this._boundMouseHandler);
}
/**
@@ -1080,6 +1092,7 @@ export class FrigateCard extends LitElement {
if (screenfull.isEnabled) {
screenfull.off('change', this._fullscreenHandler.bind(this));
}
this.removeEventListener('mousemove', this._boundMouseHandler);
super.disconnectedCallback();
}
+2 -5
View File
@@ -1,4 +1,3 @@
// TODO: Periodically refetch events.
// TODO: Editor support for timeline (incl. in views).
// TODO: Make thumbnail controls optional (in all places that use thumbnails).
// TODO: Search for TODOs and logging statements.
@@ -507,7 +506,7 @@ export class FrigateCardTimelineCore extends LitElement {
const selected = this._timeline.getSelection();
let childIndex = -1;
const children: FrigateBrowseMediaSource[] = [];
this._events.dataset.get().forEach((item) => {
this._events.dataset.get({order: 'start'}).forEach((item) => {
if (this.timelineConfig) {
let added = false;
if (
@@ -732,15 +731,13 @@ export class FrigateCardTimelineCore extends LitElement {
this._generateThumbnails();
}
if (event) {
this._timeline.setSelection([event.id], {
this._timeline.setSelection(event ? [event.id] : [], {
focus: false,
animation: {
animation: false,
zoom: false,
},
});
}
const context = this.view.context as TimelineViewContext | null;
const timelineWindow = this._timeline.getWindow();