-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdesktop.py
More file actions
46 lines (35 loc) · 1.18 KB
/
desktop.py
File metadata and controls
46 lines (35 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from __future__ import annotations
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
from leap0 import (
DEFAULT_DESKTOP_TEMPLATE_NAME,
DesktopDisplayInfo,
Leap0Client,
Leap0Error,
Sandbox,
)
def main() -> None:
client = Leap0Client()
sandbox: Sandbox | None = None
try:
sandbox = client.sandboxes.create(template_name=DEFAULT_DESKTOP_TEMPLATE_NAME)
sandbox.desktop.wait_until_ready(timeout=60.0)
print("Desktop:", sandbox.desktop.desktop_url())
display: DesktopDisplayInfo = sandbox.desktop.display_info()
print("Display:", display)
sandbox.desktop.move_pointer(x=display.width // 2, y=display.height // 2)
sandbox.desktop.click(button=1)
screenshot = sandbox.desktop.screenshot(image_format="png")
Path("desktop-screenshot.png").write_bytes(screenshot)
print("Saved screenshot to desktop-screenshot.png")
finally:
try:
if sandbox is not None:
sandbox.delete()
except Leap0Error:
pass
finally:
client.close()
if __name__ == "__main__":
main()