ADB 操作钉钉打卡

发布时间:2022-04-20浏览次数:0

支持注册ChatGPT Plus的OneKey虚拟卡
绑定Apple Pay、Google Pay、支付宝和微信支付进行日常消费

注册和了解更多 ->

silver
const process = require('child_process');
const schedule = require('node-schedule');

const sleep = (time) => new Promise(res => setTimeout(res, time));

function exec(shell) {
  return new Promise((resolve, reject) => { 
    process.exec(shell, function (error, stdout, stderr) {
      if (error !== null) {
        // console.log('exec error: ' + stderr);
        reject(stderr);
      }
      // console.log(stdout);
      return resolve(stdout);
    });
  })
  
}


function isLight(){
  return new Promise((resolve, reject) => { 
    exec(`adb shell dumpsys power`).then(res => {
      if(res.includes("mHoldingDisplaySuspendBlocker=true")){
        return resolve(true)
      }
      return resolve(false)
    });
  })
}


async function action() {
  console.log("连接至设置");
  exec(`adb connect 192.168.4.11`)
  await sleep(3000)

  console.log('点亮屏幕')
  
  const light = await isLight()

  if (!light) {
    exec(`adb shell input keyevent 26`)
    await sleep(3000)
  }

  console.log('解锁')
  exec(`adb shell input swipe 200 800 200 300 1000`)

  await sleep(6000)

  console.log('关闭应用')
  exec(`adb shell am force-stop com.alibaba.android.rimet`)

  await sleep(2000)
  console.log('打开应用')
  exec(`adb shell am start -n com.alibaba.android.rimet/com.alibaba.android.rimet.biz.LaunchHomeActivity `)

  await sleep(16000)

  console.log('关闭应用')
  exec(`adb shell am force-stop com.alibaba.android.rimet`)
  await sleep(6000)
  console.log('关闭屏幕')
  exec(`adb shell input keyevent 26`)


}


function setSchedule(date, callback) {
  schedule.scheduleJob("dingding", date, callback)
}

setSchedule('0 40 8 * * *', () => { action() })
setSchedule('0 10 18 * * *', () => { action() })
字节笔记本扫描二维码查看更多内容