Skip to content

Commit

Permalink
remove antiCursorMoveHandler from non seamless keyboard input methods…
Browse files Browse the repository at this point in the history
… (except Kodi), make enter button change command based on platform
  • Loading branch information
Nerwyn committed Nov 5, 2024
1 parent 0dae82c commit a5f6913
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 38 deletions.
4 changes: 2 additions & 2 deletions dist/universal-remote-card.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "universal-remote-card",
"version": "4.1.2",
"version": "4.1.3",
"description": "Universal Remote Card",
"main": "./dist/universal-remote-card.min.js",
"scripts": {
Expand Down
76 changes: 43 additions & 33 deletions src/classes/keyboard-dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export class KeyboardDialog extends LitElement {
this.onKeyDownFired = false;
}

fireTvOnKeyDown(e: KeyboardEvent) {
adbOnKeyDown(e: KeyboardEvent) {
e.stopImmediatePropagation();
this.forceCursorToEnd();

Expand All @@ -140,7 +140,7 @@ export class KeyboardDialog extends LitElement {
}
}

fireTvOnInput(e: InputEvent) {
adbOnInput(e: InputEvent) {
e.stopImmediatePropagation();
this.forceCursorToEnd();

Expand Down Expand Up @@ -218,14 +218,6 @@ export class KeyboardDialog extends LitElement {
this.onKeyDownFired = false;
}

androidTvEnterAndClose() {
this.hass.callService('remote', 'send_command', {
entity_id: this.config?.remote_id,
command: 'ENTER',
});
this.closeDialog();
}

androidTvSendText(text: string) {
this.hass.callService(
this.domain ?? 'remote',
Expand Down Expand Up @@ -277,22 +269,23 @@ export class KeyboardDialog extends LitElement {
}
}

textBox(_e: MouseEvent) {
search(_e: MouseEvent) {
const text = this.textarea?.value;
if (text) {
switch (this.config?.platform) {
case 'Kodi':
case 'Kodi': {
this.hass.callService('kodi', 'call_method', {
entity_id: this.config?.keyboard_id,
method: 'Input.SendText',
text: text,
done: false,
done: true,
});
break;
}
case 'Roku':
this.hass.callService('remote', 'send_command', {
entity_id: this.getRokuId('remote'),
command: `Lit_${text}`,
this.hass.callService('roku', 'search', {
entity_id: this.getRokuId('media_player'),
keyword: text,
});
break;
case 'Fire TV':
Expand All @@ -303,7 +296,7 @@ export class KeyboardDialog extends LitElement {
this.service ?? 'send_command',
{
entity_id: this.config?.keyboard_id,
command: `input text "${text}"`,
command: `am start -a "android.search.action.GLOBAL_SEARCH" --es query "${text}"`,
},
);
break;
Expand All @@ -313,23 +306,22 @@ export class KeyboardDialog extends LitElement {
this.closeDialog();
}

search(_e: MouseEvent) {
textBox(_e: MouseEvent) {
const text = this.textarea?.value;
if (text) {
switch (this.config?.platform) {
case 'Kodi': {
case 'Kodi':
this.hass.callService('kodi', 'call_method', {
entity_id: this.config?.keyboard_id,
method: 'Input.SendText',
text: text,
done: true,
done: false,
});
break;
}
case 'Roku':
this.hass.callService('roku', 'search', {
entity_id: this.getRokuId('media_player'),
keyword: text,
this.hass.callService('remote', 'send_command', {
entity_id: this.getRokuId('remote'),
command: `Lit_${text}`,
});
break;
case 'Fire TV':
Expand All @@ -340,7 +332,7 @@ export class KeyboardDialog extends LitElement {
this.service ?? 'send_command',
{
entity_id: this.config?.keyboard_id,
command: `am start -a "android.search.action.GLOBAL_SEARCH" --es query "${text}"`,
command: `input text "${text}"`,
},
);
break;
Expand All @@ -350,6 +342,27 @@ export class KeyboardDialog extends LitElement {
this.closeDialog();
}

enterDialog() {
switch (this.config?.platform) {
case 'Kodi':
break;
case 'Roku':
this.hass.callService('remote', 'send_command', {
entity_id: this.getRokuId('remote'),
command: 'enter',
});
break;
case 'Fire TV':
case 'Android TV':
this.hass.callService('remote', 'send_command', {
entity_id: this.config?.remote_id,
command: 'ENTER',
});
break;
}
this.closeDialog();
}

showDialog(e: CustomEvent) {
this.config = e.detail;

Expand Down Expand Up @@ -438,8 +451,7 @@ export class KeyboardDialog extends LitElement {
let inputHandler: ((e: InputEvent) => void) | undefined;
let keyDownHandler: ((e: KeyboardEvent) => void) | undefined;
let pasteHandler: ((e: ClipboardEvent) => void) | undefined;
let antiCursorMoveHandler: ((e: Event) => void) | undefined =
this.forceCursorToEndEvent;
let antiCursorMoveHandler: ((e: Event) => void) | undefined;
switch (this.config?.action) {
case 'search':
placeholder = 'Search for something...';
Expand All @@ -457,6 +469,7 @@ export class KeyboardDialog extends LitElement {
break;
case 'keyboard':
default:
antiCursorMoveHandler = this.forceCursorToEndEvent;
switch (this.config?.platform) {
case 'Kodi':
inputHandler = this.kodiOnInput;
Expand All @@ -468,8 +481,8 @@ export class KeyboardDialog extends LitElement {
keyDownHandler = this.rokuOnKeyDown;
break;
case 'Fire TV':
inputHandler = this.fireTvOnInput;
keyDownHandler = this.fireTvOnKeyDown;
inputHandler = this.adbOnInput;
keyDownHandler = this.adbOnKeyDown;
break;
case 'Android TV':
default:
Expand All @@ -482,10 +495,7 @@ export class KeyboardDialog extends LitElement {
buttons = html`${this.buildDialogButton(
'Close',
this.closeDialog,
)}${this.buildDialogButton(
'Enter',
this.androidTvEnterAndClose,
)}`;
)}${this.buildDialogButton('Enter', this.enterDialog)}`;
break;
}
placeholder = this.config?.keyboard_prompt ?? placeholder;
Expand Down

0 comments on commit a5f6913

Please sign in to comment.