Pass the peer id to commands

This commit is contained in:
Kovid Goyal 2021-10-30 12:29:27 +05:30
parent c3daa969fa
commit df70d8661a
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 6 additions and 5 deletions

View File

@ -395,13 +395,13 @@ class Boss:
self.child_monitor.add_child(window.id, window.child.pid, window.child.child_fd, window.screen)
self.window_id_map[window.id] = window
def _handle_remote_command(self, cmd: str, window: Optional[Window] = None, from_peer: bool = False) -> Optional[Dict[str, Any]]:
def _handle_remote_command(self, cmd: str, window: Optional[Window] = None, peer_id: int = 0) -> Optional[Dict[str, Any]]:
from .remote_control import handle_cmd
response = None
window = window or None
if self.allow_remote_control == 'y' or from_peer or getattr(window, 'allow_remote_control', False):
if self.allow_remote_control == 'y' or peer_id > 0 or getattr(window, 'allow_remote_control', False):
try:
response = handle_cmd(self, window, cmd)
response = handle_cmd(self, window, cmd, peer_id)
except Exception as err:
import traceback
response = {'ok': False, 'error': str(err)}
@ -456,7 +456,7 @@ class Boss:
terminator = b'\x1b\\'
if msg_bytes.startswith(cmd_prefix) and msg_bytes.endswith(terminator):
cmd = msg_bytes[len(cmd_prefix):-len(terminator)].decode('utf-8')
response = self._handle_remote_command(cmd, from_peer=True)
response = self._handle_remote_command(cmd, peer_id=peer_id)
if response is None:
return None
return cmd_prefix + json.dumps(response).encode('utf-8') + terminator

View File

@ -24,7 +24,7 @@ from .typing import BossType, WindowType
from .utils import TTYIO, parse_address_spec
def handle_cmd(boss: BossType, window: Optional[WindowType], serialized_cmd: str) -> Optional[Dict[str, Any]]:
def handle_cmd(boss: BossType, window: Optional[WindowType], serialized_cmd: str, peer_id: int) -> Optional[Dict[str, Any]]:
cmd = json.loads(serialized_cmd)
v = cmd['version']
no_response = cmd.get('no_response', False)
@ -34,6 +34,7 @@ def handle_cmd(boss: BossType, window: Optional[WindowType], serialized_cmd: str
return {'ok': False, 'error': 'The kitty client you are using to send remote commands is newer than this kitty instance. This is not supported.'}
c = command_for_name(cmd['cmd'])
payload = cmd.get('payload') or {}
payload['peer_id'] = peer_id
try:
ans = c.response_from_kitty(boss, window, PayloadGetter(c, payload))