├── .gitignore
├── README.md
├── build
├── AutoxDeployExecutor.ts
└── TsupConfigBuilder.ts
├── package.json
├── src
├── assets
│ └── project.json
├── main.ts
└── statics
│ └── .gitkeep
├── tsconfig.json
├── tsup.config.ts
└── types
├── autox
├── adbkit.d.ts
├── auto.d.ts
├── autojs.d.ts
└── modules
│ ├── app.d.ts
│ ├── colors.d.ts
│ ├── console.d.ts
│ ├── coordinate.d.ts
│ ├── device.d.ts
│ ├── dialogs.d.ts
│ ├── engines.d.ts
│ ├── events.d.ts
│ ├── files.d.ts
│ ├── floaty.d.ts
│ ├── global.d.ts
│ ├── http.d.ts
│ ├── images.d.ts
│ ├── keys.d.ts
│ ├── media.d.ts
│ ├── ocr.d.ts
│ ├── root.d.ts
│ ├── sensors.d.ts
│ ├── storages.d.ts
│ ├── threads.d.ts
│ ├── ui.d.ts
│ └── widgets.d.ts
├── index.d.ts
└── project
├── global.d.ts
└── module.d.ts
/.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 |
--------------------------------------------------------------------------------
/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 |
120 |
121 |
122 | );
123 |
124 | // 静态模板(如果可以还是使用静态模板比较好)
125 | // 建议放到 html 目录下(该目录受监控变动处理)
126 | import mainHtml from './html/main.html';
127 | import png from './my.png';
128 | ui.layout(mainHtml);
129 | // 动态修改属性
130 | const myImg = ui.findView('id');
131 | myImg.attr('src', `data:image/png;base64,${png}`);
132 |
133 | // 动态模板
134 | // 应该这样,更多参考:https://github.com/zspecza/common-tags
135 | import { html } from 'common-tags';
136 | import png from './my.png';
137 |
138 | ui.layout(html`
139 |
140 |
141 |
142 |
143 |
144 | `);
145 |
146 | ```
147 |
148 | ### 不推荐编码
149 |
150 | ``` ts
151 |
152 | // 尽量不要用 require 函数(某些情况下也需要该方式,如导入第三方库)
153 | require('./test.txt');
154 |
155 | ```
156 |
--------------------------------------------------------------------------------
/build/AutoxDeployExecutor.ts:
--------------------------------------------------------------------------------
1 | import nodeHttp from 'http';
2 | import nodePath from 'path';
3 |
4 | // Autox 部署动作
5 | export declare type AutoxDeployAction = 'none' | 'both' | 'save' | 'rerun';
6 |
7 | // Autox 部署执行器
8 | export class AutoxDeployExecutor {
9 |
10 | // 输出目录值
11 | private static DIST_PATH: string = './dist';
12 |
13 | // 输出主文件值
14 | private static MAIN_PATH: string = './main.js';
15 |
16 | public constructor() {
17 | }
18 |
19 | // 发送部署命令
20 | private sendDeployCmd(execCmd: string, sendPath: string, deployName: string): void {
21 | const req = nodeHttp.get(`http://127.0.0.1:9317/exec?cmd=${execCmd}&path=${encodeURI(sendPath)}`, (res) => {
22 | res.setEncoding('utf8');
23 | res.addListener('data', (data) => {
24 | console.debug('部署执行器: %s -> 执行命令成功!- data: %s', deployName, data);
25 | }).addListener('error', (error) => {
26 | console.error('部署执行器: %s -> 执行命令失败!- error: %s', deployName, error);
27 | });
28 | });
29 | req.addListener('finish', () => {
30 | console.debug('部署执行器: %s -> 发送命令成功! - cmd: %s ; path: %s', deployName, execCmd, sendPath);
31 | });
32 | req.addListener('error', (error) => {
33 | console.error('部署执行器: %s -> 发送命令失败!- error: %s', deployName, error);
34 | });
35 | }
36 |
37 | // 获取输出目录值
38 | private getDistPath(deployName: string): string {
39 | return `/${nodePath.resolve(AutoxDeployExecutor.DIST_PATH, deployName)}`;
40 | }
41 |
42 | // 获取输出主文件值
43 | private getMainPath(deployName: string): string {
44 | return `/${nodePath.resolve(AutoxDeployExecutor.DIST_PATH, deployName, AutoxDeployExecutor.MAIN_PATH)}`;
45 | }
46 |
47 | // 执行重新运行命令
48 | private execRerunCmd(deployName: string): void {
49 | this.sendDeployCmd('rerun', this.getMainPath(deployName), deployName);
50 | }
51 |
52 | // 执行保存命令
53 | private execSaveCmd(deployName: string): void {
54 | this.sendDeployCmd('save', this.getDistPath(deployName), deployName);
55 | }
56 |
57 | // 解析部署名称
58 | public resolveDeployName(projectName?: string): string {
59 | if (projectName) {
60 | return projectName;
61 | }
62 | // 这里可以修改一些自定义解析处理
63 | throw new Error('部署执行器: -> 解析错误,未知部署名称!');
64 | }
65 |
66 | // 执行部署项目
67 | public execDeployProject(deployAction: AutoxDeployAction, projectName?: string): void {
68 | const deployName: string = this.resolveDeployName(projectName);
69 | switch (deployAction) {
70 | case 'save':
71 | this.execSaveCmd(deployName);
72 | console.info('部署执行器: %s -> 完成保存!', deployName);
73 | break;
74 | case 'rerun':
75 | this.execRerunCmd(deployName);
76 | console.info('部署执行器: %s -> 完成重新运行!', deployName);
77 | break;
78 | case 'both':
79 | this.execSaveCmd(deployName);
80 | this.execRerunCmd(deployName);
81 | console.info('部署执行器: %s -> 完成保存并重新运行!', deployName);
82 | break;
83 | case 'none':
84 | default:
85 | console.info('部署执行器: %s -> 没有需要执行的动作!', deployName);
86 | break;
87 | }
88 | }
89 |
90 | }
91 |
--------------------------------------------------------------------------------
/build/TsupConfigBuilder.ts:
--------------------------------------------------------------------------------
1 | import { Options as TsupOptions } from 'tsup';
2 |
3 | import { AutoxDeployAction, AutoxDeployExecutor } from './AutoxDeployExecutor';
4 |
5 | // Tsup 运行环境
6 | export declare type TsupNodeEnv = 'production' | 'development';
7 |
8 | // Tsup 排除库
9 | export declare type TsupExternal = (string | RegExp)[];
10 |
11 | // Tsup 打包库
12 | export declare type TsupNoExternal = (string | RegExp)[];
13 |
14 | // Tsup 配置构建器
15 | export class TsupConfigBuilder {
16 |
17 | // 运行环境
18 | private static NODE_ENV_KEY: string = 'NODE_ENV';
19 |
20 | // 是否监控变动
21 | private static IS_WATCH_KEY: string = 'IS_WATCH';
22 |
23 | // 部署动作
24 | private static DEPLOY_ACTION_KEY: string = 'DEPLOY_ACTION';
25 |
26 | // 项目名称
27 | private static PROJECT_NAME_KEY: string = 'PROJECT_NAME';
28 |
29 | // 资源值前缀(非打包时,部署的资源路径)
30 | public static ASSETS_PATH_PREFIX: string = '/sdcard/脚本';
31 |
32 | // 覆盖可选
33 | private overrideOptions: TsupOptions;
34 |
35 | // 部署执行器
36 | private deployExecutor: AutoxDeployExecutor;
37 |
38 | public constructor(overrideOptions: TsupOptions) {
39 | this.overrideOptions = overrideOptions;
40 | this.deployExecutor = new AutoxDeployExecutor();
41 | }
42 |
43 | // 获取覆盖环境
44 | private getOverrideEnv(envName: string): undefined | string {
45 | if (this.overrideOptions.env) {
46 | return this.overrideOptions.env[envName];
47 | } else {
48 | return undefined;
49 | }
50 | }
51 |
52 | // 获取运行环境
53 | private getNodeEnv(): TsupNodeEnv {
54 | const nodeEnv = this.getOverrideEnv(TsupConfigBuilder.NODE_ENV_KEY);
55 | if (nodeEnv) {
56 | return nodeEnv as TsupNodeEnv;
57 | } else {
58 | return 'development';
59 | }
60 | }
61 |
62 | // 是否生产环境
63 | private isProdEnv(): boolean {
64 | return 'production' === this.getNodeEnv();
65 | }
66 |
67 | // 获取是否监控变动
68 | private getIsWatch(): boolean {
69 | const isWatch = this.getOverrideEnv(TsupConfigBuilder.IS_WATCH_KEY);
70 | if (isWatch) {
71 | return isWatch === 'true';
72 | } else {
73 | return false;
74 | }
75 | }
76 |
77 | // 获取部署动作
78 | private getDeployAction(): AutoxDeployAction {
79 | const deployAction = this.getOverrideEnv(TsupConfigBuilder.DEPLOY_ACTION_KEY);
80 | if (deployAction) {
81 | return deployAction as AutoxDeployAction;
82 | } else {
83 | return 'none';
84 | }
85 | }
86 |
87 | // 获取项目名称
88 | private getProjectName(): string {
89 | const projectName = this.getOverrideEnv(TsupConfigBuilder.PROJECT_NAME_KEY);
90 | if (projectName) {
91 | return projectName;
92 | } else {
93 | return 'unknown';
94 | }
95 | }
96 |
97 | // 构建定义对象
98 | private buildDefineObject(isProd: boolean, projectName: string, injectVariable: Record = {}, assetsPrefix?: string): Record {
99 | let assetsPath;
100 | if (assetsPrefix) {
101 | assetsPath = `${assetsPrefix}/${projectName}`;
102 | } else {
103 | if (isProd) {
104 | assetsPath = '.';
105 | } else {
106 | assetsPath = `${TsupConfigBuilder.ASSETS_PATH_PREFIX}/${projectName}`;
107 | }
108 | }
109 | return {
110 | 'injectEnvName': `"${this.getNodeEnv()}"`,
111 | 'injectAssetsPath': `"${assetsPath}"`,
112 | 'injectProjectName': `'${projectName}'`,
113 | ...injectVariable,
114 | };
115 | }
116 |
117 | // 构建定义配置
118 | // 单项目结构:./.vscode/ | ./build/ | ./lib/ | ./node_modules/ | ./types/ | ./src/ |
119 | // 多项目结构:./.vscode/ | ./build/ | ./lib/ | ./node_modules/ | ./types/ | ./src/${projectName} |
120 | public buildDefineConfig(external: TsupExternal, noExternal: TsupNoExternal, packageName?: string, uiMatch?: boolean, injectVariable?: Record, assetsPrefix?: string): TsupOptions {
121 | const isOne = Boolean(packageName);
122 | const isProd = this.isProdEnv();
123 | const isWatch = this.getIsWatch();
124 | const deployAction = this.getDeployAction();
125 | let projectName = isOne ? packageName as string : this.getProjectName();
126 | if (projectName.lastIndexOf('/') !== -1) {
127 | const splitNames = projectName.split('/');
128 | projectName = splitNames[splitNames.length - 1];
129 | }
130 | // 入口文件
131 | let entryFiles: string[];
132 | // 监控变动源码目录
133 | let watchSrcDir: string;
134 | // 资源目录
135 | let assetsDir: string;
136 | // 忽略监控变动静态目录
137 | let ignoreWatchStatics: string;
138 | if (isOne) {
139 | entryFiles = [
140 | './src/main.ts',
141 | './src/test.ts',
142 | './src/ui.ts',
143 | ];
144 | watchSrcDir = './src/';
145 | assetsDir = './src/assets/';
146 | ignoreWatchStatics = './src/statics/';
147 | } else {
148 | entryFiles = [
149 | `./src/${projectName}/main.ts`,
150 | `./src/${projectName}/test.ts`,
151 | `./src/${projectName}/ui.ts`,
152 | ];
153 | watchSrcDir = `./src/${projectName}/`;
154 | assetsDir = `./src/${projectName}/assets/`;
155 | ignoreWatchStatics = `./src/${projectName}/statics/`;
156 | }
157 | return {
158 | name: projectName,
159 | entry: entryFiles,
160 | target: 'es5',
161 | minify: isProd,
162 | watch: isWatch ? [
163 | watchSrcDir,
164 | './lib/',
165 | ] : false,
166 | ignoreWatch: [
167 | './.vscode/',
168 | './build/',
169 | './types/',
170 | ignoreWatchStatics,
171 | ],
172 | onSuccess: async () => {
173 | this.deployExecutor.execDeployProject(deployAction, projectName);
174 | },
175 | outDir: `dist/${projectName}`,
176 | define: this.buildDefineObject(isProd, projectName, injectVariable, assetsPrefix),
177 | external: external,
178 | noExternal: noExternal,
179 | replaceNodeEnv: true,
180 | clean: true,
181 | tsconfig: 'tsconfig.json',
182 | publicDir: assetsDir,
183 | platform: 'node',
184 | loader: {
185 | // 把所有图片后缀使用 base64 加载器
186 | '.jpg': 'base64',
187 | '.jpeg': 'base64',
188 | '.ico': 'base64',
189 | '.gif': 'base64',
190 | '.svg': 'base64',
191 | '.svgz': 'base64',
192 | '.webp': 'base64',
193 | '.png': 'base64',
194 | '.bmp': 'base64',
195 | // 把所有 .txt / .text 使用 text 加载器
196 | '.md': 'text',
197 | '.txt': 'text',
198 | '.text': 'text',
199 | // 把所有 .htm / .html 使用 text 加载器
200 | '.htm': 'text',
201 | '.html': 'text',
202 | // 把所有 .xml 使用 text 加载器
203 | '.xml': 'text',
204 | },
205 | plugins: [
206 | // 把所有 "ui"; 删除,在顶部添加 "ui"; 声明
207 | {
208 | name: 'replace-ui-declare',
209 | renderChunk: async (compileCode, chunkInfo) => {
210 | if (compileCode.lastIndexOf('"ui";') > -1 || compileCode.lastIndexOf("'ui';") > -1 || (uiMatch && compileCode.lastIndexOf('ui.') > -1)) {
211 | return {
212 | code: `"ui";\n${compileCode.replace('"ui";', '').replace("'ui';", '')}`,
213 | map: chunkInfo.map,
214 | };
215 | } else {
216 | return {
217 | code: compileCode,
218 | map: chunkInfo.map,
219 | };
220 | }
221 | },
222 | }
223 | ],
224 | }
225 | }
226 |
227 | // 使用新的配置
228 | public static withNewConfig(overrideOptions: TsupOptions, external: TsupExternal, noExternal: TsupNoExternal, packageName?: string, uiMatch?: boolean, injectVariable?: Record, assetsPrefix?: string): TsupOptions {
229 | return new TsupConfigBuilder(overrideOptions).buildDefineConfig(external, noExternal, packageName, uiMatch, injectVariable, assetsPrefix);
230 | }
231 |
232 | }
233 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 | }
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/src/statics/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lanaqi-opensource/autox-typescript-template/fed7dfda185a0b9a95fadd9a4d4ab8a01ffad2be/src/statics/.gitkeep
--------------------------------------------------------------------------------
/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 | }
--------------------------------------------------------------------------------
/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/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 | }
--------------------------------------------------------------------------------
/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 { };
--------------------------------------------------------------------------------
/types/autox/autojs.d.ts:
--------------------------------------------------------------------------------
1 | /* 内置模块 */
2 |
3 | /*
4 | * based on commit "cf1e602"
5 | * 文件结构
6 | *
7 | * -模块
8 | * -命名空间
9 | * -全局
10 | *
11 | * 未加入:WidgetsBasedAutomation、Shell、Thread、UI、Work with Java
12 | *
13 | */
14 | declare module 'global' {
15 |
16 | /**
17 | * 表示一个点(坐标)。
18 | */
19 | interface Point {
20 | x: number;
21 | y: number;
22 | }
23 |
24 | /**
25 | * app模块提供一系列函数,用于使用其他应用、与其他应用交互。例如发送意图、打开文件、发送邮件等。
26 | */
27 | namespace app {
28 |
29 | /**
30 | * 通过应用名称启动应用。如果该名称对应的应用不存在,则返回false; 否则返回true。如果该名称对应多个应用,则只启动其中某一个。
31 | */
32 | function launchApp(appName: string): boolean;
33 |
34 | /**
35 | * 通过应用包名启动应用。如果该包名对应的应用不存在,则返回false;否则返回true。
36 | */
37 | function launch(packageName: string): boolean;
38 |
39 | /**
40 | * 通过应用包名启动应用。如果该包名对应的应用不存在,则返回false;否则返回true。
41 | */
42 | function launchPackage(packageName: string): boolean;
43 |
44 | /**
45 | * 获取应用名称对应的已安装的应用的包名。如果该找不到该应用,返回null;如果该名称对应多个应用,则只返回其中某一个的包名。
46 | */
47 | function getPackageName(appName: string): string;
48 |
49 | /**
50 | * 获取应用包名对应的已安装的应用的名称。如果该找不到该应用,返回null。
51 | */
52 | function getAppName(packageName: string): string;
53 |
54 | /**
55 | * 打开应用的详情页(设置页)。如果找不到该应用,返回false; 否则返回true。
56 | */
57 | function openAppSetting(packageName: string): boolean;
58 |
59 | /**
60 | * 用其他应用查看文件。文件不存在的情况由查看文件的应用处理。如果找不出可以查看该文件的应用,则抛出ActivityNotException。
61 | *
62 | * @throws ActivityNotException
63 | */
64 | function viewFile(path: string): void;
65 |
66 | /**
67 | * 用其他应用编辑文件。文件不存在的情况由编辑文件的应用处理。如果找不出可以编辑该文件的应用,则抛出ActivityNotException。
68 | *
69 | * @throws ActivityNotException
70 | */
71 | function editFile(path: string): void;
72 |
73 | /**
74 | * 卸载应用。执行后会会弹出卸载应用的提示框。如果该包名的应用未安装,由应用卸载程序处理,可能弹出"未找到应用"的提示。
75 | */
76 | function uninstall(packageName: string): void;
77 |
78 | /**
79 | * 用浏览器打开网站url。网站的Url,如果不以"http:// "或"https:// "开头则默认是"http:// "。
80 | */
81 | function openUrl(url: string): void;
82 |
83 | /**
84 | * 发送邮件的参数,这些选项均是可选的。
85 | */
86 | interface SendEmailOptions {
87 | /**
88 | * 收件人的邮件地址。如果有多个收件人,则用字符串数组表示
89 | */
90 | email?: string | string[];
91 | /**
92 | * 抄送收件人的邮件地址。如果有多个抄送收件人,则用字符串数组表示
93 | */
94 | cc?: string | string[];
95 | /**
96 | * 密送收件人的邮件地址。如果有多个密送收件人,则用字符串数组表示
97 | */
98 | bcc?: string | string[];
99 | /**
100 | * 邮件主题(标题)
101 | */
102 | subject?: string;
103 | /**
104 | * 邮件正文
105 | */
106 | text?: string;
107 | /**
108 | * 附件的路径。
109 | */
110 | attachment?: string;
111 | }
112 |
113 | /**
114 | * 根据选项options调用邮箱应用发送邮件。如果没有安装邮箱应用,则抛出ActivityNotException。
115 | */
116 | function sendEmail(options: SendEmailOptions): void;
117 |
118 | /**
119 | * 启动Auto.js的特定界面。该函数在Auto.js内运行则会打开Auto.js内的界面,在打包应用中运行则会打开打包应用的相应界面。
120 | */
121 | function startActivity(name: 'console' | 'settings'): void;
122 |
123 | /**
124 | * Intent(意图) 是一个消息传递对象,您可以使用它从其他应用组件请求操作。尽管 Intent 可以通过多种方式促进组件之间的通信.
125 | */
126 | interface Intent { }
127 |
128 | /**
129 | * 构造意图Intent对象所需设置。
130 | */
131 | interface IntentOptions {
132 | action?: string;
133 | type?: string;
134 | data?: string;
135 | category?: string[];
136 | packageName?: string;
137 | className?: string;
138 | extras?: Object;
139 | }
140 |
141 | /**
142 | * 根据选项,构造一个意图Intent对象。
143 | */
144 | function intent(options: IntentOptions): Intent;
145 |
146 | /**
147 | * 根据选项构造一个Intent,并启动该Activity。
148 | */
149 | function startActivity(intent: Intent): void;
150 |
151 | /**
152 | * 根据选项构造一个Intent,并发送该广播。
153 | */
154 | function sendBroadcast(intent: Intent): void;
155 | }
156 |
157 | /**
158 | * 通过应用名称启动应用。如果该名称对应的应用不存在,则返回false; 否则返回true。如果该名称对应多个应用,则只启动其中某一个。
159 | */
160 | function launchApp(appName: string): boolean;
161 |
162 | /**
163 | * 通过应用包名启动应用。如果该包名对应的应用不存在,则返回false;否则返回true。
164 | */
165 | function launch(packageName: string): boolean;
166 |
167 | /**
168 | * 获取应用名称对应的已安装的应用的包名。如果该找不到该应用,返回null;如果该名称对应多个应用,则只返回其中某一个的包名。
169 | */
170 | function getPackageName(appName: string): string;
171 |
172 | /**
173 | * 获取应用名称对应的已安装的应用的包名。如果该找不到该应用,返回null;如果该名称对应多个应用,则只返回其中某一个的包名。
174 | */
175 | function getPackageName(appName: string): string;
176 |
177 | /**
178 | * 获取应用包名对应的已安装的应用的名称。如果该找不到该应用,返回null。
179 | */
180 | function getAppName(packageName: string): string;
181 |
182 | /**
183 | * 打开应用的详情页(设置页)。如果找不到该应用,返回false; 否则返回true。
184 | */
185 | function openAppSetting(packageName: string): boolean;
186 |
187 |
188 | // interface Console {
189 | // show(): void;
190 | // verbose(): void;
191 | // }
192 |
193 | /**
194 | * 控制台模块提供了一个和Web浏览器中相似的用于调试的控制台。用于输出一些调试信息、中间结果等。 console模块中的一些函数也可以直接作为全局函数使用,例如log, print等。
195 | */
196 | namespace console {
197 |
198 | /**
199 | * 显示控制台。这会显示一个控制台的悬浮窗(需要悬浮窗权限)。
200 | */
201 | function show(): void;
202 |
203 | /**
204 | * 隐藏控制台悬浮窗。
205 | */
206 | function hide(): void;
207 |
208 | /**
209 | * 清空控制台。
210 | */
211 | function clear(): void;
212 |
213 | /**
214 | * 打印到控制台,并带上换行符。 可以传入多个参数,第一个参数作为主要信息,其他参数作为类似于 printf(3) 中的代替值(参数都会传给 util.format())。
215 | */
216 | function log(data: string, ...args: any[]): void;
217 |
218 | /**
219 | * 与console.log类似,但输出结果以灰色字体显示。输出优先级低于log,用于输出观察性质的信息。
220 | */
221 | function verbose(data: string, ...args: any[]): void;
222 |
223 | /**
224 | * 与console.log类似,但输出结果以绿色字体显示。输出优先级高于log, 用于输出重要信息。
225 | */
226 | function info(data: string, ...args: any[]): void;
227 |
228 | /**
229 | * 与console.log类似,但输出结果以蓝色字体显示。输出优先级高于info, 用于输出警告信息。
230 | */
231 | function warn(data: string, ...args: any[]): void;
232 |
233 | /**
234 | * 与console.log类似,但输出结果以红色字体显示。输出优先级高于warn, 用于输出错误信息。
235 | */
236 | function error(data: string, ...args: any[]): void;
237 |
238 | /**
239 | * 断言。如果value为false则输出错误信息message并停止脚本运行。
240 | */
241 | function assert(value: boolean, message: string);
242 |
243 | /**
244 | * 与console.log一样输出信息,并在控制台显示输入框等待输入。按控制台的确认按钮后会将输入的字符串用eval计算后返回。
245 | */
246 | function input(data: string, ...args: any[]): string | number | boolean;
247 |
248 | /**
249 | * 与console.log一样输出信息,并在控制台显示输入框等待输入。按控制台的确认按钮后会将输入的字符串直接返回。
250 | */
251 | function rawInput(data: string, ...args: any[]): string;
252 |
253 | /**
254 | * 设置控制台的大小,单位像素。
255 | */
256 | function setSize(wight: number, height: number): void;
257 |
258 | /**
259 | * 设置控制台的位置,单位像素。
260 | */
261 | function setPosition(x: number, y: number): void;
262 |
263 | }
264 |
265 |
266 | /**
267 | * 打印到控制台,并带上换行符。 可以传入多个参数,第一个参数作为主要信息,其他参数作为类似于 printf(3) 中的代替值(参数都会传给 util.format())。
268 | */
269 | function log(data: string, ...args: any[]): void;
270 |
271 | /**
272 | * 相当于log(text)。
273 | */
274 | function print(message: string | Object): void;
275 |
276 |
277 | /* 基于坐标的触摸模拟 */
278 |
279 | /**
280 | * 设置脚本坐标点击所适合的屏幕宽高。如果脚本运行时,屏幕宽度不一致会自动放缩坐标。
281 | */
282 | function setScreenMetrics(width: number, height: number): void;
283 |
284 | /* 安卓7.0以上的触摸和手势模拟 */
285 |
286 | /**
287 | * Android7.0以上
288 | *
289 | * 模拟点击坐标(x, y)大约150毫秒,并返回是否点击成功。只有在点击执行完成后脚本才继续执行。
290 | */
291 | function click(x: number, y: number): void;
292 |
293 | /**
294 | * Android7.0以上
295 | *
296 | * 模拟长按坐标(x, y), 并返回是否成功。只有在长按执行完成(大约600毫秒)时脚本才会继续执行。
297 | */
298 | function longClick(x: number, y: number): void;
299 |
300 | /**
301 | * Android7.0以上
302 | *
303 | * 模拟按住坐标(x, y), 并返回是否成功。只有按住操作执行完成时脚本才会继续执行。
304 | *
305 | * 如果按住时间过短,那么会被系统认为是点击;如果时长超过500毫秒,则认为是长按。
306 | */
307 | function press(x: number, y: number, duration: number): void;
308 |
309 | /**
310 | * 模拟从坐标(x1, y1)滑动到坐标(x2, y2),并返回是否成功。只有滑动操作执行完成时脚本才会继续执行。
311 | */
312 | function swipe(x1: number, y1: number, x2: number, y2: number, duration: number): boolean;
313 |
314 | type GesturePoint = [number, number];
315 | /**
316 | * 模拟手势操作。例如gesture(1000, [0, 0], [500, 500], [500, 1000])为模拟一个从(0, 0)到(500, 500)到(500, 100)的手势操作,时长为2秒。
317 | */
318 | function gesture(duration: number, point1: GesturePoint, point2: GesturePoint, ...points: GesturePoint[]): void;
319 |
320 | type Gesture = [number, number, GesturePoint, GesturePoint] | [number, GesturePoint, GesturePoint];
321 | /**
322 | * 同时模拟多个手势。每个手势的参数为[delay, duration, 坐标], delay为延迟多久(毫秒)才执行该手势;duration为手势执行时长;坐标为手势经过的点的坐标。其中delay参数可以省略,默认为0。
323 | */
324 | function gestures(gesture: Gesture, ...gestures: Gesture[]): void;
325 |
326 | /**
327 | * RootAutomator是一个使用root权限来模拟触摸的对象,用它可以完成触摸与多点触摸,并且这些动作的执行没有延迟。
328 | *
329 | * 一个脚本中最好只存在一个RootAutomator,并且保证脚本结束退出他。
330 | */
331 | class RootAutomator {
332 | /**
333 | * 点击位置(x, y)。其中id是一个整数值,用于区分多点触摸,不同的id表示不同的"手指"。
334 | */
335 | tap(x: number, y: number, id?: number): void;
336 |
337 | /**
338 | * 模拟一次从(x1, y1)到(x2, y2)的时间为duration毫秒的滑动。
339 | */
340 | swipe(x1: number, x2: number, y1: number, y2: number, duration?: number): void;
341 |
342 | /**
343 | * 模拟按下位置(x, y),时长为duration毫秒。
344 | */
345 | press(x: number, y: number, duration: number, id?: number): void;
346 |
347 | /**
348 | * 模拟长按位置(x, y)。
349 | */
350 | longPress(x: number, y: number, duration?: number, id?: number): void;
351 |
352 | /**
353 | * 模拟手指按下位置(x, y)。
354 | */
355 | touchDown(x: number, y: number, id?: number): void;
356 |
357 | /**
358 | * 模拟移动手指到位置(x, y)。
359 | */
360 | touchMove(x: number, y: number, id?: number): void;
361 |
362 | /**
363 | * 模拟手指弹起。
364 | */
365 | touchUp(id?: number): void;
366 |
367 | }
368 |
369 | /**
370 | * 需要Root权限
371 | *
372 | * 实验API,请勿过度依赖
373 | *
374 | * 点击位置(x, y), 您可以通过"开发者选项"开启指针位置来确定点击坐标。
375 | */
376 | function Tap(x: number, y: number): void;
377 |
378 | /**
379 | * 需要Root权限
380 | *
381 | * 实验API,请勿过度依赖
382 | *
383 | * 滑动。从(x1, y1)位置滑动到(x2, y2)位置。
384 | */
385 | function Swipe(x1: number, x2: number, y1: number, y2: number, duration?: number): void;
386 |
387 | /**
388 | * device模块提供了与设备有关的信息与操作,例如获取设备宽高,内存使用率,IMEI,调整设备亮度、音量等。
389 | *
390 | * 此模块的部分函数,例如调整音量,需要"修改系统设置"的权限。如果没有该权限,会抛出SecurityException并跳转到权限设置界面。
391 | */
392 | namespace device {
393 |
394 | /**
395 | * 设备屏幕分辨率宽度。例如1080。
396 | */
397 | var width: number;
398 |
399 | /**
400 | * 设备屏幕分辨率高度。例如1920。
401 | */
402 | var height: number;
403 |
404 | /**
405 | * 修订版本号,或者诸如"M4-rc20"的标识。
406 | */
407 | var buildId: string;
408 |
409 | /**
410 | * 设备的主板(?)名称。
411 | */
412 | var broad: string;
413 |
414 | /**
415 | * 与产品或硬件相关的厂商品牌,如"Xiaomi", "Huawei"等。
416 | */
417 | var brand: string;
418 |
419 | /**
420 | * 设备在工业设计中的名称(代号)。
421 | */
422 | var device: string;
423 |
424 | /**
425 | * 设备型号。
426 | */
427 | var model: string;
428 |
429 | /**
430 | * 整个产品的名称。
431 | */
432 | var product: string;
433 |
434 | /**
435 | * 设备Bootloader的版本。
436 | */
437 | var bootloader: string;
438 |
439 | /**
440 | * 设备的硬件名称(来自内核命令行或者/proc)。
441 | */
442 | var hardware: string;
443 |
444 | /**
445 | * 构建(build)的唯一标识码。
446 | */
447 | var fingerprint: string;
448 |
449 | /**
450 | * 硬件序列号。
451 | */
452 | var serial: string;
453 |
454 | /**
455 | * 安卓系统API版本。例如安卓4.4的sdkInt为19。
456 | */
457 | var sdkInt: number;
458 |
459 | /**
460 | * 设备固件版本号。
461 | */
462 | var incremental: string;
463 |
464 | /**
465 | * Android系统版本号。例如"5.0", "7.1.1"。
466 | */
467 | var release: string;
468 |
469 | /**
470 | * 基础操作系统。
471 | */
472 | var baseOS: string;
473 |
474 | /**
475 | * 安全补丁程序级别。
476 | */
477 | var securityPatch: string;
478 |
479 | /**
480 | * 开发代号,例如发行版是"REL"。
481 | */
482 | var codename: string;
483 |
484 | /**
485 | * 返回设备的IMEI。
486 | */
487 | function getIMEI(): string;
488 |
489 | /**
490 | * 返回设备的Android ID。
491 | *
492 | * Android ID为一个用16进制字符串表示的64位整数,在设备第一次使用时随机生成,之后不会更改,除非恢复出厂设置。
493 | */
494 | function getAndroidId(): string;
495 |
496 | /**
497 | * 返回设备的Mac地址。该函数需要在有WLAN连接的情况下才能获取,否则会返回null。
498 | *
499 | * 可能的后续修改:未来可能增加有root权限的情况下通过root权限获取,从而在没有WLAN连接的情况下也能返回正确的Mac地址,因此请勿使用此函数判断WLAN连接。
500 | */
501 | function getMacAddress(): string;
502 |
503 | /**
504 | * 返回当前的(手动)亮度。范围为0~255。
505 | */
506 | function getBrightness(): number;
507 |
508 | /**
509 | * 返回当前亮度模式,0为手动亮度,1为自动亮度。
510 | */
511 | function getBrightnessMode(): number;
512 |
513 | /**
514 | * 设置当前手动亮度。如果当前是自动亮度模式,该函数不会影响屏幕的亮度。
515 | *
516 | * 此函数需要"修改系统设置"的权限。如果没有该权限,会抛出SecurityException并跳转到权限设置界面。
517 | */
518 | function setBrightness(b: number): void;
519 |
520 | /**
521 | * 设置当前亮度模式。
522 | *
523 | * 此函数需要"修改系统设置"的权限。如果没有该权限,会抛出SecurityException并跳转到权限设置界面。
524 | */
525 | function setBrightnessMode(mode: 0 | 1): void;
526 |
527 | /**
528 | * 返回当前媒体音量。
529 | */
530 | function getMusicVolume(): number;
531 |
532 | /**
533 | * 返回当前通知音量。
534 | */
535 | function getNotificationVolume(): number;
536 |
537 | /**
538 | * 返回当前闹钟音量。
539 | */
540 | function getAlarmVolume(): number;
541 |
542 | /**
543 | * 返回媒体音量的最大值。
544 | */
545 | function getMusicMaxVolume(): number;
546 |
547 | /**
548 | * 返回通知音量的最大值。
549 | */
550 | function getNotificationMaxVolume(): number;
551 |
552 | /**
553 | * 返回闹钟音量的最大值。
554 | */
555 | function getAlarmMaxVolume(): number;
556 |
557 | /**
558 | * 设置当前媒体音量。
559 | *
560 | * 此函数需要"修改系统设置"的权限。如果没有该权限,会抛出SecurityException并跳转到权限设置界面。
561 | */
562 | function setMusicVolume(volume: number): void;
563 |
564 | /**
565 | * 设置当前通知音量。
566 | *
567 | * 此函数需要"修改系统设置"的权限。如果没有该权限,会抛出SecurityException并跳转到权限设置界面。
568 | */
569 | function setNotificationVolume(volume: number): void;
570 |
571 | /**
572 | * 设置当前闹钟音量。
573 | *
574 | * 此函数需要"修改系统设置"的权限。如果没有该权限,会抛出SecurityException并跳转到权限设置界面。
575 | */
576 | function setAlarmVolume(volume: number): void;
577 |
578 | /**
579 | * 返回当前电量百分比。
580 | */
581 | function getBattery(): number;
582 |
583 | /**
584 | * 返回设备是否正在充电。
585 | */
586 | function isCharging(): boolean;
587 |
588 | /**
589 | * 返回设备内存总量,单位字节(B)。1MB = 1024 * 1024B。
590 | */
591 | function getTotalMem(): number;
592 |
593 | /**
594 | * 返回设备当前可用的内存,单位字节(B)。
595 | */
596 | function getAvailMem(): number;
597 |
598 | /**
599 | * 返回设备屏幕是否是亮着的。如果屏幕亮着,返回true; 否则返回false。
600 | *
601 | * 需要注意的是,类似于vivo xplay系列的息屏时钟不属于"屏幕亮着"的情况,虽然屏幕确实亮着但只能显示时钟而且不可交互,此时isScreenOn()也会返回false。
602 | */
603 | function isScreenOn(): boolean;
604 |
605 | /**
606 | * 唤醒设备。包括唤醒设备CPU、屏幕等。可以用来点亮屏幕。
607 | */
608 | function wakeUp(): void;
609 |
610 | /**
611 | * 如果屏幕没有点亮,则唤醒设备。
612 | */
613 | function wakeUpIfNeeded(): void;
614 |
615 | /**
616 | * 保持屏幕常亮。
617 | *
618 | * 此函数无法阻止用户使用锁屏键等正常关闭屏幕,只能使得设备在无人操作的情况下保持屏幕常亮;同时,如果此函数调用时屏幕没有点亮,则会唤醒屏幕。
619 | *
620 | * 在某些设备上,如果不加参数timeout,只能在Auto.js的界面保持屏幕常亮,在其他界面会自动失效,这是因为设备的省电策略造成的。因此,建议使用比较长的时长来代替"一直保持屏幕常亮"的功能,例如device.keepScreenOn(3600 * 1000)。
621 | *
622 | * 可以使用device.cancelKeepingAwake()来取消屏幕常亮。
623 | */
624 | function keepScreenOn(timeout: number): void;
625 |
626 | /**
627 | * 保持屏幕常亮,但允许屏幕变暗来节省电量。此函数可以用于定时脚本唤醒屏幕操作,不需要用户观看屏幕,可以让屏幕变暗来节省电量。
628 | *
629 | * 此函数无法阻止用户使用锁屏键等正常关闭屏幕,只能使得设备在无人操作的情况下保持屏幕常亮;同时,如果此函数调用时屏幕没有点亮,则会唤醒屏幕。
630 | *
631 | * 可以使用device.cancelKeepingAwake()来取消屏幕常亮。
632 | */
633 | function keepScreenDim(timeout: number): void;
634 |
635 | /**
636 | * 取消设备保持唤醒状态。用于取消device.keepScreenOn(), device.keepScreenDim()等函数设置的屏幕常亮。
637 | */
638 | function cancelKeepingAwake(): void;
639 |
640 | /**
641 | * 使设备震动一段时间。
642 | */
643 | function vibrate(millis: number): void;
644 |
645 | /**
646 | * 如果设备处于震动状态,则取消震动。
647 | */
648 | function cancelVibration(): void;
649 |
650 | }
651 |
652 | /**
653 | * dialogs 模块提供了简单的对话框支持,可以通过对话框和用户进行交互。
654 | */
655 | namespace dialogs {
656 |
657 | /**
658 | * 显示一个只包含“确定”按钮的提示对话框。直至用户点击确定脚本才继续运行。
659 | */
660 | function alert(title: string, content?: string): void;
661 |
662 | /**
663 | * UI模式
664 | *
665 | * 显示一个只包含“确定”按钮的提示对话框。直至用户点击确定脚本才继续运行。
666 | */
667 | function alert(title: string, content?: string, callback?: () => void): Promise;
668 |
669 | /**
670 | * 显示一个包含“确定”和“取消”按钮的提示对话框。如果用户点击“确定”则返回 true ,否则返回 false 。
671 | */
672 | function confirm(title: string, content?: string): boolean;
673 |
674 | /**
675 | * UI模式
676 | *
677 | * 显示一个包含“确定”和“取消”按钮的提示对话框。如果用户点击“确定”则返回 true ,否则返回 false 。
678 | */
679 | function confirm(title: string, content?: string, callback?: (value: boolean) => void): Promise;
680 |
681 | /**
682 | * 显示一个包含输入框的对话框,等待用户输入内容,并在用户点击确定时将输入的字符串返回。如果用户取消了输入,返回null。
683 | */
684 | function rawInput(title: string, prefill?: string): string;
685 |
686 | /**
687 | * UI模式
688 | *
689 | * 显示一个包含输入框的对话框,等待用户输入内容,并在用户点击确定时将输入的字符串返回。如果用户取消了输入,返回null。
690 | */
691 | function rawInput(title: string, prefill?: string, callback?: (value: string) => void): Promise;
692 |
693 | /**
694 | * 等效于 eval(dialogs.rawInput(title, prefill, callback)), 该函数和rawInput的区别在于,会把输入的字符串用eval计算一遍再返回,返回的可能不是字符串。
695 | */
696 | function input(title: string, prefill?: string): any;
697 |
698 | /**
699 | * UI模式
700 | *
701 | * 等效于 eval(dialogs.rawInput(title, prefill, callback)), 该函数和rawInput的区别在于,会把输入的字符串用eval计算一遍再返回,返回的可能不是字符串。
702 | */
703 | function input(title: string, prefill?: string, callback?: (value: any) => void): Promise;
704 |
705 | /**
706 | * 显示一个包含输入框的对话框,等待用户输入内容,并在用户点击确定时将输入的字符串返回。如果用户取消了输入,返回null。
707 | */
708 | function prompt(title: string, prefill?: string): string;
709 |
710 | /**
711 | * UI模式
712 | *
713 | * 显示一个包含输入框的对话框,等待用户输入内容,并在用户点击确定时将输入的字符串返回。如果用户取消了输入,返回null。
714 | */
715 | function prompt(title: string, prefill?: string, callback?: (value: string) => void): Promise;
716 |
717 | /**
718 | * 显示一个带有选项列表的对话框,等待用户选择,返回用户选择的选项索引(0 ~ item.length - 1)。如果用户取消了选择,返回-1。
719 | */
720 | function select(title: string, items: string[]): number;
721 |
722 | /**
723 | * UI模式
724 | *
725 | * 显示一个带有选项列表的对话框,等待用户选择,返回用户选择的选项索引(0 ~ item.length - 1)。如果用户取消了选择,返回-1。
726 | */
727 | function select(title: string, items: string[], callback?: (value: number) => void): Promise;
728 |
729 | /**
730 | * 显示一个单选列表对话框,等待用户选择,返回用户选择的选项索引(0 ~ item.length - 1)。如果用户取消了选择,返回-1。
731 | */
732 | function singleChoice(title: string, items: string[], index?: number): number;
733 |
734 | /**
735 | * UI模式
736 | *
737 | * 显示一个单选列表对话框,等待用户选择,返回用户选择的选项索引(0 ~ item.length - 1)。如果用户取消了选择,返回-1。
738 | */
739 | function singleChoice(title: string, items: string[], index?: number, callback?: (choice: number) => void): Promise;
740 |
741 | /**
742 | * 显示一个多选列表对话框,等待用户选择,返回用户选择的选项索引的数组。如果用户取消了选择,返回[]。
743 | */
744 | function multiChoice(title: string, items: string[], indices?: number[]): number[];
745 |
746 | /**
747 | * UI模式
748 | *
749 | * 显示一个多选列表对话框,等待用户选择,返回用户选择的选项索引的数组。如果用户取消了选择,返回[]。
750 | */
751 | function multiChoice(title: string, items: string[], indices?: number[], callback?: (choices: number[]) => void): Promise;
752 |
753 |
754 | }
755 |
756 | /**
757 | * 显示一个只包含“确定”按钮的提示对话框。直至用户点击确定脚本才继续运行。
758 | */
759 | function alert(title: string, content?: string): void;
760 |
761 | /**
762 | * UI模式
763 | *
764 | * 显示一个只包含“确定”按钮的提示对话框。直至用户点击确定脚本才继续运行。
765 | *
766 | * 在ui模式下该函数返回一个Promise。
767 | */
768 | function alert(title: string, content?: string, callback?: () => void): Promise;
769 |
770 | /**
771 | * 显示一个包含“确定”和“取消”按钮的提示对话框。如果用户点击“确定”则返回 true ,否则返回 false 。
772 | */
773 | function confirm(title: string, content?: string): boolean;
774 |
775 | /**
776 | * UI模式
777 | *
778 | * 显示一个包含“确定”和“取消”按钮的提示对话框。如果用户点击“确定”则返回 true ,否则返回 false 。
779 | *
780 | * 在ui模式下该函数返回一个Promise。
781 | */
782 | function confirm(title: string, content?: string, callback?: (value: boolean) => void): Promise;
783 |
784 | /**
785 | * 显示一个包含输入框的对话框,等待用户输入内容,并在用户点击确定时将输入的字符串返回。如果用户取消了输入,返回null。
786 | */
787 | function rawInput(title: string, prefill?: string): string;
788 |
789 | /**
790 | * UI模式
791 | *
792 | * 显示一个包含输入框的对话框,等待用户输入内容,并在用户点击确定时将输入的字符串返回。如果用户取消了输入,返回null。
793 | */
794 | function rawInput(title: string, prefill?: string, callback?: (value: string) => void): Promise;
795 |
796 | /**
797 | * engines模块包含了一些与脚本环境、脚本运行、脚本引擎有关的函数,包括运行其他脚本,关闭脚本等。
798 | */
799 | namespace engines {
800 |
801 | /**
802 | * 脚本引擎对象。
803 | */
804 | interface ScriptEngine {
805 |
806 | /**
807 | * 停止脚本引擎的执行。
808 | */
809 | forceStop(): void;
810 |
811 | /**
812 | * 返回脚本执行的路径。对于一个脚本文件而言为这个脚本所在的文件夹;对于其他脚本,例如字符串脚本,则为null或者执行时的设置值。
813 | */
814 | cwd(): string;
815 | }
816 |
817 | /**
818 | * 执行脚本时返回的对象,可以通过他获取执行的引擎、配置等,也可以停止这个执行。
819 | *
820 | * 要停止这个脚本的执行,使用exectuion.getEngine().forceStop().
821 | */
822 | interface ScriptExecution {
823 |
824 | /**
825 | * 返回执行该脚本的脚本引擎对象(ScriptEngine)
826 | */
827 | getEngine(): ScriptEngine;
828 |
829 | /**
830 | * 返回该脚本的运行配置(ScriptConfig)
831 | */
832 | getConfig(): ScriptConfig;
833 | }
834 |
835 | /**
836 | * 运行配置项。
837 | */
838 | interface ScriptConfig {
839 |
840 | /**
841 | * 延迟执行的毫秒数,默认为0。
842 | */
843 | delay?: number;
844 |
845 | /**
846 | * 循环运行次数,默认为1。0为无限循环。
847 | */
848 | loopTimes?: number;
849 |
850 | /**
851 | * 循环运行时两次运行之间的时间间隔,默认为0。
852 | */
853 | interval?: number;
854 |
855 | /**
856 | * 指定脚本运行的目录。这些路径会用于require时寻找模块文件。
857 | */
858 | path?: string | string[];
859 |
860 | /**
861 | * 返回一个字符串数组表示脚本运行时模块寻找的路径。
862 | */
863 | getpath?: string[];
864 | }
865 |
866 | /**
867 | * 在新的脚本环境中运行脚本script。返回一个ScriptExectuion对象。
868 | *
869 | * 所谓新的脚本环境,指定是,脚本中的变量和原脚本的变量是不共享的,并且,脚本会在新的线程中运行。
870 | */
871 | function execScript(name: string, script: string, config?: ScriptConfig): ScriptExecution;
872 |
873 | /**
874 | * 在新的脚本环境中运行脚本文件path:string。返回一个ScriptExecution对象。
875 | */
876 | function execScriptFile(path: string, config?: ScriptConfig): ScriptExecution;
877 |
878 | /**
879 | * 在新的脚本环境中运行录制文件path:string。返回一个ScriptExecution对象。
880 | */
881 | function execAutoFile(path: string, config?: ScriptConfig): ScriptExecution;
882 |
883 | /**
884 | * 停止所有正在运行的脚本。包括当前脚本自身。
885 | */
886 | function stopAll(): void;
887 |
888 | /**
889 | * 停止所有正在运行的脚本并显示停止的脚本数量。包括当前脚本自身。
890 | */
891 | function stopAllAndToast(): void;
892 |
893 | /**
894 | * 返回当前脚本的脚本引擎对象(ScriptEngine)
895 | */
896 | function myEngine(): void;
897 | }
898 |
899 |
900 | namespace events {
901 |
902 | interface KeyEvent {
903 | getAction();
904 | getKeyCode(): number;
905 | getEventTime(): number;
906 | getDownTime(): number;
907 | keyCodeToString(keyCode: number): string;
908 | }
909 |
910 | function emitter(): EventEmitter;
911 |
912 | function observeKey(): void;
913 |
914 | type Keys = 'volume_up' | 'volume_down' | 'home' | 'back' | 'menu';
915 |
916 | function setKeyInterceptionEnabled(key: Keys, enabled: boolean);
917 |
918 | function setKeyInterceptionEnabled(enabled: boolean);
919 |
920 | function onKeyDown(keyName: Keys, listener: (e: KeyEvent) => void): void;
921 |
922 | function onceKeyUp(keyName: Keys, listener: (e: KeyEvent) => void): void;
923 |
924 | function removeAllKeyDownListeners(keyName: Keys): void;
925 |
926 | function removeAllKeyUpListeners(keyName: Keys): void;
927 |
928 | function observeTouch(): void;
929 |
930 | function setTouchEventTimeout(timeout: number): void;
931 |
932 | function getTouchEventTimeout(): number;
933 |
934 | function onTouch(listener: (point: Point) => void): void;
935 |
936 | function removeAllTouchListeners(): void;
937 |
938 | function on(event: 'key' | 'key_down' | 'key_up', listener: (keyCode: number, e: KeyEvent) => void): void;
939 |
940 | function on(event: 'exit', listener: () => void): void;
941 |
942 | function observeNotification(): void;
943 |
944 | function observeToast(): void;
945 |
946 | /**
947 | * 系统Toast对象
948 | */
949 | interface Toast {
950 |
951 | /**
952 | * 获取Toast的文本内容
953 | */
954 | getText(): string;
955 |
956 | /**
957 | * 获取发出Toast的应用包名
958 | */
959 | getPackageName(): void;
960 |
961 | }
962 |
963 | function onToast(listener: (toast: Toast) => void): void;
964 |
965 | /**
966 | * 通知对象,可以获取通知详情,包括通知标题、内容、发出通知的包名、时间等,也可以对通知进行操作,比如点击、删除。
967 | */
968 | interface Notification {
969 | number: number;
970 | when: number;
971 | getPackageName(): string;
972 | getTitle(): string;
973 | getText(): string;
974 | click(): void;
975 | delete(): void;
976 | }
977 |
978 | function on(event: 'notification', listener: (notification: Notification) => void): void;
979 |
980 | }
981 |
982 | /**
983 | * 按键事件中所有可用的按键名称
984 | */
985 | enum keys {
986 | home,
987 | back,
988 | menu,
989 | volume_up,
990 | volume_down
991 | }
992 |
993 | interface EventEmitter {
994 | defaultMaxListeners: number;
995 | addListener(eventName: string, listener: (...args: any[]) => void): EventEmitter;
996 | emit(eventName: string, ...args: any[]): boolean;
997 | eventNames(): string[];
998 | getMaxListeners(): number;
999 | listenerCount(eventName: string): number;
1000 | on(eventName: string, listener: (...args: any[]) => void): EventEmitter;
1001 | once(eventName: string, listener: (...args: any[]) => void): EventEmitter;
1002 | prependListener(eventName: string, listener: (...args: any[]) => void): EventEmitter;
1003 | prependOnceListener(eventName: string, listener: (...args: any[]) => void): EventEmitter;
1004 | removeAllListeners(eventName?: string): EventEmitter;
1005 | removeListener(eventName: string, listener: (...args: any[]) => void): EventEmitter;
1006 | setMaxListeners(n: number): EventEmitter;
1007 | }
1008 |
1009 |
1010 | namespace floaty {
1011 | function window(layout: any): FloatyWindow;
1012 | function closeAll(): void;
1013 | interface FloatyWindow {
1014 | setAdjustEnabled(enabled: boolean): void;
1015 | setPosition(x: number, y: number): void;
1016 | getX(): number;
1017 | getY(): number;
1018 | setSize(width: number, height: number): void;
1019 | getWidht(): number;
1020 | getHeight(): number;
1021 | close(): void;
1022 | exitOnClose(): void;
1023 | }
1024 | }
1025 |
1026 |
1027 | namespace files {
1028 | type byte = number;
1029 | function isFile(path: string): boolean;
1030 | function isDir(path: string): boolean;
1031 | function isEmptyDir(path: string): boolean;
1032 | function join(parent: string, ...child: string[]): string;
1033 | function create(path: string): boolean;
1034 | function createWithDirs(path: string): boolean;
1035 | function exists(path: string): boolean;
1036 | function ensureDir(path: string): void;
1037 | function read(path: string, encoding?: string): string;
1038 | function readBytes(path: string): byte[];
1039 | function write(path: string, text, encoding?: string): void;
1040 | function writeBytes(path: string, bytes: byte[]): void;
1041 | function append(path: string, text: string, encoding?: string): void;
1042 | function appendBytes(path: string, text: byte[], encoding?: string): void;
1043 | function copy(frompath: string, topath: string): boolean;
1044 | function move(frompath: string, topath: string): boolean;
1045 | function rename(path: string, newName): boolean;
1046 | function renameWithoutExtension(path: string, newName: string): boolean;
1047 | function getName(path: string): string;
1048 | function getNameWithoutExtension(path: string): string;
1049 | function getExtension(path: string): string;
1050 | function remove(path: string): boolean;
1051 | function removeDir(path: string): boolean;
1052 | function getSdcardPath(): string;
1053 | function cwd(): string;
1054 | function path(relativePath: string): string;
1055 | function listDir(path: string, filter: (filename: string) => boolean): string[];
1056 | }
1057 |
1058 | interface ReadableTextFile {
1059 | read(): string;
1060 | read(maxCount: number): string;
1061 | readline(): string;
1062 | readlines(): string[];
1063 | close(): void;
1064 | }
1065 |
1066 | interface WritableTextFile {
1067 | write(text: string): void;
1068 | writeline(line: string): void;
1069 | writelines(lines: string[]): void;
1070 | flush(): void;
1071 | close(): void;
1072 | }
1073 |
1074 | function open(path: string, mode?: 'r', encoding?: string, bufferSize?: number): ReadableTextFile;
1075 | function open(path: string, mode?: 'w' | 'a', encoding?: string, bufferSize?: number): WritableTextFile;
1076 |
1077 | namespace media {
1078 | function scanFile(path: string): void;
1079 | function playMusic(path: string, volume?: number, looping?: boolean);
1080 | function musicSeekTo(msec: number): void;
1081 | function pauseMusic(): void;
1082 | function resumeMusic(): void;
1083 | function stopMusic(): void;
1084 | function isMusicPlaying(): boolean;
1085 | function getMusicDuration(): number;
1086 | function getMusicCurrentPosition(): number;
1087 | }
1088 |
1089 | namespace sensors {
1090 | interface SensorEventEmitter {
1091 | on(eventName: 'change', callback: (...args: number[]) => void): void;
1092 | on(eventName: 'accuracy_change', callback: (accuracy: number) => void): void;
1093 | }
1094 | function on(eventName: 'unsupported_sensor', callback: (sensorName: string) => void): void;
1095 | function register(sensorName: string, delay?: delay): SensorEventEmitter;
1096 | function unregister(emitter: SensorEventEmitter);
1097 | function unregisterAll(): void;
1098 | var ignoresUnsupportedSensor: boolean;
1099 | enum delay {
1100 | normal,
1101 | ui,
1102 | game,
1103 | fastest
1104 | }
1105 | }
1106 |
1107 | function sleep(n: number): void;
1108 |
1109 | function currentPackage(): string;
1110 |
1111 | function currentActivity(): string;
1112 |
1113 | function setClip(test: string): void;
1114 |
1115 | function getClip(): string;
1116 |
1117 | function toast(message: string): void;
1118 |
1119 | function toastLog(message: string): void;
1120 |
1121 | function waitForActivity(activity: string, period?: number): void;
1122 |
1123 | function waitForPackage(packageName: string, period?: number): void;
1124 |
1125 | function exit(): void;
1126 |
1127 | function random(): number;
1128 | function random(min: number, max: number): number;
1129 |
1130 |
1131 | namespace http {
1132 | interface HttpRequestOptions {
1133 | header: { [key: string]: string },
1134 | method: 'GET' | 'POST' | 'PUT' | 'DELET' | 'PATCH';
1135 | contentType: string;
1136 | body: string | string[] | files.byte[]
1137 | }
1138 | interface Request {
1139 |
1140 | }
1141 | interface Response {
1142 | statusCode: number;
1143 | statusMessage: string;
1144 | headers: { [key: string]: string };
1145 | body: ResponseBody;
1146 | request: Request;
1147 | url: string;
1148 | method: 'GET' | 'POST' | 'PUT' | 'DELET' | 'PATCH';
1149 | }
1150 | interface ResponseBody {
1151 | bytes(): files.byte[];
1152 | string(): string;
1153 | json(): object;
1154 | contentType: string;
1155 | }
1156 | function get(url: string, options?: HttpRequestOptions, callback?: (resp: Response) => void): Response;
1157 | function post(url: string, data: object, options?: HttpRequestOptions, callback?: (resp: Response) => void): Response;
1158 | function postJson(url: string, data?: object, options?: HttpRequestOptions, callback?: (resp: Response) => void): Response;
1159 |
1160 | interface RequestMultipartBody {
1161 | file: ReadableTextFile | [string, string] | [string, string, string];
1162 | }
1163 | function postMultipart(url: string, files: RequestMultipartBody, options?: HttpRequestOptions, callback?: (resp: Response) => void): void;
1164 | function postMultipart(url: string, files: { [key: string]: string } & RequestMultipartBody, options?: HttpRequestOptions, callback?: (resp: Response) => void): void;
1165 |
1166 | function request(url: string, options?: HttpRequestOptions, callback?: (resp: Response) => void): void;
1167 |
1168 | }
1169 |
1170 |
1171 | interface Image {
1172 | getWidth(): number;
1173 | getHeight(): number;
1174 | saveTo(path: string): void;
1175 | pixel(x: number, y: number): number;
1176 | }
1177 |
1178 |
1179 | namespace images {
1180 | function requestScreenCapture(landscape?: boolean): boolean;
1181 | function captureScreen(): Image;
1182 | function captureScreen(path: string): void;
1183 | function pixel(image: Image, x: number, y: number): number;
1184 | function save(image: Image, path: string): void;
1185 | function read(path: string): Image;
1186 | function load(url: string): Image;
1187 | interface FindColorOptions {
1188 | region?: [number, number] | [number, number, number, number];
1189 | threshold?: number;
1190 | }
1191 | function clip(image: Image, x: number, y: number, w: number, h: number): Image;
1192 | function findColor(image: Image, color: number | string, options: FindColorOptions): Point;
1193 | function findColorInRegion(image: Image, color: number | string, x: number, y: number, width?: number, height?: number, threshold?: number): Point;
1194 | function findColorEquals(image: Image, color: number | string, x?: number, y?: number, width?: number, height?: number): Point;
1195 | function detectsColor(image: Image, color: number | string, x: number, y: number, threshold?: number, algorithm?: 'diff'): Point;
1196 | interface FindImageOptions {
1197 | region?: [number, number] | [number, number, number, number];
1198 | threshold?: number;
1199 | level?: number;
1200 | }
1201 | function findImage(image: Image, template: Image, options?: FindImageOptions): Point;
1202 | function findImageInRegion(image: Image, template: Image, x: number, y: number, width?: number, height?: number, threshold?: number): Point;
1203 | function findMultiColors(image: Image, firstColor: number | string, colors: [number, number, number | string][], options?: FindColorOptions): Point;
1204 | }
1205 |
1206 |
1207 | namespace colors {
1208 | function toString(color: number): string;
1209 | function red(color: number | string): number;
1210 | function green(color: number | string): number;
1211 | function blue(color: number | string): number;
1212 | function alpha(color: number | string): number;
1213 | function rgb(red: number, green: number, blue: number): number;
1214 | function argb(alpha: number, red: number, green: number, blue: number): number;
1215 | function parseColor(colorStr: string): number;
1216 | function isSimilar(color1: number | string, color2: number | string, threshold: number, algorithm: 'diff' | 'rgb' | 'rgb+' | 'hs'): boolean;
1217 | function equals(color1: number | string, color2: number | string): boolean;
1218 | }
1219 |
1220 |
1221 | /* 全局按键 */
1222 | function back(): boolean;
1223 | function home(): boolean;
1224 | function powerDialog(): boolean;
1225 | function notifications(): boolean;
1226 | function quickSettings(): boolean;
1227 | function recents(): boolean;
1228 | function splitScreen(): boolean;
1229 | function Home(): void;
1230 | function Back(): void;
1231 | function Power(): void;
1232 | function Menu(): void;
1233 | function VolumeUp(): void;
1234 | function VolumeDown(): void;
1235 | function Camera(): void;
1236 | function Up(): void;
1237 | function Down(): void;
1238 | function Left(): void;
1239 | function Right(): void;
1240 | function OK(): void;
1241 | function Text(text: string): void;
1242 | function KeyCode(code: number | string): void;
1243 |
1244 |
1245 | // var module: { exports: any };
1246 |
1247 |
1248 | interface Storage {
1249 | get(key: string, defaultValue?: T): T;
1250 | put(key: string, value: T): void;
1251 | remove(key: string): void;
1252 | contains(key: string): boolean;
1253 | clear(): void;
1254 | }
1255 |
1256 | namespace storages {
1257 | function create(name: string): Storage;
1258 | function remove(name: string): boolean;
1259 | }
1260 |
1261 | function auto(mode?: 'fast' | 'normal'): void;
1262 | namespace auto {
1263 | function waitFor(): void;
1264 | function setMode(mode: 'fast' | 'normal'): void;
1265 | }
1266 | function selector(): UiSelector;
1267 | function click(text: string, index?: number): boolean;
1268 | function click(left: number, top: number, bottom: number, right: number): boolean;
1269 | function longClick(text: string, index?: number): boolean;
1270 | function scrollUp(index?: number): boolean;
1271 | function scrollDown(index?: number): boolean;
1272 | function setText(text: string): boolean;
1273 | function setText(index: number, text: string): boolean;
1274 | function input(text: string): boolean;
1275 | function input(index: number, text: string): boolean;
1276 |
1277 | interface UiSelector {
1278 | text(str: string): UiSelector;
1279 | textContains(str: string): UiSelector;
1280 | textStartsWith(prefix: string): UiSelector;
1281 | textEndsWith(suffix: string): UiSelector;
1282 | textMatches(reg: string | RegExp): UiSelector;
1283 | desc(str: string): UiSelector;
1284 | descContains(str: string): UiSelector;
1285 | descStartsWith(prefix: string): UiSelector;
1286 | descEndsWith(suffix: string): UiSelector;
1287 | descMatches(reg: string | RegExp): UiSelector;
1288 | id(resId: string): UiSelector;
1289 | idContains(str: string): UiSelector;
1290 | idStartsWith(prefix: string): UiSelector;
1291 | idEndsWith(suffix: string): UiSelector;
1292 | idMatches(reg: string | RegExp): UiSelector;
1293 | className(str: string): UiSelector;
1294 | classNameContains(str: string): UiSelector;
1295 | classNameStartsWith(prefix: string): UiSelector;
1296 | classNameEndsWith(suffix: string): UiSelector;
1297 | classNameMatches(reg: string | RegExp): UiSelector;
1298 | packageName(str: string): UiSelector;
1299 | packageNameContains(str: string): UiSelector;
1300 | packageNameStartsWith(prefix: string): UiSelector;
1301 | packageNameEndsWith(suffix: string): UiSelector;
1302 | packageNameMatches(reg: string | RegExp): UiSelector;
1303 | bounds(left: number, top: number, right: number, buttom: number): UiSelector;
1304 | boundsInside(left: number, top: number, right: number, buttom: number): UiSelector;
1305 | boundsContains(left: number, top: number, right: number, buttom: number): UiSelector;
1306 | drawingOrder(order): UiSelector;
1307 | clickable(b: boolean): UiSelector;
1308 | longClickable(b: boolean): UiSelector;
1309 | checkable(b: boolean): UiSelector;
1310 | selected(b: boolean): UiSelector;
1311 | enabled(b: boolean): UiSelector;
1312 | scrollable(b: boolean): UiSelector;
1313 | editable(b: boolean): UiSelector;
1314 | multiLine(b: boolean): UiSelector;
1315 | findOne(): UiObject;
1316 | findOne(timeout: number): UiObject;
1317 | findOnce(): UiObject;
1318 | findOnce(i: number): UiObject;
1319 | find(): UiCollection;
1320 | untilFind(): UiCollection;
1321 | exists(): boolean;
1322 | waitFor(): void;
1323 | filter(filter: (obj: UiObject) => boolean)
1324 | }
1325 |
1326 | interface UiObject {
1327 | click(): boolean;
1328 | longClick(): boolean;
1329 | setText(text: string): boolean;
1330 | copy(): boolean;
1331 | cut(): boolean;
1332 | paste(): boolean;
1333 | setSelection(start, end): boolean;
1334 | scrollForward(): boolean;
1335 | scrollBackward(): boolean;
1336 | select(): boolean;
1337 | collapse(): boolean;
1338 | expand(): boolean;
1339 | show(): boolean;
1340 | scrollUp(): boolean;
1341 | scrollDown(): boolean;
1342 | scrollLeft(): boolean;
1343 | scrollRight(): boolean;
1344 | children(): UiCollection;
1345 | childCount(): number;
1346 | child(i: number): UiObject;
1347 | parent(): UiObject;
1348 | bounds(): Rect;
1349 | boundsInParent(): Rect;
1350 | drawingOrder(): number;
1351 | id(): string;
1352 | text(): string;
1353 | findByText(str: string): UiCollection;
1354 | findOne(selector): UiObject;
1355 | find(selector): UiCollection;
1356 | }
1357 |
1358 | interface UiCollection {
1359 | size(): number;
1360 | get(i: number): UiObject;
1361 | each(func: (obj: UiObject) => void): void;
1362 | empty(): boolean;
1363 | nonEmpty(): boolean;
1364 | find(selector): UiCollection;
1365 | findOne(selector): UiObject;
1366 | }
1367 |
1368 | interface Rect {
1369 | left: number;
1370 | right: number;
1371 | top: number;
1372 | bottom: number;
1373 | centerX(): number;
1374 | centerY(): number;
1375 | width(): number;
1376 | height(): number;
1377 | contains(r): Rect;
1378 | intersect(r): Rect;
1379 | }
1380 |
1381 | }
1382 |
1383 |
1384 | export { };
1385 |
--------------------------------------------------------------------------------
/types/autox/modules/app.d.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * app模块提供一系列函数,用于使用其他应用、与其他应用交互。例如发送意图、打开文件、发送邮件等。
3 | */
4 | declare namespace app {
5 |
6 | /**
7 | * 通过应用名称启动应用。如果该名称对应的应用不存在,则返回false; 否则返回true。如果该名称对应多个应用,则只启动其中某一个。
8 | */
9 | function launchApp(appName: string): boolean;
10 |
11 | /**
12 | * 通过应用包名启动应用。如果该包名对应的应用不存在,则返回false;否则返回true。
13 | */
14 | function launch(packageName: string): boolean;
15 |
16 | /**
17 | * 通过应用包名启动应用。如果该包名对应的应用不存在,则返回false;否则返回true。
18 | */
19 | function launchPackage(packageName: string): boolean;
20 |
21 | /**
22 | * 获取应用名称对应的已安装的应用的包名。如果该找不到该应用,返回null;如果该名称对应多个应用,则只返回其中某一个的包名。
23 | */
24 | function getPackageName(appName: string): string;
25 |
26 | /**
27 | * 获取应用包名对应的已安装的应用的名称。如果该找不到该应用,返回null。
28 | */
29 | function getAppName(packageName: string): string;
30 |
31 | /**
32 | * 打开应用的详情页(设置页)。如果找不到该应用,返回false; 否则返回true。
33 | */
34 | function openAppSetting(packageName: string): boolean;
35 |
36 | /**
37 | * 用其他应用查看文件。文件不存在的情况由查看文件的应用处理。如果找不出可以查看该文件的应用,则抛出ActivityNotException。
38 | *
39 | * @throws ActivityNotException
40 | */
41 | function viewFile(path: string): void;
42 |
43 | /**
44 | * 用其他应用编辑文件。文件不存在的情况由编辑文件的应用处理。如果找不出可以编辑该文件的应用,则抛出ActivityNotException。
45 | *
46 | * @throws ActivityNotException
47 | */
48 | function editFile(path: string): void;
49 |
50 | /**
51 | * 卸载应用。执行后会会弹出卸载应用的提示框。如果该包名的应用未安装,由应用卸载程序处理,可能弹出"未找到应用"的提示。
52 | */
53 | function uninstall(packageName: string): void;
54 |
55 | /**
56 | * 用浏览器打开网站url。网站的Url,如果不以"http:// "或"https:// "开头则默认是"http:// "。
57 | */
58 | function openUrl(url: string): void;
59 |
60 | /**
61 | * 发送邮件的参数,这些选项均是可选的。
62 | */
63 | interface SendEmailOptions {
64 | /**
65 | * 收件人的邮件地址。如果有多个收件人,则用字符串数组表示
66 | */
67 | email?: string | string[];
68 | /**
69 | * 抄送收件人的邮件地址。如果有多个抄送收件人,则用字符串数组表示
70 | */
71 | cc?: string | string[];
72 | /**
73 | * 密送收件人的邮件地址。如果有多个密送收件人,则用字符串数组表示
74 | */
75 | bcc?: string | string[];
76 | /**
77 | * 邮件主题(标题)
78 | */
79 | subject?: string;
80 | /**
81 | * 邮件正文
82 | */
83 | text?: string;
84 | /**
85 | * 附件的路径。
86 | */
87 | attachment?: string;
88 | }
89 |
90 | /**
91 | * 根据选项options调用邮箱应用发送邮件。如果没有安装邮箱应用,则抛出ActivityNotException。
92 | */
93 | function sendEmail(options: SendEmailOptions): void;
94 |
95 | /**
96 | * 启动Auto.js的特定界面。该函数在Auto.js内运行则会打开Auto.js内的界面,在打包应用中运行则会打开打包应用的相应界面。
97 | */
98 | function startActivity(name: 'console' | 'settings'): void;
99 |
100 | /**
101 | * Intent(意图) 是一个消息传递对象,您可以使用它从其他应用组件请求操作。尽管 Intent 可以通过多种方式促进组件之间的通信.
102 | */
103 | interface Intent { }
104 |
105 | /**
106 | * 构造意图Intent对象所需设置。
107 | */
108 | interface IntentOptions {
109 | action?: string;
110 | type?: string;
111 | data?: string;
112 | category?: string[];
113 | packageName?: string;
114 | className?: string;
115 | extras?: Object;
116 | }
117 |
118 | /**
119 | * 根据选项,构造一个意图Intent对象。
120 | */
121 | function intent(options: IntentOptions): Intent;
122 |
123 | /**
124 | * 根据选项构造一个Intent,并启动该Activity。
125 | */
126 | function startActivity(intent: Intent): void;
127 |
128 | /**
129 | * 根据选项构造一个Intent,并发送该广播。
130 | */
131 | function sendBroadcast(intent: Intent): void;
132 |
133 | }
134 |
135 | /**
136 | * 通过应用名称启动应用。如果该名称对应的应用不存在,则返回false; 否则返回true。如果该名称对应多个应用,则只启动其中某一个。
137 | */
138 | declare function launchApp(appName: string): boolean;
139 |
140 | /**
141 | * 通过应用包名启动应用。如果该包名对应的应用不存在,则返回false;否则返回true。
142 | */
143 | declare function launch(packageName: string): boolean;
144 |
145 | /**
146 | * 获取应用名称对应的已安装的应用的包名。如果该找不到该应用,返回null;如果该名称对应多个应用,则只返回其中某一个的包名。
147 | */
148 | declare function getPackageName(appName: string): string;
149 |
150 | /**
151 | * 获取应用名称对应的已安装的应用的包名。如果该找不到该应用,返回null;如果该名称对应多个应用,则只返回其中某一个的包名。
152 | */
153 | declare function getPackageName(appName: string): string;
154 |
155 | /**
156 | * 获取应用包名对应的已安装的应用的名称。如果该找不到该应用,返回null。
157 | */
158 | declare function getAppName(packageName: string): string;
159 |
160 | /**
161 | * 打开应用的详情页(设置页)。如果找不到该应用,返回false; 否则返回true。
162 | */
163 | declare function openAppSetting(packageName: string): boolean;
164 |
--------------------------------------------------------------------------------
/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/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/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/device.d.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * device模块提供了与设备有关的信息与操作,例如获取设备宽高,内存使用率,IMEI,调整设备亮度、音量等。
3 | *
4 | * 此模块的部分函数,例如调整音量,需要"修改系统设置"的权限。如果没有该权限,会抛出SecurityException并跳转到权限设置界面。
5 | */
6 | declare global {
7 | namespace device {
8 |
9 | /**
10 | * 设备屏幕分辨率宽度。例如1080。
11 | */
12 | const width: number;
13 |
14 | /**
15 | * 设备屏幕分辨率高度。例如1920。
16 | */
17 | const height: number;
18 |
19 | /**
20 | * 修订版本号,或者诸如"M4-rc20"的标识。
21 | */
22 | const buildId: string;
23 |
24 | /**
25 | * 设备的主板(?)名称。
26 | */
27 | const broad: string;
28 |
29 | /**
30 | * 与产品或硬件相关的厂商品牌,如"Xiaomi", "Huawei"等。
31 | */
32 | const brand: string;
33 |
34 | /**
35 | * 设备在工业设计中的名称(代号)。
36 | */
37 | const device: string;
38 |
39 | /**
40 | * 设备型号。
41 | */
42 | const model: string;
43 |
44 | /**
45 | * 整个产品的名称。
46 | */
47 | const product: string;
48 |
49 | /**
50 | * 设备Bootloader的版本。
51 | */
52 | const bootloader: string;
53 |
54 | /**
55 | * 设备的硬件名称(来自内核命令行或者/proc)。
56 | */
57 | const hardware: string;
58 |
59 | /**
60 | * 构建(build)的唯一标识码。
61 | */
62 | const fingerprint: string;
63 |
64 | /**
65 | * 硬件序列号。
66 | */
67 | const serial: string;
68 |
69 | /**
70 | * 安卓系统API版本。例如安卓4.4的sdkInt为19。
71 | */
72 | const sdkInt: number;
73 |
74 | /**
75 | * 设备固件版本号。
76 | */
77 | const incremental: string;
78 |
79 | /**
80 | * Android系统版本号。例如"5.0", "7.1.1"。
81 | */
82 | const release: string;
83 |
84 | /**
85 | * 基础操作系统。
86 | */
87 | const baseOS: string;
88 |
89 | /**
90 | * 安全补丁程序级别。
91 | */
92 | const securityPatch: string;
93 |
94 | /**
95 | * 开发代号,例如发行版是"REL"。
96 | */
97 | const codename: string;
98 |
99 | /**
100 | * 返回设备的IMEI。
101 | */
102 | function getIMEI(): string;
103 |
104 | /**
105 | * 返回设备的Android ID。
106 | *
107 | * Android ID为一个用16进制字符串表示的64位整数,在设备第一次使用时随机生成,之后不会更改,除非恢复出厂设置。
108 | */
109 | function getAndroidId(): string;
110 |
111 | /**
112 | * 返回设备的Mac地址。该函数需要在有WLAN连接的情况下才能获取,否则会返回null。
113 | *
114 | * 可能的后续修改:未来可能增加有root权限的情况下通过root权限获取,从而在没有WLAN连接的情况下也能返回正确的Mac地址,因此请勿使用此函数判断WLAN连接。
115 | */
116 | function getMacAddress(): string;
117 |
118 | /**
119 | * 返回当前的(手动)亮度。范围为0~255。
120 | */
121 | function getBrightness(): number;
122 |
123 | /**
124 | * 返回当前亮度模式,0为手动亮度,1为自动亮度。
125 | */
126 | function getBrightnessMode(): number;
127 |
128 | /**
129 | * 设置当前手动亮度。如果当前是自动亮度模式,该函数不会影响屏幕的亮度。
130 | *
131 | * 此函数需要"修改系统设置"的权限。如果没有该权限,会抛出SecurityException并跳转到权限设置界面。
132 | */
133 | function setBrightness(b: number): void;
134 |
135 | /**
136 | * 设置当前亮度模式。
137 | *
138 | * 此函数需要"修改系统设置"的权限。如果没有该权限,会抛出SecurityException并跳转到权限设置界面。
139 | */
140 | function setBrightnessMode(mode: 0 | 1): void;
141 |
142 | /**
143 | * 返回当前媒体音量。
144 | */
145 | function getMusicVolume(): number;
146 |
147 | /**
148 | * 返回当前通知音量。
149 | */
150 | function getNotificationVolume(): number;
151 |
152 | /**
153 | * 返回当前闹钟音量。
154 | */
155 | function getAlarmVolume(): number;
156 |
157 | /**
158 | * 返回媒体音量的最大值。
159 | */
160 | function getMusicMaxVolume(): number;
161 |
162 | /**
163 | * 返回通知音量的最大值。
164 | */
165 | function getNotificationMaxVolume(): number;
166 |
167 | /**
168 | * 返回闹钟音量的最大值。
169 | */
170 | function getAlarmMaxVolume(): number;
171 |
172 | /**
173 | * 设置当前媒体音量。
174 | *
175 | * 此函数需要"修改系统设置"的权限。如果没有该权限,会抛出SecurityException并跳转到权限设置界面。
176 | */
177 | function setMusicVolume(volume: number): void;
178 |
179 | /**
180 | * 设置当前通知音量。
181 | *
182 | * 此函数需要"修改系统设置"的权限。如果没有该权限,会抛出SecurityException并跳转到权限设置界面。
183 | */
184 | function setNotificationVolume(volume: number): void;
185 |
186 | /**
187 | * 设置当前闹钟音量。
188 | *
189 | * 此函数需要"修改系统设置"的权限。如果没有该权限,会抛出SecurityException并跳转到权限设置界面。
190 | */
191 | function setAlarmVolume(volume: number): void;
192 |
193 | /**
194 | * 返回当前电量百分比。
195 | */
196 | function getBattery(): number;
197 |
198 | /**
199 | * 返回设备是否正在充电。
200 | */
201 | function isCharging(): boolean;
202 |
203 | /**
204 | * 返回设备内存总量,单位字节(B)。1MB = 1024 * 1024B。
205 | */
206 | function getTotalMem(): number;
207 |
208 | /**
209 | * 返回设备当前可用的内存,单位字节(B)。
210 | */
211 | function getAvailMem(): number;
212 |
213 | /**
214 | * 返回设备屏幕是否是亮着的。如果屏幕亮着,返回true; 否则返回false。
215 | *
216 | * 需要注意的是,类似于vivo xplay系列的息屏时钟不属于"屏幕亮着"的情况,虽然屏幕确实亮着但只能显示时钟而且不可交互,此时isScreenOn()也会返回false。
217 | */
218 | function isScreenOn(): boolean;
219 |
220 | /**
221 | * 唤醒设备。包括唤醒设备CPU、屏幕等。可以用来点亮屏幕。
222 | */
223 | function wakeUp(): void;
224 |
225 | /**
226 | * 如果屏幕没有点亮,则唤醒设备。
227 | */
228 | function wakeUpIfNeeded(): void;
229 |
230 | /**
231 | * 保持屏幕常亮。
232 | *
233 | * 此函数无法阻止用户使用锁屏键等正常关闭屏幕,只能使得设备在无人操作的情况下保持屏幕常亮;同时,如果此函数调用时屏幕没有点亮,则会唤醒屏幕。
234 | *
235 | * 在某些设备上,如果不加参数timeout,只能在Auto.js的界面保持屏幕常亮,在其他界面会自动失效,这是因为设备的省电策略造成的。因此,建议使用比较长的时长来代替"一直保持屏幕常亮"的功能,例如device.keepScreenOn(3600 * 1000)。
236 | *
237 | * 可以使用device.cancelKeepingAwake()来取消屏幕常亮。
238 | */
239 | function keepScreenOn(timeout: number): void;
240 |
241 | /**
242 | * 保持屏幕常亮,但允许屏幕变暗来节省电量。此函数可以用于定时脚本唤醒屏幕操作,不需要用户观看屏幕,可以让屏幕变暗来节省电量。
243 | *
244 | * 此函数无法阻止用户使用锁屏键等正常关闭屏幕,只能使得设备在无人操作的情况下保持屏幕常亮;同时,如果此函数调用时屏幕没有点亮,则会唤醒屏幕。
245 | *
246 | * 可以使用device.cancelKeepingAwake()来取消屏幕常亮。
247 | */
248 | function keepScreenDim(timeout: number): void;
249 |
250 | /**
251 | * 取消设备保持唤醒状态。用于取消device.keepScreenOn(), device.keepScreenDim()等函数设置的屏幕常亮。
252 | */
253 | function cancelKeepingAwake(): void;
254 |
255 | /**
256 | * 使设备震动一段时间。
257 | */
258 | function vibrate(millis: number): void;
259 |
260 | /**
261 | * 如果设备处于震动状态,则取消震动。
262 | */
263 | function cancelVibration(): void;
264 |
265 | }
266 |
267 | }
268 |
269 | export { };
--------------------------------------------------------------------------------
/types/autox/modules/dialogs.d.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * dialogs 模块提供了简单的对话框支持,可以通过对话框和用户进行交互。
3 | */
4 | declare namespace dialogs {
5 |
6 | /**
7 | * 显示一个只包含“确定”按钮的提示对话框。直至用户点击确定脚本才继续运行。
8 | */
9 | function alert(title: string, content?: string): void;
10 |
11 | /**
12 | * UI模式
13 | *
14 | * 显示一个只包含“确定”按钮的提示对话框。直至用户点击确定脚本才继续运行。
15 | */
16 | function alert(title: string, content?: string, callback?: () => void): Promise;
17 |
18 | /**
19 | * 显示一个包含“确定”和“取消”按钮的提示对话框。如果用户点击“确定”则返回 true ,否则返回 false 。
20 | */
21 | function confirm(title: string, content?: string): boolean;
22 |
23 | /**
24 | * UI模式
25 | *
26 | * 显示一个包含“确定”和“取消”按钮的提示对话框。如果用户点击“确定”则返回 true ,否则返回 false 。
27 | */
28 | function confirm(title: string, content?: string, callback?: (value: boolean) => void): Promise;
29 |
30 | /**
31 | * 显示一个包含输入框的对话框,等待用户输入内容,并在用户点击确定时将输入的字符串返回。如果用户取消了输入,返回null。
32 | */
33 | function rawInput(title: string, prefill?: string): string;
34 |
35 | /**
36 | * UI模式
37 | *
38 | * 显示一个包含输入框的对话框,等待用户输入内容,并在用户点击确定时将输入的字符串返回。如果用户取消了输入,返回null。
39 | */
40 | function rawInput(title: string, prefill?: string, callback?: (value: string) => void): Promise;
41 |
42 | /**
43 | * 等效于 eval(dialogs.rawInput(title, prefill, callback)), 该函数和rawInput的区别在于,会把输入的字符串用eval计算一遍再返回,返回的可能不是字符串。
44 | */
45 | function input(title: string, prefill?: string): any;
46 |
47 | /**
48 | * UI模式
49 | *
50 | * 等效于 eval(dialogs.rawInput(title, prefill, callback)), 该函数和rawInput的区别在于,会把输入的字符串用eval计算一遍再返回,返回的可能不是字符串。
51 | */
52 | function input(title: string, prefill?: string, callback?: (value: any) => void): Promise;
53 |
54 | /**
55 | * 显示一个包含输入框的对话框,等待用户输入内容,并在用户点击确定时将输入的字符串返回。如果用户取消了输入,返回null。
56 | */
57 | function prompt(title: string, prefill?: string): string;
58 |
59 | /**
60 | * UI模式
61 | *
62 | * 显示一个包含输入框的对话框,等待用户输入内容,并在用户点击确定时将输入的字符串返回。如果用户取消了输入,返回null。
63 | */
64 | function prompt(title: string, prefill?: string, callback?: (value: string) => void): Promise;
65 |
66 | /**
67 | * 显示一个带有选项列表的对话框,等待用户选择,返回用户选择的选项索引(0 ~ item.length - 1)。如果用户取消了选择,返回-1。
68 | */
69 | function select(title: string, items: string[]): number;
70 |
71 | /**
72 | * UI模式
73 | *
74 | * 显示一个带有选项列表的对话框,等待用户选择,返回用户选择的选项索引(0 ~ item.length - 1)。如果用户取消了选择,返回-1。
75 | */
76 | function select(title: string, items: string[], callback?: (value: number) => void): Promise;
77 |
78 | /**
79 | * 显示一个单选列表对话框,等待用户选择,返回用户选择的选项索引(0 ~ item.length - 1)。如果用户取消了选择,返回-1。
80 | */
81 | function singleChoice(title: string, items: string[], index?: number): number;
82 |
83 | /**
84 | * UI模式
85 | *
86 | * 显示一个单选列表对话框,等待用户选择,返回用户选择的选项索引(0 ~ item.length - 1)。如果用户取消了选择,返回-1。
87 | */
88 | function singleChoice(title: string, items: string[], index?: number, callback?: (choice: number) => void): Promise;
89 |
90 | /**
91 | * 显示一个多选列表对话框,等待用户选择,返回用户选择的选项索引的数组。如果用户取消了选择,返回[]。
92 | */
93 | function multiChoice(title: string, items: string[], indices?: number[]): number[];
94 |
95 | /**
96 | * UI模式
97 | *
98 | * 显示一个多选列表对话框,等待用户选择,返回用户选择的选项索引的数组。如果用户取消了选择,返回[]。
99 | */
100 | function multiChoice(title: string, items: string[], indices?: number[], callback?: (choices: number[]) => void): Promise;
101 |
102 |
103 | }
104 |
105 | /**
106 | * 显示一个只包含“确定”按钮的提示对话框。直至用户点击确定脚本才继续运行。
107 | */
108 | declare function alert(title: string, content?: string): void;
109 |
110 | /**
111 | * UI模式
112 | *
113 | * 显示一个只包含“确定”按钮的提示对话框。直至用户点击确定脚本才继续运行。
114 | *
115 | * 在ui模式下该函数返回一个Promise。
116 | */
117 | declare function alert(title: string, content?: string, callback?: () => void): Promise;
118 |
119 | /**
120 | * 显示一个包含“确定”和“取消”按钮的提示对话框。如果用户点击“确定”则返回 true ,否则返回 false 。
121 | */
122 | declare function confirm(title: string, content?: string): boolean;
123 |
124 | /**
125 | * UI模式
126 | *
127 | * 显示一个包含“确定”和“取消”按钮的提示对话框。如果用户点击“确定”则返回 true ,否则返回 false 。
128 | *
129 | * 在ui模式下该函数返回一个Promise。
130 | */
131 | declare function confirm(title: string, content?: string, callback?: (value: boolean) => void): Promise;
132 |
133 | /**
134 | * 显示一个包含输入框的对话框,等待用户输入内容,并在用户点击确定时将输入的字符串返回。如果用户取消了输入,返回null。
135 | */
136 | declare function rawInput(title: string, prefill?: string): string;
137 |
138 | /**
139 | * UI模式
140 | *
141 | * 显示一个包含输入框的对话框,等待用户输入内容,并在用户点击确定时将输入的字符串返回。如果用户取消了输入,返回null。
142 | */
143 | declare function rawInput(title: string, prefill?: string, callback?: (value: string) => void): Promise;
144 |
--------------------------------------------------------------------------------
/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 | }
--------------------------------------------------------------------------------
/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/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/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/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/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/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/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 |
--------------------------------------------------------------------------------
/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/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/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 | }
--------------------------------------------------------------------------------
/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/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/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/widgets.d.ts:
--------------------------------------------------------------------------------
1 | declare function auto(mode?: 'fast' | 'normal'): void;
2 | declare namespace auto {
3 | function waitFor(): void;
4 | function setMode(mode: 'fast' | 'normal'): void;
5 | }
6 | declare function selector(): UiSelector;
7 | declare function click(text: string, index?: number): boolean;
8 | declare function click(left: number, top: number, bottom: number, right: number): boolean;
9 | declare function longClick(text: string, index?: number): boolean;
10 | declare function scrollUp(index?: number): boolean;
11 | declare function scrollDown(index?: number): boolean;
12 | declare function setText(text: string): boolean;
13 | declare function setText(index: number, text: string): boolean;
14 | declare function input(text: string): boolean;
15 | declare function input(index: number, text: string): boolean;
16 |
17 | declare interface UiSelector {
18 | text(str: string): UiSelector;
19 | textContains(str: string): UiSelector;
20 | textStartsWith(prefix: string): UiSelector;
21 | textEndsWith(suffix: string): UiSelector;
22 | textMatches(reg: string | RegExp): UiSelector;
23 | desc(str: string): UiSelector;
24 | descContains(str: string): UiSelector;
25 | descStartsWith(prefix: string): UiSelector;
26 | descEndsWith(suffix: string): UiSelector;
27 | descMatches(reg: string | RegExp): UiSelector;
28 | id(resId: string): UiSelector;
29 | idContains(str: string): UiSelector;
30 | idStartsWith(prefix: string): UiSelector;
31 | idEndsWith(suffix: string): UiSelector;
32 | idMatches(reg: string | RegExp): UiSelector;
33 | className(str: string): UiSelector;
34 | classNameContains(str: string): UiSelector;
35 | classNameStartsWith(prefix: string): UiSelector;
36 | classNameEndsWith(suffix: string): UiSelector;
37 | classNameMatches(reg: string | RegExp): UiSelector;
38 | packageName(str: string): UiSelector;
39 | packageNameContains(str: string): UiSelector;
40 | packageNameStartsWith(prefix: string): UiSelector;
41 | packageNameEndsWith(suffix: string): UiSelector;
42 | packageNameMatches(reg: string | RegExp): UiSelector;
43 | bounds(left: number, top: number, right: number, buttom: number): UiSelector;
44 | boundsInside(left: number, top: number, right: number, buttom: number): UiSelector;
45 | boundsContains(left: number, top: number, right: number, buttom: number): UiSelector;
46 | drawingOrder(order): UiSelector;
47 | clickable(b: boolean): UiSelector;
48 | longClickable(b: boolean): UiSelector;
49 | checkable(b: boolean): UiSelector;
50 | selected(b: boolean): UiSelector;
51 | enabled(b: boolean): UiSelector;
52 | scrollable(b: boolean): UiSelector;
53 | editable(b: boolean): UiSelector;
54 | multiLine(b: boolean): UiSelector;
55 | findOne(): UiObject;
56 | findOne(timeout: number): UiObject;
57 | findOnce(): UiObject;
58 | findOnce(i: number): UiObject;
59 | find(): UiCollection;
60 | untilFind(): UiCollection;
61 | exists(): boolean;
62 | waitFor(): void;
63 | filter(filter: (obj: UiObject) => boolean)
64 | }
65 |
66 | declare interface UiObject {
67 | click(): boolean;
68 | longClick(): boolean;
69 | setText(text: string): boolean;
70 | copy(): boolean;
71 | cut(): boolean;
72 | paste(): boolean;
73 | setSelection(start, end): boolean;
74 | scrollForward(): boolean;
75 | scrollBackward(): boolean;
76 | select(): boolean;
77 | collapse(): boolean;
78 | expand(): boolean;
79 | show(): boolean;
80 | scrollUp(): boolean;
81 | scrollDown(): boolean;
82 | scrollLeft(): boolean;
83 | scrollRight(): boolean;
84 | children(): UiCollection;
85 | childCount(): number;
86 | child(i: number): UiObject;
87 | parent(): UiObject;
88 | bounds(): Rect;
89 | boundsInParent(): Rect;
90 | drawingOrder(): number;
91 | id(): string;
92 | text(): string;
93 | findByText(str: string): UiCollection;
94 | findOne(selector): UiObject;
95 | find(selector): UiCollection;
96 | }
97 |
98 | declare interface UiCollection {
99 | size(): number;
100 | get(i: number): UiObject;
101 | each(func: (obj: UiObject) => void): void;
102 | empty(): boolean;
103 | nonEmpty(): boolean;
104 | find(selector): UiCollection;
105 | findOne(selector): UiObject;
106 | }
107 |
108 | declare interface Rect {
109 | left: number;
110 | right: number;
111 | top: number;
112 | bottom: number;
113 | centerX(): number;
114 | centerY(): number;
115 | width(): number;
116 | height(): number;
117 | contains(r): Rect;
118 | intersect(r): Rect;
119 | }
--------------------------------------------------------------------------------
/types/index.d.ts:
--------------------------------------------------------------------------------
1 | ///
2 | ///
3 | ///
4 | ///
5 | ///
6 |
--------------------------------------------------------------------------------
/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/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 |
--------------------------------------------------------------------------------