Skip to content

Commit

Permalink
New Computer Update (better computer synchronizing)
Browse files Browse the repository at this point in the history
  • Loading branch information
KillianLucas committed Dec 22, 2023
1 parent cc2e1f8 commit 2127887
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions interpreter/core/computer/computer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json

from .terminal.terminal import Terminal

try:
Expand Down Expand Up @@ -61,3 +63,13 @@ def screenshot(self, *args, **kwargs):
Shortcut for computer.display.screenshot
"""
return self.display.screenshot(*args, **kwargs)

def to_dict(self):
def json_serializable(obj):
try:
json.dumps(obj)
return True
except (TypeError, OverflowError):
return False

return {k: v for k, v in self.__dict__.items() if json_serializable(v)}
4 changes: 2 additions & 2 deletions interpreter/core/respond.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def respond(interpreter):
# sync up the interpreter's computer with your computer
try:
if interpreter.os and language == "python":
computer_json = json.dumps(interpreter.computer.__dict__)
computer_json = json.dumps(interpreter.computer.to_dict())
sync_code = f"""import json\ncomputer.__dict__ = json.loads('''{computer_json}''')"""
for _ in interpreter.computer.run("python", sync_code):
pass
Expand All @@ -196,7 +196,7 @@ def respond(interpreter):
# sync up the interpreter's computer with your computer
for line in interpreter.computer.run(
"python",
"import json\nprint(json.dumps(computer.__dict__))",
"import json\nprint(json.dumps(computer.to_dict()))",
):
pass
interpreter.computer.__dict__ = json.loads(line["content"])
Expand Down

0 comments on commit 2127887

Please sign in to comment.