| ... | @@ -23,6 +23,7 @@ SCREEN_SLOT = threading.BoundedSemaphore(1) | ... | @@ -23,6 +23,7 @@ SCREEN_SLOT = threading.BoundedSemaphore(1) |
| 23 | DEADLINE = ContextVar('computer_deadline', default=float('inf')) | 23 | DEADLINE = ContextVar('computer_deadline', default=float('inf')) |
| 24 | OPERATION = ContextVar('computer_operation', default=None) | 24 | OPERATION = ContextVar('computer_operation', default=None) |
| 25 | FILE_CHUNK = json.loads((Path(__file__).resolve().parent.parent / 'dashboard/src/host-protocol.json').read_text())['file_chunk'] | 25 | FILE_CHUNK = json.loads((Path(__file__).resolve().parent.parent / 'dashboard/src/host-protocol.json').read_text())['file_chunk'] |
| | 26 | DRAG_DURATION_MS = 400 |
| 26 | | 27 | |
| 27 | | 28 | |
| 28 | def remaining(limit): | 29 | def remaining(limit): |
| ... | @@ -213,7 +214,7 @@ async def capture(name, actions, platform, screenshot=True, native_text=True): | ... | @@ -213,7 +214,7 @@ async def capture(name, actions, platform, screenshot=True, native_text=True): |
| 213 | for step in range(1, 21): | 214 | for step in range(1, 21): |
| 214 | screen.input({'type': 'pointer', 'x': round(x+(end_x-x)*step/20), | 215 | screen.input({'type': 'pointer', 'x': round(x+(end_x-x)*step/20), |
| 215 | 'y': round(y+(end_y-y)*step/20), 'buttons': button}) | 216 | 'y': round(y+(end_y-y)*step/20), 'buttons': button}) |
| 216 | await asyncio.sleep(action.get('duration_ms', 400)/20000) | 217 | await asyncio.sleep(action.get('duration_ms', DRAG_DURATION_MS)/20000) |
| 217 | screen.input({'type': 'release'}) | 218 | screen.input({'type': 'release'}) |
| 218 | elif kind == 'scroll': | 219 | elif kind == 'scroll': |
| 219 | wheel = {'up': 8, 'down': 16, 'left': 32, 'right': 64}[action['direction']] | 220 | wheel = {'up': 8, 'down': 16, 'left': 32, 'right': 64}[action['direction']] |
| ... | @@ -349,7 +350,7 @@ def validate(request): | ... | @@ -349,7 +350,7 @@ def validate(request): |
| 349 | actions = request.get('actions') | 350 | actions = request.get('actions') |
| 350 | if not isinstance(actions,list) or not 1 <= len(actions) <= 100: | 351 | if not isinstance(actions,list) or not 1 <= len(actions) <= 100: |
| 351 | raise ValueError('Send between 1 and 100 desktop actions.') | 352 | raise ValueError('Send between 1 and 100 desktop actions.') |
| 352 | for item in actions: | 353 | for index, item in enumerate(actions, 1): |
| 353 | if not isinstance(item,dict): | 354 | if not isinstance(item,dict): |
| 354 | raise ValueError('Send a desktop action object.') | 355 | raise ValueError('Send a desktop action object.') |
| 355 | kind = item.get('type') | 356 | kind = item.get('type') |
| ... | @@ -365,7 +366,7 @@ def validate(request): | ... | @@ -365,7 +366,7 @@ def validate(request): |
| 365 | raise ValueError('Choose the left, right, or middle mouse button.') | 366 | raise ValueError('Choose the left, right, or middle mouse button.') |
| 366 | for key,maximum in [('count',3),('amount',100),('duration_ms',5000)]: | 367 | for key,maximum in [('count',3),('amount',100),('duration_ms',5000)]: |
| 367 | if key in item and (type(item[key]) is not int or not 1 <= item[key] <= maximum): | 368 | if key in item and (type(item[key]) is not int or not 1 <= item[key] <= maximum): |
| 368 | raise ValueError('The desktop action exceeds its limit.') | 369 | raise ValueError(f'Action {index}: {key} must be an integer from 1 to {maximum}.') |
| 369 | if kind == 'scroll' and item['direction'] not in ('up','down','left','right'): | 370 | if kind == 'scroll' and item['direction'] not in ('up','down','left','right'): |
| 370 | raise ValueError('Choose a scroll direction.') | 371 | raise ValueError('Choose a scroll direction.') |
| 371 | if kind == 'key': | 372 | if kind == 'key': |
| ... | @@ -374,8 +375,8 @@ def validate(request): | ... | @@ -374,8 +375,8 @@ def validate(request): |
| 374 | for key in item['keys']: keycode(key) | 375 | for key in item['keys']: keycode(key) |
| 375 | if kind == 'text' and (not isinstance(item['text'],str) or len(item['text'].encode()) > 16384): | 376 | if kind == 'text' and (not isinstance(item['text'],str) or len(item['text'].encode()) > 16384): |
| 376 | raise ValueError('Type at most 16 KiB of text at a time.') | 377 | raise ValueError('Type at most 16 KiB of text at a time.') |
| 377 | if sum(a.get('duration_ms',0) for a in actions) > 15000: | 378 | if sum(a.get('duration_ms', DRAG_DURATION_MS if a['type'] == 'drag' else 0) for a in actions) > 15000: |
| 378 | raise ValueError('Keep total waits and drags under 15 seconds.') | 379 | raise ValueError('Waits and drags must total at most 15 seconds.') |
| 379 | | 380 | |
| 380 | | 381 | |
| 381 | def record_operation(name, operation): | 382 | def record_operation(name, operation): |