autojs-filesync
v1.0.7
Published
1. 功能: 局域网 电脑和手机文件同步, 手机端软件是 autojs 2. 安装 ``` npm i autojs-filesync --save ```
Downloads
19
Maintainers
Readme
- 功能: 局域网 电脑和手机文件同步, 手机端软件是 autojs
- 安装
npm i autojs-filesync --save
- 启动 和 停止
const autojsFileSync = require('autojs-filesync')
console.log('autojsFileSync 开始')
autojsFileSync.start()
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms))
}
async function stop() {
await sleep(15000)
console.log('autojsFileSync 停止')
autojsFileSync.stop()
}
stop()
- 手机上autojs执行的代码, 将autojsProject文件夹从电脑同步到手机上.
var computerIP = '192.168.124.22'
var port = '3789' // 默认端口3789, 可指定别的端口
var projectName = 'autojsProject'
downLoad(projectName)
sleep(2000)
runProject()
function runProject() {
var filePath = files.join(files.getSdcardPath(), '脚本', projectName, 'index.js')
console.log('filePath=')
console.log(filePath)
engines.execScriptFile(filePath, { path: files.join(files.getSdcardPath(), '脚本', projectName) })
}
function downLoad(projectName) {
var projectFileList = getProjectFileList(projectName)
log('projectFileList=')
log(projectFileList)
projectFileList.map(filePath => {
downloadFile(filePath)
})
}
function downloadFile(filePath) {
var url = util.format('http://%s:%s/fileSync/project/file/%s', computerIP, port, filePath)
url = url.replace(/\s/g, '')
console.log(url)
var r = http.get(url)
r = r.body.bytes()
files.createWithDirs(filePath)
files.writeBytes(filePath, r)
}
function getProjectFileList(projectName) {
var url = util.format('http://%s:%s/fileSync/project/fileList/', computerIP, port, projectName)
url = url.replace(/\s/g, '')
console.log(url)
var r = http.get(url)
r = r.body.json()
return r
}