Skip to content

Commit

Permalink
feat: add restart atx agent function
Browse files Browse the repository at this point in the history
  • Loading branch information
mastrolube committed Feb 17, 2024
1 parent d2c566d commit f1fa4a3
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions GramAddict/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,11 +428,22 @@ def print_telegram_reports(
def kill_atx_agent(device):
_restore_keyboard(device)
logger.info("Kill atx agent.")
cmd: str = (
f"adb{'' if configs.device_id is None else ' -s ' + configs.device_id} shell pkill atx-agent"
)
cmd: str = f"adb{'' if configs.device_id is None else f' -s {configs.device_id}'} shell pkill atx-agent"
subprocess.run(cmd, stdout=PIPE, stderr=PIPE, shell=True, encoding="utf8")

def restart_atx_agent(device):
kill_atx_agent(device)
logger.info("Restarting atx agent.")
cmd: str = f"adb{'' if configs.device_id is None else f' -s {configs.device_id}'} shell /data/local/tmp/atx-agent server -d"

try:
result = subprocess.run(cmd, stdout=PIPE, stderr=PIPE, shell=True, encoding="utf8", check=True)
if result.returncode != 0:
logger.error(f"Failed to restart atx-agent: {result.stderr}")
else:
logger.info("atx-agent restarted successfully.")
except subprocess.CalledProcessError as e:
logger.error(f"Error occurred while restarting atx-agent: {e}")

def _restore_keyboard(device):
logger.debug("Back to default keyboard!")
Expand Down

0 comments on commit f1fa4a3

Please sign in to comment.