Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何调用 vscode 中的动作? #6

Closed
lanmingle opened this issue Apr 17, 2023 · 5 comments
Closed

如何调用 vscode 中的动作? #6

lanmingle opened this issue Apr 17, 2023 · 5 comments
Labels
Apperception 🎯 统觉 Issue closed by the creater on his or her own Feature 💎 功能 New feature or request

Comments

@lanmingle
Copy link

lanmingle commented Apr 17, 2023

比如调用保存、重新运行。

autox 中提供 http 接口,127.0.0.1:9317/cmd=x&path=x 这样

原在 autox 中弄了一个基于 TS 的模板:https://github.com/lanaqi-opensource/autox-typescript-template ,现在想用 AutoJs6 却没能对这个项目支持。

PS:想用 AutoJs6 ,感觉 AutoJs6 文档健全点,也没有这么多碎片化。

@SuperMonster003
Copy link
Owner

SuperMonster003 commented May 31, 2023

可以提供更详细的接口参数吗, 比如 cmd 需要那些参数, 分别做什么用, path 又有什么作用, 格式是什么.

例如我猜想到的 cmd 可能是 "run", 发送到 VSCode 后会运行脚本; 也可能是 "stop", 发送后 VSCode 将停止运行当前脚本; 等等.

我需要知道接口参数的功能及说明, 才能让 VSCode 插件对接收到的指令做出预期响应.

关联议题: SuperMonster003/AutoJs6#66

@SuperMonster003 SuperMonster003 added Accepted 🌱 受理 Maintainer may be busy resolving or fixing the labeled issues Feedback Awaited 🕒 等待反馈 Waiting for the feedback from issue creater and issue will be closed if duration is over one month More Info Needed 🔎 提供详情 Further information is requested Feature 💎 功能 New feature or request labels May 31, 2023
@lanmingle
Copy link
Author

lanmingle commented Jun 9, 2023

谢谢作者大大的支持。

能否提供 http 接口支持,如 save 的时候,把指定文件或文件内容,类似 vs code 中调用 id, name, script 等(可以保存到指定目录上等)。

    saveTo(devices: Devices) {
        let editor = vscode.window.activeTextEditor;
        devices.sendCommand('save', {
            id: editor.document.fileName,
            name: editor.document.fileName,
            script: editor.document.getText(),
        });
    }

这个是调用 autoxjs 中的例子

   // cmd 是 run 或 save
   // path 是本地需要保存或运行的目录值(类似在 vscode 中保存项目)

    // 发送部署命令
    private sendDeployCmd(execCmd: string, sendPath: string, deployName: string): void {
        const req = nodeHttp.get(`http://127.0.0.1:9317/exec?cmd=${execCmd}&path=${encodeURI(sendPath)}`, (res) => {
            res.setEncoding('utf8');
            res.addListener('data', (data) => {
                console.debug('部署执行器: %s -> 执行命令成功!- data: %s', deployName, data);
            }).addListener('error', (error) => {
                console.error('部署执行器: %s -> 执行命令失败!- error: %s', deployName, error);
            });
        });
        req.addListener('finish', () => {
            console.debug('部署执行器: %s -> 发送命令成功! - cmd: %s ; path: %s', deployName, execCmd, sendPath);
        });
        req.addListener('error', (error) => {
            console.error('部署执行器: %s -> 发送命令失败!- error: %s', deployName, error);
        });
    }

@SuperMonster003
Copy link
Owner

我看到项目中的 "使用步骤" 如下:

  1. 复制工程目录所有到你的项目中。
  2. 打开 VsCode 开启服务并监听 ADB 设备。
  3. 使用 Autox.js 连接 VsCode 监听。
  4. 运行项目中 scripts 即可。
  5. 使用资源文件时,需先部署,否则无法读取(可以修改 DEPLOY_ACTION 为 both 值)。

但我还是没能理解具体要怎样操作或测试.

我根据你提供的 "发送部署命令" 方法 sendDeployCmd(execCmd: string, sendPath: string, deployName: string): void 做了一定程度的适配, 但有几点注意事项:

  1. AutoJS6 VSCode 插件需 1.0.5 及以上版本
  2. VSCode 插件无需手动开启监听服务, 启动 VSCode 时插件将自动激活服务
  3. VSCode 插件的 HTTP 服务监听端口为 10347
  4. 查询字符串 cmd=${execCmd} 中, execCmd 支持的命令有:
'viewDocument', 'connect', 'disconnectAll',
'run', 'runOnDevice', 'stop', 'stopAll', 'rerun',
'save', 'saveToDevice', 'newProject',
'runProject', 'saveProject', 'rerunProject'

我看到你的项目使用的两个命令 'rerun' 和 'save' 都是项目级别的, 因此对应 AutoJs6 VSCode 插件应分别为 'rerunProject' 和 'saveProject'.

PS: VSCode 插件 1.0.5 版本暂时还没有发布到 VSCode 插件市场, 计划于本周内发布.

@lanmingle
Copy link
Author

@SuperMonster003 很棒哟 ~ 我这边这几天更新一下这个模板工程。

@lanmingle
Copy link
Author

项目模板已更新,地址:https://github.com/lanaqi-opensource/autojs6-typescript-template
后续可能会修改上述更多命令支持。

@SuperMonster003 SuperMonster003 added Apperception 🎯 统觉 Issue closed by the creater on his or her own and removed Accepted 🌱 受理 Maintainer may be busy resolving or fixing the labeled issues Feedback Awaited 🕒 等待反馈 Waiting for the feedback from issue creater and issue will be closed if duration is over one month More Info Needed 🔎 提供详情 Further information is requested labels Nov 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Apperception 🎯 统觉 Issue closed by the creater on his or her own Feature 💎 功能 New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants