from wda import Client

from Entity.Variables import tikTokApp
from Utils.AiUtils import AiUtils
from Utils.LogManager import LogManager

# 页面控制工具类
class ControlUtils(object):

    # 打开Tik Tok
    @classmethod
    def openTikTok(cls, session: Client):
        currentApp = session.app_current()
        if currentApp != tikTokApp:
            session.app_start(tikTokApp)

    # 返回
    @classmethod
    def clickBack(cls, session: Client):
        x, y = AiUtils.findImageInScreen("back")
        if x > 0:
            r = session.swipe_right()
            if r.status == 0:
                return True
            else:
                return False
        else:
            print("本页面无法返回")
            LogManager.info("没有返回按钮")
            return False

    # 点赞
    @classmethod
    def clickLike(cls, session: Client):
        scale = session.scale
        x, y = AiUtils.findImageInScreen("add")
        print(x,y)
        if x > -1:
            print("找到目标了")
            r = session.click(x // scale, y // scale + 50)
            if r.status == 0:
                return True
            else:
                return False
        else:
            print("没有找到目标")
            return False

    # 点击评论
    # @classmethod
    # def clickComment(cls, session: Client):
    #     scale = session.scale
    #     x, y = AiUtils.findImageInScreen("add")
    #     print(x,y)
    #     if x > -1:
    #         print("找到目标了")
    #         r = session.click(x // scale, y // scale + 120)
    #         if r.status == 0:
    #             return True
    #         else:
    #             return False
    #     else:
    #         print("没有找到目标")
    #         return False



# ControlUtils.backAction("eca000fcb6f55d7ed9b4c524055214c26a7de7aa")