├── src ├── statics │ └── .gitkeep ├── assets │ └── project.json └── main.ts ├── .gitignore ├── types ├── index.d.ts ├── project │ ├── global.d.ts │ └── module.d.ts └── autox │ ├── modules │ ├── storages.d.ts │ ├── ocr.d.ts │ ├── media.d.ts │ ├── sensors.d.ts │ ├── colors.d.ts │ ├── global.d.ts │ ├── keys.d.ts │ ├── threads.d.ts │ ├── floaty.d.ts │ ├── root.d.ts │ ├── coordinate.d.ts │ ├── http.d.ts │ ├── ui.d.ts │ ├── console.d.ts │ ├── images.d.ts │ ├── files.d.ts │ ├── engines.d.ts │ ├── events.d.ts │ ├── app.d.ts │ ├── widgets.d.ts │ ├── dialogs.d.ts │ └── device.d.ts │ ├── adbkit.d.ts │ ├── auto.d.ts │ └── autojs.d.ts ├── tsup.config.ts ├── tsconfig.json ├── package.json └── README.md /src/statics/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # workspace 2 | .idea/ 3 | *.iws 4 | *.iml 5 | *.ipr 6 | 7 | # project 8 | dist/ 9 | node_modules/ 10 | package-lock.json 11 | *.lock 12 | *.log 13 | -------------------------------------------------------------------------------- /types/index.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | /// 5 | /// 6 | -------------------------------------------------------------------------------- /src/assets/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@lanaqi/autox-typescript-template", 3 | "versionName": "0.0.1", 4 | "versionCode": 1, 5 | "packageName": "com.lanaqi.autox.template", 6 | "main": "main.js", 7 | "launchConfig": { 8 | "hideLogs": false 9 | } 10 | } -------------------------------------------------------------------------------- /types/project/global.d.ts: -------------------------------------------------------------------------------- 1 | // 全局 2 | 3 | declare global { 4 | 5 | // 注入环境名称 6 | var injectEnvName: string; 7 | 8 | // 注入资源路径 9 | var injectAssetsPath: string; 10 | 11 | // 注入项目名称 12 | var injectProjectName: string; 13 | 14 | } 15 | 16 | export { 17 | }; 18 | -------------------------------------------------------------------------------- /types/autox/modules/storages.d.ts: -------------------------------------------------------------------------------- 1 | interface Storage { 2 | get(key: string, defaultValue?: T): T; 3 | put(key: string, value: T): void; 4 | remove(key: string): void; 5 | contains(key: string): boolean; 6 | clear(): void; 7 | } 8 | 9 | declare namespace storages { 10 | function create(name: string): Storage; 11 | function remove(name: string): boolean; 12 | } -------------------------------------------------------------------------------- /types/autox/modules/ocr.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | declare namespace paddle { 4 | 5 | function ocr(img: Image, cpuThreadNum?: number, useSlim?: boolean): string[]; 6 | 7 | function ocrText(img: Image, cpuThreadNum?: number, useSlim?: boolean): string[]; 8 | 9 | function release(): void; 10 | 11 | } 12 | 13 | declare namespace gmlkit { 14 | 15 | function ocr(img: Image, language: string): object; 16 | 17 | } 18 | -------------------------------------------------------------------------------- /types/autox/modules/media.d.ts: -------------------------------------------------------------------------------- 1 | declare namespace media { 2 | function scanFile(path: string): void; 3 | function playMusic(path: string, volume?: number, looping?: boolean); 4 | function musicSeekTo(msec: number): void; 5 | function pauseMusic(): void; 6 | function resumeMusic(): void; 7 | function stopMusic(): void; 8 | function isMusicPlaying(): boolean; 9 | function getMusicDuration(): number; 10 | function getMusicCurrentPosition(): number; 11 | } 12 | -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | function MyAnnotation(target: any) { 2 | target.prototype.name = '哈哈哈'; 3 | } 4 | 5 | @MyAnnotation 6 | class Person { 7 | 8 | public age: number; 9 | 10 | public name!: string; 11 | 12 | public constructor() { 13 | this.age = 18; 14 | } 15 | 16 | public toObject(): object { 17 | return { 18 | name: this.name, 19 | age: this.age, 20 | }; 21 | } 22 | 23 | } 24 | 25 | const p = new Person(); 26 | 27 | console.log('Person:', p.toObject()); 28 | -------------------------------------------------------------------------------- /types/autox/modules/sensors.d.ts: -------------------------------------------------------------------------------- 1 | declare namespace sensors { 2 | interface SensorEventEmitter { 3 | on(eventName: 'change', callback: (...args: number[]) => void): void; 4 | on(eventName: 'accuracy_change', callback: (accuracy: number) => void): void; 5 | } 6 | function on(eventName: 'unsupported_sensor', callback: (sensorName: string) => void): void; 7 | function register(sensorName: string, delay?: delay): SensorEventEmitter; 8 | function unregister(emitter: SensorEventEmitter); 9 | function unregisterAll(): void; 10 | var ignoresUnsupportedSensor: boolean; 11 | enum delay { 12 | normal, 13 | ui, 14 | game, 15 | fastest 16 | } 17 | } -------------------------------------------------------------------------------- /tsup.config.ts: -------------------------------------------------------------------------------- 1 | import { defineConfig, Options as TsupOptions } from 'tsup'; 2 | 3 | import { TsupConfigBuilder } from './build/TsupConfigBuilder'; 4 | 5 | // @ts-ignore 6 | import { name as packageName } from './package.json'; 7 | 8 | export default defineConfig((overrideOptions: TsupOptions) => 9 | TsupConfigBuilder.withNewConfig( 10 | overrideOptions, 11 | [ 12 | ], // 引用外部库(不打包) 13 | [ 14 | 'common-tags', // 可选库,如果不需要先在 package.json 中删除,再删除该依赖项 15 | ], // 引用内部库(会打包) 16 | packageName, // 项目包名 17 | true, // 是否匹配ui相关内容后自动添加'ui';到第一行 18 | {}, // 自定义注入变量(Record) 19 | // TsupConfigBuilder.ASSETS_PATH_PREFIX, // 覆盖资源前缀 20 | ), 21 | ); 22 | -------------------------------------------------------------------------------- /types/autox/modules/colors.d.ts: -------------------------------------------------------------------------------- 1 | declare namespace colors { 2 | function toString(color: number): string; 3 | function red(color: number | string): number; 4 | function green(color: number | string): number; 5 | function blue(color: number | string): number; 6 | function alpha(color: number | string): number; 7 | function rgb(red: number, green: number, blue: number): number; 8 | function argb(alpha: number, red: number, green: number, blue: number): number; 9 | function parseColor(colorStr: string): number; 10 | function isSimilar(color1: number | string, color2: number | string, threshold: number, algorithm: 'diff' | 'rgb' | 'rgb+' | 'hs'): boolean; 11 | function equals(color1: number | string, color2: number | string): boolean; 12 | } 13 | 14 | -------------------------------------------------------------------------------- /types/autox/modules/global.d.ts: -------------------------------------------------------------------------------- 1 | interface Point { 2 | x: number; 3 | y: number; 4 | } 5 | 6 | declare function sleep(n: number): void; 7 | 8 | declare function currentPackage(): string; 9 | 10 | declare function currentActivity(): string; 11 | 12 | declare function setClip(test: string): void; 13 | 14 | declare function getClip(): string; 15 | 16 | declare function toast(message: string): void; 17 | 18 | declare function toastLog(message: string): void; 19 | 20 | declare function waitForActivity(activity: string, period?: number): void; 21 | 22 | declare function waitForPackage(packageName: string, period?: number): void; 23 | 24 | declare function exit(): void; 25 | 26 | declare function random(): number; 27 | declare function random(min: number, max: number): number; 28 | 29 | declare function sync(handler: () => R): () => R; 30 | -------------------------------------------------------------------------------- /types/autox/modules/keys.d.ts: -------------------------------------------------------------------------------- 1 | declare function back(): boolean; 2 | declare function home(): boolean; 3 | declare function powerDialog(): boolean; 4 | declare function notifications(): boolean; 5 | declare function quickSettings(): boolean; 6 | declare function recents(): boolean; 7 | declare function splitScreen(): boolean; 8 | declare function Home(): void; 9 | declare function Back(): void; 10 | declare function Power(): void; 11 | declare function Menu(): void; 12 | declare function VolumeUp(): void; 13 | declare function VolumeDown(): void; 14 | declare function Camera(): void; 15 | declare function Up(): void; 16 | declare function Down(): void; 17 | declare function Left(): void; 18 | declare function Right(): void; 19 | declare function OK(): void; 20 | declare function Text(text: string): void; 21 | declare function KeyCode(code: number | string): void; 22 | -------------------------------------------------------------------------------- /types/autox/adbkit.d.ts: -------------------------------------------------------------------------------- 1 | 2 | // import * as a from "adbkit"; 3 | 4 | declare module "adbkit" { 5 | import { ReadStream } from "fs"; 6 | 7 | export interface TcpUsbServer { } 8 | 9 | export interface Connection { } 10 | 11 | export interface Device { 12 | id: string; 13 | type: string; 14 | } 15 | 16 | export interface Client { 17 | createTcpUsbBridge(serial: string): TcpUsbServer; 18 | connection(): Promise; 19 | version(): any; 20 | listDevices(): Promise; 21 | screencap(serial: string): Promise; 22 | } 23 | 24 | export interface ClientOptions { 25 | host?: string; 26 | port?: number; 27 | bin?: string; 28 | } 29 | 30 | export function createClient(options?: ClientOptions): Client; 31 | 32 | export var KeyCode: any; 33 | 34 | export var util: any; 35 | } -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "lib": [ 4 | "ES2015" 5 | ], 6 | "allowJs": true, 7 | "checkJs": false, 8 | "importHelpers": true, 9 | "strict": true, 10 | "noImplicitAny": false, 11 | "strictNullChecks": true, 12 | "noImplicitThis": true, 13 | "alwaysStrict": false, 14 | "noImplicitReturns": true, 15 | "allowUmdGlobalAccess": true, 16 | "experimentalDecorators": true, 17 | "emitDecoratorMetadata": false, // 注意:不支持该配置 18 | "resolveJsonModule": true, 19 | "baseUrl": ".", 20 | "paths": {}, 21 | "types": [ 22 | "node", 23 | "./types/index.d.ts" 24 | ], 25 | }, 26 | "include": [ 27 | "./src/**/*", 28 | "./lib/**/*" 29 | ], 30 | "exclude": [ 31 | "./.vscode/", 32 | "./build/", 33 | "./dist/", 34 | "./types/", 35 | "./src/assets/", 36 | "./src/statics/" 37 | ], 38 | "extends": "@tsconfig/recommended/tsconfig.json", 39 | "compileOnSave": true 40 | } -------------------------------------------------------------------------------- /types/autox/modules/threads.d.ts: -------------------------------------------------------------------------------- 1 | declare namespace threads { 2 | 3 | type ThreadTimerID = number; 4 | 5 | interface Thread { 6 | interrupt(): void; 7 | join(timeout?: number); 8 | isAlive(): boolean; 9 | waitFor(): void; 10 | setTimeout(callback: (...args: any[]) => void, delay: number, ...args: any[]): ThreadTimerID; 11 | setInterval(callback: (...args: any[]) => void, delay: number, ...args: any[]): ThreadTimerID; 12 | setImmediate(callback: (...args: any[]) => void, ...args: any[]): ThreadTimerID; 13 | clearInterval(id: ThreadTimerID): void; 14 | clearTimeout(id: ThreadTimerID): void; 15 | clearImmediate(id: ThreadTimerID): void; 16 | } 17 | 18 | function start(action): Thread; 19 | function shutDownAll(): void; 20 | function currentThread(): Thread; 21 | function disposable(): any; 22 | function atomic(initialValue?: number): any; 23 | function lock(): any; 24 | 25 | 26 | } -------------------------------------------------------------------------------- /types/autox/modules/floaty.d.ts: -------------------------------------------------------------------------------- 1 | declare namespace floaty { 2 | function window(layout: any): FloatyWindow; 3 | function rawWindow(layout: any): FloatyRawWindow; 4 | function closeAll(): void; 5 | function checkPermission(): boolean; 6 | function requestPermission(): void; 7 | interface FloatyWindow { 8 | setAdjustEnabled(enabled: boolean): void; 9 | setPosition(x: number, y: number): void; 10 | getX(): number; 11 | getY(): number; 12 | setSize(width: number, height: number): void; 13 | getWidht(): number; 14 | getHeight(): number; 15 | close(): void; 16 | exitOnClose(): void; 17 | } 18 | interface FloatyRawWindow { 19 | setTouchable(enabled: boolean): void; 20 | setPosition(x: number, y: number): void; 21 | getX(): number; 22 | getY(): number; 23 | setSize(width: number, height: number): void; 24 | getWidht(): number; 25 | getHeight(): number; 26 | close(): void; 27 | exitOnClose(): void; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /types/autox/auto.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | /// 5 | /// 6 | /// 7 | /// 8 | /// 9 | /// 10 | /// 11 | /// 12 | /// 13 | /// 14 | /// 15 | /// 16 | /// 17 | /// 18 | /// 19 | /// 20 | /// 21 | /// 22 | /// 23 | 24 | declare global { 25 | 26 | } 27 | 28 | export { }; -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@lanaqi/autox-typescript-template", 3 | "version": "0.0.1-alpha.1", 4 | "scripts": { 5 | "build:dev": "tsup --env.NODE_ENV=development", 6 | "build:prod": "tsup --env.NODE_ENV=production", 7 | "rerun:dev": "tsup --env.NODE_ENV=development --env.DEPLOY_ACTION=rerun", 8 | "rerun:prod": "tsup --env.NODE_ENV=production --env.DEPLOY_ACTION=rerun", 9 | "save:dev": "tsup --env.NODE_ENV=development --env.DEPLOY_ACTION=save", 10 | "save:prod": "tsup --env.NODE_ENV=production --env.DEPLOY_ACTION=save", 11 | "deploy:dev": "tsup --env.NODE_ENV=development --env.DEPLOY_ACTION=both", 12 | "deploy:prod": "tsup --env.NODE_ENV=production --env.DEPLOY_ACTION=both", 13 | "watch:dev": "tsup --env.NODE_ENV=development --env.DEPLOY_ACTION=rerun --env.IS_WATCH=true", 14 | "watch:prod": "tsup --env.NODE_ENV=production --env.DEPLOY_ACTION=rerun --env.IS_WATCH=true" 15 | }, 16 | "dependencies": { 17 | "common-tags": "^1.8.2" 18 | }, 19 | "devDependencies": { 20 | "@swc/core": "^1.3.68", 21 | "@tsconfig/recommended": "^1.0.2", 22 | "@types/node": "^20.4.1", 23 | "tslib": "^2.6.0", 24 | "tsup": "^7.1.0", 25 | "typescript": "^5.1.6" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /types/autox/modules/root.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * RootAutomator是一个使用root权限来模拟触摸的对象,用它可以完成触摸与多点触摸,并且这些动作的执行没有延迟。 3 | * 4 | * 一个脚本中最好只存在一个RootAutomator,并且保证脚本结束退出他。 5 | */ 6 | declare class RootAutomator { 7 | /** 8 | * 点击位置(x, y)。其中id是一个整数值,用于区分多点触摸,不同的id表示不同的"手指"。 9 | */ 10 | tap(x: number, y: number, id?: number): void; 11 | 12 | /** 13 | * 模拟一次从(x1, y1)到(x2, y2)的时间为duration毫秒的滑动。 14 | */ 15 | swipe(x1: number, x2: number, y1: number, y2: number, duration?: number): void; 16 | 17 | /** 18 | * 模拟按下位置(x, y),时长为duration毫秒。 19 | */ 20 | press(x: number, y: number, duration: number, id?: number): void; 21 | 22 | /** 23 | * 模拟长按位置(x, y)。 24 | */ 25 | longPress(x: number, y: number, duration?: number, id?: number): void; 26 | 27 | /** 28 | * 模拟手指按下位置(x, y)。 29 | */ 30 | touchDown(x: number, y: number, id?: number): void; 31 | 32 | /** 33 | * 模拟移动手指到位置(x, y)。 34 | */ 35 | touchMove(x: number, y: number, id?: number): void; 36 | 37 | /** 38 | * 模拟手指弹起。 39 | */ 40 | touchUp(id?: number): void; 41 | 42 | } 43 | 44 | /** 45 | * 需要Root权限 46 | * 47 | * 实验API,请勿过度依赖 48 | * 49 | * 点击位置(x, y), 您可以通过"开发者选项"开启指针位置来确定点击坐标。 50 | */ 51 | declare function Tap(x: number, y: number): void; 52 | 53 | /** 54 | * 需要Root权限 55 | * 56 | * 实验API,请勿过度依赖 57 | * 58 | * 滑动。从(x1, y1)位置滑动到(x2, y2)位置。 59 | */ 60 | declare function Swipe(x1: number, x2: number, y1: number, y2: number, duration?: number): void; 61 | -------------------------------------------------------------------------------- /types/autox/modules/coordinate.d.ts: -------------------------------------------------------------------------------- 1 | /* 基于坐标的触摸模拟 */ 2 | 3 | /** 4 | * 设置脚本坐标点击所适合的屏幕宽高。如果脚本运行时,屏幕宽度不一致会自动放缩坐标。 5 | */ 6 | declare function setScreenMetrics(width: number, height: number): void; 7 | 8 | /* 安卓7.0以上的触摸和手势模拟 */ 9 | 10 | /** 11 | * Android7.0以上 12 | * 13 | * 模拟点击坐标(x, y)大约150毫秒,并返回是否点击成功。只有在点击执行完成后脚本才继续执行。 14 | */ 15 | declare function click(x: number, y: number): void; 16 | 17 | /** 18 | * Android7.0以上 19 | * 20 | * 模拟长按坐标(x, y), 并返回是否成功。只有在长按执行完成(大约600毫秒)时脚本才会继续执行。 21 | */ 22 | declare function longClick(x: number, y: number): void; 23 | 24 | /** 25 | * Android7.0以上 26 | * 27 | * 模拟按住坐标(x, y), 并返回是否成功。只有按住操作执行完成时脚本才会继续执行。 28 | * 29 | * 如果按住时间过短,那么会被系统认为是点击;如果时长超过500毫秒,则认为是长按。 30 | */ 31 | declare function press(x: number, y: number, duration: number): void; 32 | 33 | /** 34 | * 模拟从坐标(x1, y1)滑动到坐标(x2, y2),并返回是否成功。只有滑动操作执行完成时脚本才会继续执行。 35 | */ 36 | declare function swipe(x1: number, y1: number, x2: number, y2: number, duration: number): boolean; 37 | 38 | type GesturePoint = [number, number]; 39 | /** 40 | * 模拟手势操作。例如gesture(1000, [0, 0], [500, 500], [500, 1000])为模拟一个从(0, 0)到(500, 500)到(500, 100)的手势操作,时长为2秒。 41 | */ 42 | declare function gesture(duration: number, point1: GesturePoint, point2: GesturePoint, ...points: GesturePoint[]): void; 43 | 44 | type Gesture = [number, number, GesturePoint, GesturePoint] | [number, GesturePoint, GesturePoint]; 45 | /** 46 | * 同时模拟多个手势。每个手势的参数为[delay, duration, 坐标], delay为延迟多久(毫秒)才执行该手势;duration为手势执行时长;坐标为手势经过的点的坐标。其中delay参数可以省略,默认为0。 47 | */ 48 | declare function gestures(gesture: Gesture, ...gestures: Gesture[]): void; 49 | -------------------------------------------------------------------------------- /types/autox/modules/http.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | declare namespace http { 4 | interface HttpRequestOptions { 5 | header: { [key: string]: string }, 6 | method: 'GET' | 'POST' | 'PUT' | 'DELET' | 'PATCH'; 7 | contentType: string; 8 | body: string | string[] | files.byte[] 9 | } 10 | interface Request { 11 | 12 | } 13 | interface Response { 14 | statusCode: number; 15 | statusMessage: string; 16 | headers: { [key: string]: string }; 17 | body: ResponseBody; 18 | request: Request; 19 | url: string; 20 | method: 'GET' | 'POST' | 'PUT' | 'DELET' | 'PATCH'; 21 | } 22 | interface ResponseBody { 23 | bytes(): files.byte[]; 24 | string(): string; 25 | json(): object; 26 | contentType: string; 27 | } 28 | function get(url: string, options?: HttpRequestOptions, callback?: (resp: Response) => void): Response; 29 | function post(url: string, data: object, options?: HttpRequestOptions, callback?: (resp: Response) => void): Response; 30 | function postJson(url: string, data?: object, options?: HttpRequestOptions, callback?: (resp: Response) => void): Response; 31 | 32 | interface RequestMultipartBody { 33 | file: ReadableTextFile | [string, string] | [string, string, string]; 34 | } 35 | function postMultipart(url: string, files: RequestMultipartBody, options?: HttpRequestOptions, callback?: (resp: Response) => void): void; 36 | function postMultipart(url: string, files: { [key: string]: string } & RequestMultipartBody, options?: HttpRequestOptions, callback?: (resp: Response) => void): void; 37 | 38 | function request(url: string, options?: HttpRequestOptions, callback?: (resp: Response) => void): void; 39 | 40 | } 41 | -------------------------------------------------------------------------------- /types/autox/modules/ui.d.ts: -------------------------------------------------------------------------------- 1 | // interface View { 2 | // w: 'auto' | '*' | number; 3 | // h: 'auto' | '*' | number; 4 | // id: string; 5 | // gravity: 'left' | 'right' | 'top' | 'bottom' | 'center' | 'center_vertical' | 'center_horizontal' | string; 6 | // layout_gravity: 'left' | 'right' | 'top' | 'bottom' | 'center' | 'center_vertical' | 'center_horizontal' | string; 7 | // margin: number | string; 8 | // marginLeft: number; 9 | // marginRight: number; 10 | // marginTop: number; 11 | // marginBottom: number; 12 | // padding 13 | // paddingLeft: number; 14 | // paddingRight: number; 15 | // paddingTop: number; 16 | // paddingBottom: number; 17 | // bg 18 | // alpha 19 | // foreground 20 | // minHeight 21 | // minWidth 22 | // visbility 23 | // rotation 24 | // transformPivotX 25 | // transformPivotY 26 | // style 27 | // } 28 | 29 | // interface UI { 30 | // [id: string]: View | ((...args: any[]) => any); 31 | // layout(xml: any): void; 32 | // inflate(xml: any, parent?: View): void; 33 | // findView(id: string): View; 34 | // finish() 35 | // setContentView(view: View) 36 | // run(callback) 37 | // post(callback, delay?: number): void; 38 | // statusBarColor(color) 39 | // showPopupMenu(view, menu) 40 | // } 41 | 42 | // declare const ui: UI; 43 | 44 | type View = any; 45 | 46 | interface UILike { 47 | toString(): string; 48 | } 49 | 50 | declare namespace ui { 51 | function layout(xml: UILike | any): void; 52 | function inflate(xml: UILike | any, parent?: View): void; 53 | function findView(id: string): View; 54 | function finish() 55 | function setContentView(view: View) 56 | function run(callback) 57 | function post(callback, delay?: number): void; 58 | function statusBarColor(color) 59 | function showPopupMenu(view, menu) 60 | } -------------------------------------------------------------------------------- /types/autox/modules/console.d.ts: -------------------------------------------------------------------------------- 1 | interface Console { 2 | /** 3 | * 显示控制台。这会显示一个控制台的悬浮窗(需要悬浮窗权限)。 4 | */ 5 | show(): void; 6 | 7 | /** 8 | * 隐藏控制台悬浮窗。 9 | */ 10 | hide(): void; 11 | 12 | /** 13 | * 清空控制台。 14 | */ 15 | clear(): void; 16 | 17 | /** 18 | * 打印到控制台,并带上换行符。 可以传入多个参数,第一个参数作为主要信息,其他参数作为类似于 printf(3) 中的代替值(参数都会传给 util.format())。 19 | */ 20 | log(data: string, ...args: any[]): void; 21 | 22 | /** 23 | * 与console.log类似,但输出结果以灰色字体显示。输出优先级低于log,用于输出观察性质的信息。 24 | */ 25 | verbose(data: string, ...args: any[]): void; 26 | 27 | /** 28 | * 与console.log类似,但输出结果以绿色字体显示。输出优先级高于log, 用于输出重要信息。 29 | */ 30 | info(data: string, ...args: any[]): void; 31 | 32 | /** 33 | * 与console.log类似,但输出结果以蓝色字体显示。输出优先级高于info, 用于输出警告信息。 34 | */ 35 | warn(data: string, ...args: any[]): void; 36 | 37 | /** 38 | * 与console.log类似,但输出结果以红色字体显示。输出优先级高于warn, 用于输出错误信息。 39 | */ 40 | error(data: string, ...args: any[]): void; 41 | 42 | /** 43 | * 断言。如果value为false则输出错误信息message并停止脚本运行。 44 | */ 45 | assert(value: boolean, message: string); 46 | 47 | /** 48 | * 与console.log一样输出信息,并在控制台显示输入框等待输入。按控制台的确认按钮后会将输入的字符串用eval计算后返回。 49 | */ 50 | input(data: string, ...args: any[]): string | number | boolean; 51 | 52 | /** 53 | * 与console.log一样输出信息,并在控制台显示输入框等待输入。按控制台的确认按钮后会将输入的字符串直接返回。 54 | */ 55 | rawInput(data: string, ...args: any[]): string; 56 | 57 | /** 58 | * 设置控制台的大小,单位像素。 59 | */ 60 | setSize(wight: number, height: number): void; 61 | 62 | /** 63 | * 设置控制台的位置,单位像素。 64 | */ 65 | setPosition(x: number, y: number): void; 66 | 67 | } 68 | 69 | /** 70 | * 打印到控制台,并带上换行符。 可以传入多个参数,第一个参数作为主要信息,其他参数作为类似于 printf(3) 中的代替值(参数都会传给 util.format())。 71 | */ 72 | declare function log(data: string, ...args: any[]): void; 73 | 74 | /** 75 | * 相当于log(text)。 76 | */ 77 | declare function print(message: string | Object): void; 78 | 79 | -------------------------------------------------------------------------------- /types/project/module.d.ts: -------------------------------------------------------------------------------- 1 | // 模板 2 | 3 | declare module "*.xml" { 4 | 5 | const content: string; 6 | 7 | export default content; 8 | 9 | } 10 | 11 | declare module "*.htm" { 12 | 13 | const content: string; 14 | 15 | export default content; 16 | 17 | } 18 | 19 | declare module "*.html" { 20 | 21 | const content: string; 22 | 23 | export default content; 24 | 25 | } 26 | 27 | // 图片 28 | 29 | declare module "*.jpg" { 30 | 31 | const content: string; 32 | 33 | export default content; 34 | 35 | } 36 | 37 | declare module "*.jpeg" { 38 | 39 | const content: string; 40 | 41 | export default content; 42 | 43 | } 44 | 45 | declare module "*.ico" { 46 | 47 | const content: string; 48 | 49 | export default content; 50 | 51 | } 52 | 53 | declare module "*.gif" { 54 | 55 | const content: string; 56 | 57 | export default content; 58 | 59 | } 60 | 61 | declare module "*.svg" { 62 | 63 | const content: string; 64 | 65 | export default content; 66 | 67 | } 68 | 69 | declare module "*.svgz" { 70 | 71 | const content: string; 72 | 73 | export default content; 74 | 75 | } 76 | 77 | declare module "*.webp" { 78 | 79 | const content: string; 80 | 81 | export default content; 82 | 83 | } 84 | 85 | declare module "*.png" { 86 | 87 | const content: string; 88 | 89 | export default content; 90 | 91 | } 92 | 93 | declare module "*.bmp" { 94 | 95 | const content: string; 96 | 97 | export default content; 98 | 99 | } 100 | 101 | // 文本 102 | 103 | declare module "*.md" { 104 | 105 | const content: string; 106 | 107 | export default content; 108 | 109 | } 110 | 111 | declare module "*.txt" { 112 | 113 | const content: string; 114 | 115 | export default content; 116 | 117 | } 118 | 119 | declare module "*.text" { 120 | 121 | const content: string; 122 | 123 | export default content; 124 | 125 | } 126 | -------------------------------------------------------------------------------- /types/autox/modules/images.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | interface Image { 4 | getWidth(): number; 5 | getHeight(): number; 6 | saveTo(path: string): void; 7 | pixel(x: number, y: number): number; 8 | recycle(): void; 9 | } 10 | 11 | 12 | declare namespace images { 13 | function requestScreenCapture(landscape?: boolean): boolean; 14 | function captureScreen(): Image; 15 | function captureScreen(path: string): void; 16 | function pixel(image: Image, x: number, y: number): number; 17 | function save(image: Image, path: string): void; 18 | function read(path: string): Image; 19 | function load(url: string): Image; 20 | function copy(image: Image): Image; 21 | function grayscale(image: Image): Image; 22 | interface FindColorOptions { 23 | region?: [number, number] | [number, number, number, number]; 24 | threshold?: number; 25 | } 26 | function clip(image: Image, x: number, y: number, w: number, h: number): Image; 27 | function findColor(image: Image, color: number | string, options?: FindColorOptions): Point; 28 | function findColorInRegion(image: Image, color: number | string, x: number, y: number, width?: number, height?: number, threshold?: number): Point; 29 | function findColorEquals(image: Image, color: number | string, x?: number, y?: number, width?: number, height?: number): Point; 30 | function detectsColor(image: Image, color: number | string, x: number, y: number, threshold?: number, algorithm?: 'diff'): Point; 31 | interface FindImageOptions { 32 | region?: [number, number] | [number, number, number, number]; 33 | threshold?: number; 34 | level?: number; 35 | } 36 | function findImage(image: Image, template: Image, options?: FindImageOptions): Point; 37 | function findImageInRegion(image: Image, template: Image, x: number, y: number, width?: number, height?: number, threshold?: number): Point; 38 | function findMultiColors(image: Image, firstColor: number | string, colors: [number, number, number | string][], options?: FindColorOptions): Point; 39 | 40 | function fromBase64(base64: string): Image; 41 | function toBase64(img: Image): string; 42 | } 43 | -------------------------------------------------------------------------------- /types/autox/modules/files.d.ts: -------------------------------------------------------------------------------- 1 | declare namespace files { 2 | type byte = number; 3 | function isFile(path: string): boolean; 4 | function isDir(path: string): boolean; 5 | function isEmptyDir(path: string): boolean; 6 | function join(parent: string, ...child: string[]): string; 7 | function create(path: string): boolean; 8 | function createWithDirs(path: string): boolean; 9 | function exists(path: string): boolean; 10 | function ensureDir(path: string): void; 11 | function read(path: string, encoding?: string): string; 12 | function readBytes(path: string): byte[]; 13 | function write(path: string, text, encoding?: string): void; 14 | function writeBytes(path: string, bytes: byte[]): void; 15 | function append(path: string, text: string, encoding?: string): void; 16 | function appendBytes(path: string, text: byte[], encoding?: string): void; 17 | function copy(frompath: string, topath: string): boolean; 18 | function move(frompath: string, topath: string): boolean; 19 | function rename(path: string, newName): boolean; 20 | function renameWithoutExtension(path: string, newName: string): boolean; 21 | function getName(path: string): string; 22 | function getNameWithoutExtension(path: string): string; 23 | function getExtension(path: string): string; 24 | function remove(path: string): boolean; 25 | function removeDir(path: string): boolean; 26 | function getSdcardPath(): string; 27 | function cwd(): string; 28 | function path(relativePath: string): string; 29 | function listDir(path: string, filter: (filename: string) => boolean): string[]; 30 | } 31 | 32 | interface ReadableTextFile { 33 | read(): string; 34 | read(maxCount: number): string; 35 | readline(): string; 36 | readlines(): string[]; 37 | close(): void; 38 | } 39 | 40 | interface WritableTextFile { 41 | write(text: string): void; 42 | writeline(line: string): void; 43 | writelines(lines: string[]): void; 44 | flush(): void; 45 | close(): void; 46 | } 47 | 48 | declare function open(path: string, mode?: 'r', encoding?: string, bufferSize?: number): ReadableTextFile; 49 | declare function open(path: string, mode?: 'w' | 'a', encoding?: string, bufferSize?: number): WritableTextFile; 50 | -------------------------------------------------------------------------------- /types/autox/modules/engines.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * engines模块包含了一些与脚本环境、脚本运行、脚本引擎有关的函数,包括运行其他脚本,关闭脚本等。 3 | */ 4 | declare namespace engines { 5 | 6 | /** 7 | * 脚本引擎对象。 8 | */ 9 | interface ScriptEngine { 10 | 11 | /** 12 | * 停止脚本引擎的执行。 13 | */ 14 | forceStop(): void; 15 | 16 | /** 17 | * 返回脚本执行的路径。对于一个脚本文件而言为这个脚本所在的文件夹;对于其他脚本,例如字符串脚本,则为null或者执行时的设置值。 18 | */ 19 | cwd(): string; 20 | } 21 | 22 | /** 23 | * 执行脚本时返回的对象,可以通过他获取执行的引擎、配置等,也可以停止这个执行。 24 | * 25 | * 要停止这个脚本的执行,使用exectuion.getEngine().forceStop(). 26 | */ 27 | interface ScriptExecution { 28 | 29 | /** 30 | * 返回执行该脚本的脚本引擎对象(ScriptEngine) 31 | */ 32 | getEngine(): ScriptEngine; 33 | 34 | /** 35 | * 返回该脚本的运行配置(ScriptConfig) 36 | */ 37 | getConfig(): ScriptConfig; 38 | } 39 | 40 | /** 41 | * 运行配置项。 42 | */ 43 | interface ScriptConfig { 44 | 45 | /** 46 | * 延迟执行的毫秒数,默认为0。 47 | */ 48 | delay?: number; 49 | 50 | /** 51 | * 循环运行次数,默认为1。0为无限循环。 52 | */ 53 | loopTimes?: number; 54 | 55 | /** 56 | * 循环运行时两次运行之间的时间间隔,默认为0。 57 | */ 58 | interval?: number; 59 | 60 | /** 61 | * 指定脚本运行的目录。这些路径会用于require时寻找模块文件。 62 | */ 63 | path?: string | string[]; 64 | 65 | /** 66 | * 返回一个字符串数组表示脚本运行时模块寻找的路径。 67 | */ 68 | getpath?: string[]; 69 | } 70 | 71 | /** 72 | * 在新的脚本环境中运行脚本script。返回一个ScriptExectuion对象。 73 | * 74 | * 所谓新的脚本环境,指定是,脚本中的变量和原脚本的变量是不共享的,并且,脚本会在新的线程中运行。 75 | */ 76 | function execScript(name: string, script: string, config?: ScriptConfig): ScriptExecution; 77 | 78 | /** 79 | * 在新的脚本环境中运行脚本文件path:string。返回一个ScriptExecution对象。 80 | */ 81 | function execScriptFile(path: string, config?: ScriptConfig): ScriptExecution; 82 | 83 | /** 84 | * 在新的脚本环境中运行录制文件path:string。返回一个ScriptExecution对象。 85 | */ 86 | function execAutoFile(path: string, config?: ScriptConfig): ScriptExecution; 87 | 88 | /** 89 | * 停止所有正在运行的脚本。包括当前脚本自身。 90 | */ 91 | function stopAll(): void; 92 | 93 | /** 94 | * 停止所有正在运行的脚本并显示停止的脚本数量。包括当前脚本自身。 95 | */ 96 | function stopAllAndToast(): void; 97 | 98 | /** 99 | * 返回当前脚本的脚本引擎对象(ScriptEngine) 100 | */ 101 | function myEngine(): void; 102 | } 103 | -------------------------------------------------------------------------------- /types/autox/modules/events.d.ts: -------------------------------------------------------------------------------- 1 | declare namespace events { 2 | 3 | interface KeyEvent { 4 | getAction(); 5 | getKeyCode(): number; 6 | getEventTime(): number; 7 | getDownTime(): number; 8 | keyCodeToString(keyCode: number): string; 9 | } 10 | 11 | function emitter(): EventEmitter; 12 | 13 | function observeKey(): void; 14 | 15 | type Keys = 'volume_up' | 'volume_down' | 'home' | 'back' | 'menu'; 16 | 17 | function setKeyInterceptionEnabled(key: Keys, enabled: boolean); 18 | 19 | function setKeyInterceptionEnabled(enabled: boolean); 20 | 21 | function onKeyDown(keyName: Keys, listener: (e: KeyEvent) => void): void; 22 | 23 | function onceKeyUp(keyName: Keys, listener: (e: KeyEvent) => void): void; 24 | 25 | function removeAllKeyDownListeners(keyName: Keys): void; 26 | 27 | function removeAllKeyUpListeners(keyName: Keys): void; 28 | 29 | function observeTouch(): void; 30 | 31 | function setTouchEventTimeout(timeout: number): void; 32 | 33 | function getTouchEventTimeout(): number; 34 | 35 | function onTouch(listener: (point: Point) => void): void; 36 | 37 | function removeAllTouchListeners(): void; 38 | 39 | function on(event: 'key' | 'key_down' | 'key_up', listener: (keyCode: number, e: KeyEvent) => void): void; 40 | 41 | function on(event: 'exit', listener: () => void): void; 42 | 43 | function observeNotification(): void; 44 | 45 | function observeToast(): void; 46 | 47 | /** 48 | * 系统Toast对象 49 | */ 50 | interface Toast { 51 | 52 | /** 53 | * 获取Toast的文本内容 54 | */ 55 | getText(): string; 56 | 57 | /** 58 | * 获取发出Toast的应用包名 59 | */ 60 | getPackageName(): void; 61 | 62 | } 63 | 64 | function onToast(listener: (toast: Toast) => void): void; 65 | 66 | /** 67 | * 通知对象,可以获取通知详情,包括通知标题、内容、发出通知的包名、时间等,也可以对通知进行操作,比如点击、删除。 68 | */ 69 | interface Notification { 70 | number: number; 71 | when: number; 72 | getPackageName(): string; 73 | getTitle(): string; 74 | getText(): string; 75 | click(): void; 76 | delete(): void; 77 | } 78 | 79 | function on(event: 'notification', listener: (notification: Notification) => void): void; 80 | 81 | } 82 | 83 | /** 84 | * 按键事件中所有可用的按键名称 85 | */ 86 | declare enum keys { 87 | home, 88 | back, 89 | menu, 90 | volume_up, 91 | volume_down 92 | } 93 | 94 | interface EventEmitter { 95 | defaultMaxListeners: number; 96 | addListener(eventName: string, listener: (...args: any[]) => void): EventEmitter; 97 | emit(eventName: string, ...args: any[]): boolean; 98 | eventNames(): string[]; 99 | getMaxListeners(): number; 100 | listenerCount(eventName: string): number; 101 | on(eventName: string, listener: (...args: any[]) => void): EventEmitter; 102 | once(eventName: string, listener: (...args: any[]) => void): EventEmitter; 103 | prependListener(eventName: string, listener: (...args: any[]) => void): EventEmitter; 104 | prependOnceListener(eventName: string, listener: (...args: any[]) => void): EventEmitter; 105 | removeAllListeners(eventName?: string): EventEmitter; 106 | removeListener(eventName: string, listener: (...args: any[]) => void): EventEmitter; 107 | setMaxListeners(n: number): EventEmitter; 108 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Autox TypeScript Template 2 | 3 | 基于 VsCode 开发 TypeScript 工程化的 Autox 模板。 4 | 5 | ## 工程结构 6 | 7 | - build 8 | 9 | 这个目录是构建支持,一般情况下不需要修改以及增加。 10 | 11 | - lib 12 | 13 | 这个目录是编写一些公共特征的库,可以划分模块,如 m1 / m2 然后再 tsconfig.json 文件中添加 paths 内容即可。 14 | 15 | paths:{ 16 | "@lanaqi/m1": [ 17 | './lib/m1/index.ts' 18 | ] 19 | } 20 | 21 | 其中 index.ts 内容示例如下: 22 | 23 | import A from "./dir/a"; 24 | 25 | export { 26 | A 27 | }; 28 | 29 | - src 30 | 31 | 这个目录是源码目录,其中 main.ts 是入口文件。 32 | 其中 ./src/assets/ 是资源目录。 33 | 34 | 多项目结构: 35 | ./src/${projectName}/main.ts 以及 ./src/${projectName}/assets/ 36 | 另外需要覆盖环境变量:PROJECT_NAME , 如 -env.PROJECT_NAME=a 这样。 37 | 需要注意的是,多项目时 tsup.config.ts 不需要传递 packageName 参数。 38 | 39 | export default defineConfig((overrideOptions: TsupOptions) => TsupConfigBuilder.withNewConfig(overrideOptions)); 40 | 41 | 更多参考:./build/ 中实现的源码。 42 | 43 | - types 44 | 45 | 这个目录是类型声明目录,声明一些公共库或注入变量等。 46 | 47 | - dist 48 | 49 | 这个目录是构建输出,编译后生成的源码以及资源在这个目录下,这个目录下以项目名方式分类,如下: 50 | dist/a 51 | dist/b 52 | 53 | - .gitignore 54 | 55 | 通用 git 忽略配置文件,可自行修改。 56 | 57 | - package.json 58 | 59 | 项目描述文件,可自行修改(一般情况下只需要修改 name & version 即可,多项目下需要注意传递项目名)。 60 | 61 | - tsconfig.json 62 | 63 | TypeScript 配置文件,一般情况下按需修改。 64 | 65 | - tsup.config.ts 66 | 67 | Tsup 配置文件,一般情况下单项目不需要修改。 68 | 69 | ## 使用步骤 70 | 71 | 1. 复制工程目录所有到你的项目中。 72 | 2. 打开 VsCode 开启服务并监听 ADB 设备。 73 | 3. 使用 Autox.js 连接 VsCode 监听。 74 | 4. 运行项目中 scripts 即可。 75 | 5. 使用资源文件时,需先部署,否则无法读取(可以修改 DEPLOY_ACTION 为 both 值)。 76 | 77 | ## 编码方式 78 | 79 | 应遵守以下代码编写方式。 80 | 81 | ### 导入模块方式 82 | 83 | ``` js 84 | 85 | // 不要这样 86 | var circle = require('circle.js'); 87 | console.log("半径为 4 的圆的面积是 %d", circle.area(4)); 88 | 89 | // 应该这样(这个 circle.js 应遵守 es5+ 标准) 90 | import circle from './circle'; 91 | console.log("半径为 4 的圆的面积是 %d", circle.area(4)); 92 | 93 | ``` 94 | 95 | ### 导入静态资源 96 | 97 | 建议把这一类放置 src/static 目录下。 98 | 99 | ``` ts 100 | 101 | // 支持后缀:jpg / jpeg / ico / gif / svg / svgz / webp / png / bmp 102 | import png from './my.png'; 103 | 104 | // 同时也支持对 .md / .txt / .text 文件读取为文本字符串 105 | import txt from './test.txt'; 106 | 107 | ``` 108 | 109 | ### 编写 UI 方式 110 | 111 | ``` jsx 112 | 113 | // 在原始 js 中使用 ui 时,必须先在 main.js 的顶部 "ui"; 声明。 114 | // 在这里不必声明,会自动注入,当使用 ui. 时注入。 115 | 116 | // 不要这样 117 | ui.layout( 118 | 119 |