Skip to content

Commit

Permalink
2.1.10 - 修复闹钟间隔事件监测异常 Pro版本支持对话框按钮颜色并优化控件获取
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperMonster003 committed Aug 22, 2021
1 parent 6e93a95 commit 2c8c4a3
Show file tree
Hide file tree
Showing 16 changed files with 263 additions and 172 deletions.
21 changes: 9 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@

[comment]: <> (Version history only shows last 3 versions)

# v2.1.10
###### 2021/08/22
* `修复` 获取能量罩信息时可能出现空指针的问题
* `修复` 闹钟间隔事件监测代码异常导致脚本终止的问题
* `修复` $$cvt对0到1之间的输入数据返回值为空的问题
* `优化` threadsx.start()支持箭头函数及绑定函数
* `优化` Pro版本增加对话框按钮自定义颜色设置的支持
* `优化` Pro版本移除获取控件信息对currentPackage()的依赖

# v2.1.9
###### 2021/08/20
* `修复` 配置工具无法设置排行榜滑动距离等相关配置项的问题
Expand All @@ -129,18 +138,6 @@
* `优化` 完善内存信息工具内的提示信息
* `优化` 去除控制台消息在简略模式下的部分无关内容

# v2.1.7
###### 2021/08/08
* `新增` 内存信息工具 (简易) (/tools/auto.js-memory-info-tool.js)
* `修复` 由项目自动管理的定时任务排他特性失效的问题
* `修复` Pro版本控件刷新滞缓造成部分条件判断失效的问题
* `修复` swipeAndShow方法内部逻辑错误导致功能失效的问题
* `修复` debugInfo方法强制标记参数可能不生效的问题
* `优化` 增加闹钟事件监测避免执行期间可能的闹钟误触 _[`issue #505`](https://github.com/SuperMonster003/Ant-Forest/issues/505)_
* `优化` 模块化与排行榜数据样本池相关的实例
* `优化` 及时回收图片资源避免可能的内存泄漏 _[`issue #497`](https://github.com/SuperMonster003/Ant-Forest/issues/497)_
* `优化` 能量雨收集工具条件判断完善及网络异常适配

##### 更多版本历史可参阅

* [CHANGELOG-2.md](https://github.com/SuperMonster003/Ant-Forest/blob/master/documents/CHANGELOG-2.md) ( 2.x 版本 )
Expand Down
73 changes: 38 additions & 35 deletions ant-forest-launcher.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Alipay ant forest intelligent collection script launcher
* @since Aug 20, 2021
* @version 2.1.9
* @since Aug 22, 2021
* @version 2.1.10
* @author SuperMonster003
* @see https://github.com/SuperMonster003/Ant-Forest
*/
Expand Down Expand Up @@ -139,19 +139,17 @@ let $$init = {
get ts_sec() {
return Date.now() / 1e3 >> 0;
},
exit: (quiet) => {
if (quiet !== true) {
$$app.layout.closeAll();
floaty.closeAll(); // just in case
debugInfo('关闭所有floaty悬浮窗');
if ($$app.queue.excl_tasks_all_len > 1) {
debugInfo('移除当前脚本广播监听器');
events.broadcast.removeAllListeners();
debugInfo('发送初始屏幕开关状态广播');
events.broadcast.emit('init_scr_on_state_change', $$app.init_scr_on);
}
messageAction($$app.task_name + '任务结束', 1, 0, 0, '2_n');
exit() {
this.layout.closeAll();
floaty.closeAll(); // just in case
debugInfo('关闭所有floaty悬浮窗');
if (this.queue.excl_tasks_all_len > 1) {
debugInfo('移除当前脚本广播监听器');
events.broadcast.removeAllListeners();
debugInfo('发送初始屏幕开关状态广播');
events.broadcast.emit('init_scr_on_state_change', this.init_scr_on);
}
messageAction(this.task_name + '任务结束', 1, 0, 0, '2_n');
// exit() might cause ScriptInterruptedException
// as $$app.exit might invoked within Promise
ui.post(exit);
Expand Down Expand Up @@ -3158,9 +3156,7 @@ let $$init = {
}, 10e3);
},
start(this_arg) {
this._thd = threadsx.start(new java.lang.Runnable({
run: () => this._fx(this_arg),
}));
this._thd = threadsx.start(() => this._fx(this_arg));
},
interrupt() {
if (this._thd) {
Expand Down Expand Up @@ -3288,6 +3284,7 @@ let $$init = {
messageAction('触发按键: 音量减/VOL-', 3, 0, 1);
messageAction(_keyMsg(e), 3, 0, 1, 1);
$$app.monitor.insurance.reset();
threads.shutDownAll();
engines.myEngine().forceStop();
});
events.setKeyInterceptionEnabled('volume_up', true);
Expand All @@ -3296,6 +3293,7 @@ let $$init = {
messageAction('触发按键: 音量加/VOL+', 4, 0, 1);
messageAction(_keyMsg(e), 4, 0, 1, 1);
$$app.monitor.insurance.reset();
threads.shutDownAll();
engines.stopAllAndToast();
});
});
Expand Down Expand Up @@ -3407,11 +3405,11 @@ let $$init = {
_outer_pkg: /clock|alarm/i,
_isInnerPkg() {
$$a11y.service.refreshServiceInfo();
return !!currentPackage().match(this._inner_pkg);
return this._inner_pkg.test(currentPackage());
},
_isOuterPkg() {
$$a11y.service.refreshServiceInfo();
return !!currentPackage().match(this._outer_pkg);
return this._outer_pkg.test(currentPackage());
},
_saveInnerPkg() {
this._inner_pkg = currentPackage();
Expand All @@ -3428,7 +3426,7 @@ let $$init = {
_msgAboutToTrigger() {
if (files.exists('./modules/mod-alarm-countdown.js')) {
return require('./modules/mod-alarm-countdown').show({
is_async: true,
is_async: true, title: '闹钟即将触发',
});
}
let _delay = 2;
Expand All @@ -3438,7 +3436,7 @@ let $$init = {
}, _delay * 1e3);
},
_msgTriggered() {
$$toast('闹钟界面置于后台时\n脚本将自动继续', 'L', 'F');
$$toast('支付宝界面前置时\n脚本将自动继续', 'L', 'F');
},
trigger() {
return devicex.isNextAlarmClockTriggered(this._thrd);
Expand Down Expand Up @@ -3929,9 +3927,7 @@ let $$init = {
}
debugInfo('开启' + name + '监测线程');
let _args = [].slice.call(arguments);
return _thd = threadsx.start(new java.lang.Runnable({
run: () => thr_f.apply(global, _args),
}));
return _thd = threadsx.start(() => thr_f.apply(global, _args));
};
this.interrupt = function () {
if (_thd && !this.disabled) {
Expand Down Expand Up @@ -4291,7 +4287,7 @@ let $$init = {
let _aim = Array.from(arguments, s => s.toLowerCase());
_aim = _aim.length ? _aim : ['alipay', 'app'];
_aim.includes('alipay') && $$app.page.alipay.close();
_aim.includes('app') && $$app.exit(true);
_aim.includes('app') && ui.post(exit);
}
}
},
Expand Down Expand Up @@ -5427,9 +5423,13 @@ let $$af = {
// tool function(s) //

function _title() {
let _tt;
waitForAction(() => _tt = $$sel.get('fri_tt', 'txt'), 18e3, 80);
$$af.nick = _tt ? _tt.replace(/的蚂蚁森林$/, '') : '';
let _title = '';
let _ctr = 0;
waitForAction(() => {
_ctr++ % 25 || $$a11y.service.refreshServiceInfo();
return _title = $$sel.get('fri_tt', 'txt') || '';
}, 18e3, 80);
$$af.nick = _title.replace(/的蚂蚁森林$/, '');
}

function _intro() {
Expand Down Expand Up @@ -5607,13 +5607,15 @@ let $$af = {
let _txt_cvr = $$sel.pickup(_w_cvr, 'txt');
let _date_str = '';
void _w_lst.children().some((child) => {
if (child.childCount()) {
return (
$$sel.pickup([child, 'c1>1'], 'txt') ||
$$sel.pickup([child, 'c0>1'], 'txt')
) === _txt_cvr;
if (child !== null /* mystical */) {
if (child.childCount()) {
return (
$$sel.pickup([child, 'c1>1'], 'txt') ||
$$sel.pickup([child, 'c0>1'], 'txt')
) === _txt_cvr;
}
_date_str = $$sel.pickup(child, 'txt');
}
_date_str = $$sel.pickup(child, 'txt');
});
return _date_str;
}
Expand Down Expand Up @@ -5920,7 +5922,7 @@ let $$af = {
this.ready() && this.stable() && this.stat();
},
};
return new java.lang.Runnable({run: _maker.fx.bind(_maker)});
return _maker.fx.bind(_maker);
}
}
}
Expand Down Expand Up @@ -6818,6 +6820,7 @@ let $$af = {
let _1st = 1;

do {
$$impeded('排行榜控件滚动流程');
_1st ? _1st &= 0 : sleep(_itv);
let _ls = scrollable(true).findOnce();
_ls ? _ls.scrollDown() : debugInfo$('scrollable(): null', 3);
Expand Down
6 changes: 3 additions & 3 deletions ant-forest-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ let $$init = {
if (!$$arr(_content)) {
_content = [_content];
}
if ($$und(_content[1]) || !!_content[1]) {
if ($$und(_content[1]) || _content[1]) {
_content[1] =
'有效值: ' + _mini + ' [ ' + _mini_p + ' ] ' +
' - ' + _maxi + ' [ ' + _maxi_p + ' ]\n' +
Expand Down Expand Up @@ -2715,7 +2715,7 @@ let $$init = {
let _sess_sel_idx = $$und(_show_zero) ? $$cfg.ses.stat_list_show_zero : _show_zero;
dialogsx
.builds([
'收取值筛选', '', ['R', 'hint'], 'B', 'K', 1,
'收取值筛选', '', ['设为默认值', 'hint'], 'B', 'K', 1,
], {
items: _getItems($$sto.af_cfg.get('config', {}).stat_list_show_zero),
itemsSelectMode: 'single',
Expand Down Expand Up @@ -2748,7 +2748,7 @@ let $$init = {
let _sess_sel_idx = $$und(_range) ? $$cfg.ses.stat_list_date_range : _range;
let _posFunc = d => _posDefault(d);
let _diag = dialogsx.builds([
'日期统计范围', '', ['R', 'hint'], 'B', 'K', 1,
'日期统计范围', '', ['设为默认值', 'hint'], 'B', 'K', 1,
], {
items: $$view.getStatPageItems({
def: $$sto.af_cfg.get('config', {}).stat_list_date_range,
Expand Down
9 changes: 9 additions & 0 deletions documents/CHANGELOG-2.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
### 版本历史 - 2.x
******

# v2.1.10
###### 2021/08/22
* `修复` 获取能量罩信息时可能出现空指针的问题
* `修复` 闹钟间隔事件监测代码异常导致脚本终止的问题
* `修复` $$cvt对0到1之间的输入数据返回值为空的问题
* `优化` threadsx.start()支持箭头函数及绑定函数
* `优化` Pro版本增加对话框按钮自定义颜色设置的支持
* `优化` Pro版本移除获取控件信息对currentPackage()的依赖

# v2.1.9
###### 2021/08/20
* `修复` 配置工具无法设置排行榜滑动距离等相关配置项的问题
Expand Down
58 changes: 35 additions & 23 deletions modules/ext-a11y.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ let Secure = Settings.Secure;

let UiSelector = com.stardust.autojs.core.accessibility.UiSelector;
let AccessibilityService = com.stardust.autojs.core.accessibility.AccessibilityService;
let AccessibilityWindowInfo = android.view.accessibility.AccessibilityWindowInfo;

let ctx_reso = context.getContentResolver();
let autojs_a11y_svc_name = context.getPackageName() + '/' +
Expand Down Expand Up @@ -52,45 +53,56 @@ let ext = {
},
bridge: {
/**
* @param {android.view.accessibility.AccessibilityWindowInfo} wi
* @returns {boolean}
*/
_isLatestPackage(wi) {
return wi.getRoot().getPackageName() === runtime.info.getLatestPackage();
},
/**
* @param {
* function(info:android.view.accessibility.AccessibilityWindowInfo):boolean
* } filter
* @param {function(info:android.view.accessibility.AccessibilityWindowInfo):boolean} filter
*/
setWindowFilter(filter) {
auto.setWindowFilter(function (wi) {
try {
return filter(wi);
} catch (e) {
// eg: TypeError: Cannot call method "getPackageName" of null
return false;
}
});
},
/** @param {string[]} blacklist */
setWindowBlacklist(blacklist) {
this.setWindowFilter(wi => this._isLatestPackage(wi)
&& !~blacklist.indexOf(wi.getRoot().getPackageName()));
/** @param {string[]} pkg_blist */
setWindowBlacklist(pkg_blist) {
this.setWindowFilter(wi => pkg_blist.indexOf(wi.getRoot().getPackageName()) < 0);
},
/** @param {string[]} whitelist */
setWindowWhitelist(whitelist) {
this.setWindowFilter(wi => this._isLatestPackage(wi)
&& !!~whitelist.indexOf(wi.getRoot().getPackageName()));
/** @param {string[]} pkg_wlist */
setWindowWhitelist(pkg_wlist) {
this.setWindowFilter(wi => pkg_wlist.indexOf(wi.getRoot().getPackageName()) > -1);
},
setWindowAllowAll() {
this.setWindowFilter(() => true);
},
resetWindowFilter() {
this.setWindowFilter((wi) => {
return devicex.isLocked() || this._isLatestPackage(wi);
return this.isWindowType(wi, 'APPLICATION')
|| this.isWindowType(wi, 'SYSTEM') && wi.isActive();
});
},
/**
* @param {android.view.accessibility.AccessibilityWindowInfo} wi
* @param {'APPLICATION'|'INPUT_METHOD'|'SYSTEM'|'ACCESSIBILITY_OVERLAY'|'SPLIT_SCREEN_DIVIDER'|number} type
* @returns {boolean}
*/
isWindowType(wi, type) {
if (typeof type === 'number') {
return type === wi.getType();
}
let _types = {
APPLICATION: 0x1,
INPUT_METHOD: 0x2,
SYSTEM: 0x3,
ACCESSIBILITY_OVERLAY: 0x4,
SPLIT_SCREEN_DIVIDER: 0x5,
};
let _type = String(type).toUpperCase();
if (!(_type in _types)) {
throw TypeError('Unknown type of "type" for isWindowType()');
}
return AccessibilityWindowInfo['TYPE_' + _type] === wi.getType();
},
},
service: {
refreshServiceInfo() {
Expand Down Expand Up @@ -398,7 +410,7 @@ let ext = {
* @returns {boolean}
*/
function _isArrResType(type) {
return !!type.match(/^(widgets|points)$/);
return /^(widgets|points)$/.test(type);
}

/**
Expand Down Expand Up @@ -518,9 +530,9 @@ let ext = {
* @returns {number}
*/
function _getTxtLen(w) {
let _text = w && w.findOnce();
let _text = w instanceof UiSelector ? w.findOnce() : null;
_text = _text === null ? '' : _text.text() || '';
let _desc = w && w.findOnce();
let _desc = w instanceof UiSelector ? w.findOnce() : null;
_desc = _desc === null ? '' : _desc.desc() || '';
return Math.max(_desc.length, _text.length);
}
Expand Down
2 changes: 1 addition & 1 deletion modules/ext-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ let ext = {
* @returns {boolean}
*/
isAutoJsPro() {
return (this.isAutoJsPro = () => !!this.getAutoJsPkgName().match(/pro/))();
return (this.isAutoJsPro = () => /pro/.test(this.getAutoJsPkgName()))();
},
/**
* @example
Expand Down
Loading

0 comments on commit 2c8c4a3

Please sign in to comment.