Pass the peer id to commands
This commit is contained in:
parent
c3daa969fa
commit
df70d8661a
@ -395,13 +395,13 @@ class Boss:
|
|||||||
self.child_monitor.add_child(window.id, window.child.pid, window.child.child_fd, window.screen)
|
self.child_monitor.add_child(window.id, window.child.pid, window.child.child_fd, window.screen)
|
||||||
self.window_id_map[window.id] = window
|
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
|
from .remote_control import handle_cmd
|
||||||
response = None
|
response = None
|
||||||
window = window or 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:
|
try:
|
||||||
response = handle_cmd(self, window, cmd)
|
response = handle_cmd(self, window, cmd, peer_id)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
import traceback
|
import traceback
|
||||||
response = {'ok': False, 'error': str(err)}
|
response = {'ok': False, 'error': str(err)}
|
||||||
@ -456,7 +456,7 @@ class Boss:
|
|||||||
terminator = b'\x1b\\'
|
terminator = b'\x1b\\'
|
||||||
if msg_bytes.startswith(cmd_prefix) and msg_bytes.endswith(terminator):
|
if msg_bytes.startswith(cmd_prefix) and msg_bytes.endswith(terminator):
|
||||||
cmd = msg_bytes[len(cmd_prefix):-len(terminator)].decode('utf-8')
|
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:
|
if response is None:
|
||||||
return None
|
return None
|
||||||
return cmd_prefix + json.dumps(response).encode('utf-8') + terminator
|
return cmd_prefix + json.dumps(response).encode('utf-8') + terminator
|
||||||
|
|||||||
@ -24,7 +24,7 @@ from .typing import BossType, WindowType
|
|||||||
from .utils import TTYIO, parse_address_spec
|
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)
|
cmd = json.loads(serialized_cmd)
|
||||||
v = cmd['version']
|
v = cmd['version']
|
||||||
no_response = cmd.get('no_response', False)
|
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.'}
|
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'])
|
c = command_for_name(cmd['cmd'])
|
||||||
payload = cmd.get('payload') or {}
|
payload = cmd.get('payload') or {}
|
||||||
|
payload['peer_id'] = peer_id
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ans = c.response_from_kitty(boss, window, PayloadGetter(c, payload))
|
ans = c.response_from_kitty(boss, window, PayloadGetter(c, payload))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user