diff --git a/build.sh b/build.sh index ab081b4..6c59f5a 100755 --- a/build.sh +++ b/build.sh @@ -1,11 +1,15 @@ # 1. clean dist rm -rf ./dist -# 2. tsc compile +# 2. tsc compile `npm bin`/tsc -# 3. move resouce +# 3. move resource cp -r ./resource ./dist/resource +# 4. delete unused resource files +rm -rf ./dist/resource/swift/src +rm -rf ./dist/resource/swift/build.sh + # 4. replace ts-node to node grep -rl 'ts-node' ./dist/bin | xargs sed -i '' 's/ts-node/node/g' diff --git a/package.json b/package.json index a4e8790..7bc58c5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "macaca-macos", - "version": "0.2.32", + "version": "0.3.0", "description": "Macaca MacOS driver", "keywords": [ "macos", @@ -37,7 +37,6 @@ "macaca-ecosystem": "1", "mocha": "8", "nyc": "^13.1.0", - "power-assert": "^1.6.1", "ts-node": "^10.9.1", "typescript": "4" }, diff --git a/resource/swift/mouse-drag b/resource/swift/mouse-drag-arm64 similarity index 100% rename from resource/swift/mouse-drag rename to resource/swift/mouse-drag-arm64 diff --git a/resource/swift/mouse-drag-x64 b/resource/swift/mouse-drag-x64 new file mode 100755 index 0000000..2712f70 Binary files /dev/null and b/resource/swift/mouse-drag-x64 differ diff --git a/resource/swift/ocr b/resource/swift/ocr-arm64 similarity index 100% rename from resource/swift/ocr rename to resource/swift/ocr-arm64 diff --git a/resource/swift/ocr-x64 b/resource/swift/ocr-x64 new file mode 100755 index 0000000..a86488a Binary files /dev/null and b/resource/swift/ocr-x64 differ diff --git a/resource/swift/readme.md b/resource/swift/readme.md index da159f5..e5bbafd 100644 --- a/resource/swift/readme.md +++ b/resource/swift/readme.md @@ -11,4 +11,3 @@ bash ./build.sh - mouse-drag - mouse drag to (+x,+y) relate to current point - mouse-drag delay x y - diff --git a/src/core/jxa/osaUtil.ts b/src/core/jxa/osaUtil.ts index 03597e8..b8d18c4 100644 --- a/src/core/jxa/osaUtil.ts +++ b/src/core/jxa/osaUtil.ts @@ -7,7 +7,7 @@ const scptDir = `${Helper.getResourcePath()}/applescript/scpt`; // 直接执行 AppleScript 脚本/脚本包 export const osaUtil = { - async execAppleScriptStr(funcStr): Promise { + async execAppleScriptStr(funcStr: string): Promise { return new Promise((resolve, reject) => { applescript.execString(funcStr, (err, rtn) => { if (err) { diff --git a/src/driver/mouse.ts b/src/driver/mouse.ts index 1959502..f30ecd8 100644 --- a/src/driver/mouse.ts +++ b/src/driver/mouse.ts @@ -5,6 +5,9 @@ import { EDriver } from '../core/enums'; import { osaUtil } from '../core/jxa/osaUtil'; import { jxaUtil } from '../core/jxa/jxaUtil'; import ScreenDriver from './screen'; +import os from 'os'; +import assert from 'assert'; +import fs from 'fs'; export default class MouseDriver { mouseMoveTo(x: number, y: number) { @@ -92,7 +95,9 @@ export default class MouseDriver { } // default swift const curr_pos = this.mouseGetPos(); - shell.exec(`${Helper.getResourcePath()}/swift/mouse-drag 10 ${curr_pos.x} ${curr_pos.y} ${x} ${y}`, { silent: true }); + const cmdFile = `${Helper.getResourcePath()}/swift/mouse-drag-${os.arch()}`; + assert(fs.existsSync(cmdFile), `不支持的架构: ${os.arch()}`); + shell.exec(`${cmdFile} 10 ${curr_pos.x} ${curr_pos.y} ${x} ${y}`, { silent: true }); } mouseGetPos() { diff --git a/src/driver/screen.ts b/src/driver/screen.ts index 8d59532..87c250d 100644 --- a/src/driver/screen.ts +++ b/src/driver/screen.ts @@ -2,6 +2,8 @@ import shell from 'shelljs'; import robot from 'robotjs'; import fs from 'fs'; import { Helper } from '../core/helper'; +import os from 'os'; +import assert from 'assert'; export default class ScreenDriver { @@ -11,10 +13,17 @@ export default class ScreenDriver { * 暴露ocr方法,支持通过重写使用三方能力替代 */ async fileOcr(imgFile: string): Promise<{ - rect: { left, top, height, width }; + rect: { + left: number; + top: number; + height: number; + width: number; + }; word: string; }[]> { - const resStr = shell.exec(`${Helper.getResourcePath()}/swift/ocr ${imgFile}`, { silent: true }).stdout; + const cmdFile = `${Helper.getResourcePath()}/swift/ocr-${os.arch()}`; + assert(fs.existsSync(cmdFile), `不支持的架构: ${os.arch()}`); + const resStr = shell.exec(`${cmdFile} ${imgFile}`, { silent: true }).stdout; return JSON.parse(resStr); } @@ -100,7 +109,13 @@ export default class ScreenDriver { return resultList; } - screenGetSize() { + /** + * 含头部的系统状态栏 + */ + screenGetSize(): { + width: number; + height: number; + } { return robot.getScreenSize(); } diff --git a/test/jxaUtil.test.ts b/test/jxaUtil.test.ts index 4e3c242..f34e13b 100644 --- a/test/jxaUtil.test.ts +++ b/test/jxaUtil.test.ts @@ -1,6 +1,6 @@ import { jxaUtil } from '../src/core/jxa/jxaUtil'; import MacacaMacOS from '../src/macaca-macos'; -import assert from 'power-assert'; +import assert from 'assert'; describe.skip('jxaUtil unit testing', function() { diff --git a/test/macaca-macos.test.ts b/test/macaca-macos.test.ts index 852af3b..aacc151 100644 --- a/test/macaca-macos.test.ts +++ b/test/macaca-macos.test.ts @@ -1,13 +1,13 @@ import MacacaMacOS from '../src/macaca-macos'; import { Helper } from '../src/core/helper'; import { EDriver } from '../src/core/enums'; -import assert from 'power-assert'; +import assert from 'assert'; describe('macaca-macos unit testing', function() { this.timeout(0); process.env.MACACA_MACOS_DEBUG = 'true'; const driver = new MacacaMacOS(); - let res; + let res: any; it.skip('isAppRunning should be ok', async () => { this.timeout(0); diff --git a/test/osaUtil.test.ts b/test/osaUtil.test.ts index 40d26b5..1188eb5 100644 --- a/test/osaUtil.test.ts +++ b/test/osaUtil.test.ts @@ -1,6 +1,6 @@ import { osaUtil } from '../src/core/jxa/osaUtil'; import MacacaMacOS from '../src/macaca-macos'; -import assert from 'power-assert'; +import assert from 'assert'; describe('osaUtil unit testing', function() {