-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod_main.js
378 lines (361 loc) · 13.2 KB
/
mod_main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
// termux初始化脚本
let termuxScript = `pkg update -y
`;
let termuxScript_1 = `pkg upgrade -y
`;
let termuxScript_2 = `Y
`;
// UI初始化
ui.layout(main); // 显示视图
// 创建悬浮窗类
F = new FloatingWindowControl(window, window.floatingView, functionWindow, window.move);
function hnfo(string, time) {
let time = time ? time : 2000;
if (F.isMini) {
F.onLongClick();
hnfo(string, time);
return
}
string_ = string.length > 15 ? string.slice(0, 15) + "···" : string;
window.hint_info.setText(window.hint_info.getText() == "" ? "提示:" + string_ : window.hint_info.getText() + "\n" + string_);
hint(1, "提示:" + string, time);
}
function herror(string, time) {
let time = time ? time : 2000;
if (F.isMini) {
F.onLongClick();
herror(string, time);
return
}
string_ = string.length > 15 ? string.slice(0, 15) + "···" : string;
window.hint_error.setText(window.hint_error.getText() == "" ? "报错:" + string_ : window.hint_error.getText() + "\n" + string_);
hint(2, "报错:" + string, time);
}
function hint(mod, string, delay) {
if (F.isMini) {
F.onLongClick();
hint(string);
return;
}
// 获取当前时间戳和要添加的文本
var currentTimeStamp = getCurrentTimeStamp();
var textToSet = window.hint.getText() + "\n" + currentTimeStamp + "/\n" + string;
// 设置文本
window.hint.setText(textToSet);
// 使用post方法在UI线程中排队滚动操作
ui.post(() => {
// 获取ScrollView和内部文本视图的高度
var scrollViewHeight = window.scrollView.getHeight();
var textHeight = window.hint.getHeight();
// 计算需要滚动到的位置
var scrollPosition = textHeight - scrollViewHeight;
// 使用scrollTo方法滚动到最底部
if (scrollPosition > 0) {
window.scrollView.scrollTo(0, scrollPosition);
}
});
F.twinkle(mod, delay);
}
// hint(1, "欢迎使用本助手!");
ui.viewpager.currentItem = 1; //跳转到1号子页面
ui.viewpager.overScrollMode = View.OVER_SCROLL_NEVER; //删除滑动到底的阴影
ui.sideViewList.setDataSource(sideViewList);
ui.viewpager.setPageTransformer(true, new MyPageTransform()); //设置viewpager切换动画
function MyPageTransform() {
// 自定义滑动页面切换器
var mDp30 = dp2px(30);
var mRadius = 0;
var pageWidth;
this.transformPage = (function(view, position) {
pageWidth = view.getWidth();
if (position < -1) {
view.setAlpha(0);
} else if (position <= 0) {
view.setTranslationX(pageWidth * position);
} else if (position <= 1) {
view.setTranslationX((pageWidth * 0.6) * -position);
view.setScaleX(1 - (0.2 * position));
view.setScaleY(1 - (0.2 * position));
if (mRadius != parseInt(mDp30 * position)) { //圆角切换
ui.card.attr("cardCornerRadius", (mRadius = parseInt(mDp30 * position)) + "px");
ui.card.attr("cardElevation", (mRadius = parseInt(mDp30 * position * 0.5)) + "px");
};
if (position == 1) { // 当位于左侧页面时
currentPage = -1; // 更新当前页面状态
ui.sideViewList.attr("w", parseInt(pageWidth * 0.5) + "px");
};
} else {
view.setAlpha(0);
}
});
};
loadTools(0); // 初始化
function acceTest() {
threads.start(() => {
auto.waitFor();
ui.post(() => {
accBool = true;
if (currentPage == "set") ui.acc_text.setText("无障碍权限:" + (accBool ? '已授予' : '未授予(点击进行授予)'));
});
});
}
ui.emitter.on("back_pressed", (e) => {
// 返回执行函数
// 数字标识为基础页面;字符串标识为侧边栏中的其他页面
/*
-1:侧边栏
0:主页
1:工具页
*/
if (currentPage == "web") { // 如果当前页面是讨论页面
if (ui.webView.canGoBack()) { // 如果webView可以返回
ui.webView.goBack(); // 执行返回操作
} else {
// 如果webView不能返回,则返回至上一个页面
ui.viewpager.currentItem = 0;
currentPage = -1;
}
} else {
if (currentPage == 2) {
// loadTools("sS");
} else
if (currentPage == 1) {
loadTools(0);
} else if (currentPage == 0) { // 判断是否退出
backPressCount++;
if (backPressCount == 1) {
toast("再按一次退出应用");
backPressTimer = setTimeout(() => {
// 如果在提示后用户没有再次点击返回键,则重置点击次数
backPressCount = 0;
}, 3000);
}
// 如果点击次数为2,则退出应用
if (backPressCount == 2) {
clearTimeout(backPressTimer);
exit();
}
} else if (currentPage == -1) {
ui.viewpager.currentItem = 1;
loadTools(0);
} else {
ui.viewpager.currentItem = 0;
currentPage = -1;
toast("再按一次返回工具界面");
}
}
e.consumed = true;
});
ui.sideViewList.on("item_click", (item, index) => {
// 侧边栏监听函数
if (index == 0) {
loadTools(0);
ui.viewpager.currentItem = 1; //跳转到1号子页面
} else if (index == 1) {
currentPage = "web";
changeToViewXML(webViewXML);
// webViewExtend(ui.webView);
ui.viewpager.currentItem = 1; //跳转到1号子页面
ui.webView.loadUrl("https://github.com/Delta-Water/RustedWarfare-Development-Tools/discussions");
} else if (index == 2) {
accTestBool = dataBase.get("accTestBool", false);
changeToViewXML(settingXML);
ui.viewpager.currentItem = 1;
currentPage = "set";
ui.acc.on("check", (checked) => {
if (checked) {
accTestBool = true;
dataBase.put("accTestBool", true)
} else {
accTestBool = false;
dataBase.put("accTestBool", false)
}
})
ui.acc_text.on("click", () => {
acceTest();
})
ui.acc_text.setText("无障碍权限:" + (accBool ? '已授予' : '未授予(点击进行授予)'));
} else if (index == 3) {
dialogs.build({
title: "关于",
content: '开发者:DeltaWater\n自动热更新已开启\n版本号:' + vN_ + "\n欢迎有一定代码基础者加入开发\n欢迎分享本工具,持续完善中",
positive: "分享",
neutral: "检测更新",
negative: "GitHub"
})
.on("positive", () => {
setClip("https://github.com/Delta-Water/RustedWarfare-Development-Tools/releases");
toast("已复制下载链接");
})
.on("neutral", () => {
updateFiles(true);
})
.on("negative", () => {
app.openUrl("https://github.com/Delta-Water/RustedWarfare-Development-Tools");
})
.show();
}
})
function loadTools(pa, pa2) {
// 工具加载函数
/*
0:加载本地工具和工具源
*/
if (pa == 0) {
if (accTestBool) {
acceTest();
}
let sourcesArray = [];
let toolsArray = [];
files.listDir(assPath).forEach((fileName) => {
let _path = assPath + fileName + "/";
let info = JSON.parse(files.read(_path + "info.json"));
sourcesArray.push({
"p": _path,
"n": info.name,
"sI": info.simpleIntroduction,
"dI": info.detailedIntroduction,
"v": info.version
});
files.listDir(_path).forEach((fileName) => {
let __path = _path + fileName + "/";
if (files.isDir(__path)) {
let info = JSON.parse(files.read(__path + "info.json"));
toolsArray.push({
"p": __path,
"n": info.name,
"dI": info.detailedIntroduction,
"t": info.termux == true ? true : false
})
}
});
})
changeToViewXML(toolsViewXML);
currentPage = 0;
ui.tools.setDataSource(toolsArray);
ui.tools.on("item_click", (item) => {
if (item.t) {
if (!T.launchTest()) return
if (accBool != true) {
herror("请先行前往设置检测(授予)无障碍");
return
}
initTermux();
}
toolScript = files.read(item.p + "main.js");
eval(toolScript);
currentPage = 1;
});
} else if (pa == "sS") { //searchSource
} else if (pa == "sT") { //searchTools
}
}
function initTermux() {
// termux初始化函数
if (!dataBase.get("initTermuxBool", false)) {
hnfo("你尚未进行初始化");
let successStrings = [
["Run 'apt list --upgradable' to see", "All packages are up to date."],
];
hnfo("获取pkg更新信息", 4000);
T.sendCommandAndConfirm(termuxScript, successStrings, (id) => {
if (id[0] == 1) {
hnfo("无需更新");
hnfo("已完成初始化");
dataBase.put("initTermuxBool", true);
hnfo("请返回到助手执行下一步操作");
return
}
hnfo("即将执行pkg包更新指令,更新过程可能耗时长,请耐心等待,在下载中可以切后台去其他应用放松一下");
let successStrings = [
["*** sources.list (Y/I/N/O/D/Z) [default=N] ?", "to remove and", ]
];
T.sendCommandAndConfirm(termuxScript_1, successStrings, (id) => {
if (id[0] != 0) {
hnfo("完成更新");
hnfo("已完成初始化");
dataBase.put("initTermuxBool", true);
hnfo("请返回到助手执行下一步操作");
return
}
let successStrings = [
"*** sources.list (Y/I/N/O/D/Z) [default=N] ?Y"
];
T.sendCommandAndConfirm(termuxScript_2, successStrings, () => {
hnfo("完成更新");
hnfo("已完成初始化");
dataBase.put("initTermuxBool", true);
hnfo("请返回到助手执行下一步操作");
});
})
})
return
}
}
// 暂时弃用的代码
/*
activity.setSupportActionBar(ui.toolbar);
ui.toolsViewPager.setTitles(["工具", "仓库"]);
ui.tabs.setupWithViewPager(ui.toolsViewPager);
ui.sources.setDataSource(sourcesArray);
*/
/*
var webSettings = ui.webView.getSettings();
webSettings.setJavaScriptEnabled(true); // 启用JavaScript
webSettings.setAllowFileAccess(true); // 允许访问文件
webSettings.setAllowContentAccess(true); // 允许内容访问
webSettings.setDomStorageEnabled(true); // 启用DOM存储API
*/
// ui.webView.loadUrl("https://github.com/Delta-Water/RustedWarfare-Development-Tools/discussions");
/*
function webViewExtend(webView) {
webView.webViewClient = new JavaAdapter(android.webkit.WebViewClient, {
shouldOverrideUrlLoading: function(view, url) {
view.loadUrl(url);
return true;
},
onReceivedError: function(view, errorCode, description, failingUrl) {
// 处理错误
},
doUpdateVisitedHistory: function(view, url, isReload) {
// 更新历史记录
},
onFormResubmission: function(view, dontResend, resend) {
// 处理表单重新提交
},
onReceivedSslError: function(view, handler, error) {
// 处理SSL错误
},
onScaleChanged: function(view, oldScale, newScale) {
// 缩放变化
},
onUnhandledKeyEvent: function(view, event) {
// 处理未处理的关键事件
},
onPageFinished: function(view, url) {
// 页面加载完成
// 将JavaScript函数作为参数传递给WebView的loadUrl方法
ui.webView.loadUrl("javascript:(function(){" + hideUnwantedContent + "})()");
},
onPageStarted: function(view, url, favicon) {
// 页面开始加载
},
onReceivedHttpAuthRequest: function(view, handler, host, realm) {
// 接收HTTP身份验证请求
},
shouldOverrideKeyEvent: function(view, event) {
// 是否覆盖关键事件
},
onUnhandledInputEvent: function(view, event) {
// 处理未处理的输入事件
},
onReceivedLoginRequest: function(view, realm, account, args) {
// 接收登录请求
}
});
}*/
/*
// 创建一个JavaScript函数,用于隐藏不需要的元素
var hideUnwantedContent = `
`;
*/