Skip to content

Commit

Permalink
Add get_clipboard function.
Browse files Browse the repository at this point in the history
  • Loading branch information
NoneTypeCoder authored and codeskyblue committed Nov 20, 2024
1 parent 59bbb0e commit e1f4190
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions wda/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,10 +717,29 @@ def callback(session):
"""
pass

# Not working
# def get_clipboard(self):
# return self.http.post("/wda/getPasteboard").value
def get_clipboard(self, wda_bundle_id):
""" Get clipboard text.
If you want to use this function, you have to set wda foreground which would switch the
current screen of the phone. Then we will try to switch back to the screen before.
Args:
wda_bundle_id: The bundle id of the started wda.
Returns:
Clipboard text.
"""
current_app_bundle_id = self.app_current().get("bundleId", "")
# Set wda foreground, it's necessary.
try:
self.app_launch(wda_bundle_id)
except:
pass
clipboard_text = self._session_http.post("/wda/getPasteboard").value
# Switch back to the screen before.
self.app_launch(current_app_bundle_id)
return base64.b64decode(clipboard_text).decode('utf-8')

# Not working
# def siri_activate(self, text):
# self.http.post("/wda/siri/activate", {"text": text})
Expand Down

0 comments on commit e1f4190

Please sign in to comment.