Add initial keyboard shortcut support.

This commit is contained in:
Dermot Duffy
2024-06-05 21:44:17 -07:00
parent 904f6d8142
commit 7ab545738d
186 changed files with 9564 additions and 3658 deletions
+19 -2
View File
@@ -16,7 +16,7 @@ import {
Overrides,
} from '../config/types';
import { desparsifyArrays } from '../utils/basic';
import { CardConditionAPI } from './types';
import { CardConditionAPI, KeysState } from './types';
interface MicrophoneConditionState {
connected?: boolean;
@@ -35,6 +35,7 @@ interface ConditionState {
interaction?: boolean;
microphone?: MicrophoneConditionState;
user?: CurrentUser;
keys?: KeysState;
}
export class ConditionsEvaluateRequestEvent extends Event {
@@ -190,7 +191,9 @@ export class ConditionsManager {
const config = this._api.getConfigManager().getConfig();
const conditions: FrigateCardCondition[] = [];
config?.overrides?.forEach((override) => conditions.push(...override.conditions));
config?.automations?.forEach((automation) => conditions.push(...automation.conditions));
config?.automations?.forEach((automation) =>
conditions.push(...automation.conditions),
);
// Element conditions can be arbitrarily nested underneath conditionals and
// custom elements that this card may not known. Here we recursively parse
@@ -323,6 +326,20 @@ export class ConditionsManager {
(conditionObj.muted === undefined ||
state.microphone?.muted === conditionObj.muted)
);
case 'key':
return (
!!state.keys &&
conditionObj.key in state.keys &&
(conditionObj.state ?? 'down') === state.keys[conditionObj.key].state &&
(conditionObj.ctrl === undefined ||
conditionObj.ctrl === !!state.keys[conditionObj.key].ctrl) &&
(conditionObj.alt === undefined ||
conditionObj.alt === !!state.keys[conditionObj.key].alt) &&
(conditionObj.meta === undefined ||
conditionObj.meta === !!state.keys[conditionObj.key].meta) &&
(conditionObj.shift === undefined ||
conditionObj.shift === !!state.keys[conditionObj.key].shift)
);
}
}