-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
悬浮窗停止脚本运行,外置配置文件无法加载。 #360
Copy link
Copy link
Closed
Labels
Apperception 🎯 统觉Issue closed by the creater on his or her ownIssue closed by the creater on his or her ownDoubt ❔ 疑惑Any doubts about this repositoryAny doubts about this repositorySettled 🌴 完成Happy ending for both human beings and issues themselvesHappy ending for both human beings and issues themselves
Description
Metadata
Metadata
Assignees
Labels
Apperception 🎯 统觉Issue closed by the creater on his or her ownIssue closed by the creater on his or her ownDoubt ❔ 疑惑Any doubts about this repositoryAny doubts about this repositorySettled 🌴 完成Happy ending for both human beings and issues themselvesHappy ending for both human beings and issues themselves
我有一个脚本,是这样的结构:
我的脚本.js:
`
// 引入配置文件,这里面就是个数组
var config = require("./config.js");
function a(){
//反正就是有函数应用配置里的参数
let username =config.username;
let password = config.password;
……
}
fuction b(){
// 诸如此类的引用,不计其数
let url =config.url;
let token = config.token;
……
}
……
function main(){
// 主函数调用上面的函数
a();
b();
……
}
//执行主函数
main();
`
结构大概是这样,很简单。
现在我想做一个悬浮窗按钮,能够停止这个脚本。
我先新建了一个脚本,尝试外部调用js文件。
当我使用engines.execScriptFile("我的脚本.js")时:
07:17:49.393/E: Error: Can't resolve relative module ID "./config.js" when require() is used outside of a module (file:///android_asset/modules/jvm-npm.js#100) Error: Can't resolve relative module ID "./config.js" when require() is used outside of a module at file:///android_asset/modules/jvm-npm.js:100:0 at file:///android_asset/modules/jvm-npm.js:64:0 at /storage/emulated/0/脚本/我的脚本.js:16:0然后我尝试在原来的脚本里面,使用调用函数的方式,去调用main函数。
engines.execScript("hello world", "main();\n" + main.toString());
ReferenceError: "config" 未定义. ($engine/hello world.js#3) ReferenceError: "config" 未定义.啊这……
也许我应该放弃这种方式,想想有没有其它方式。
毕竟我的需求是弄个悬浮窗的停止按钮,目前为止连悬浮窗都没有。
我看到Autojs6APP里内置的demo是这样子的。
可是,外部配置文件,就加载不了了。
不知道还有没有其它办法?
神一样的作者,还请赐我指引。