diff --git a/Ant_Forest_Launcher.js b/Ant_Forest_Launcher.js index 6ec74a7..41fd012 100644 --- a/Ant_Forest_Launcher.js +++ b/Ant_Forest_Launcher.js @@ -1,8 +1,8 @@ /** * @overview alipay ant forest energy intelligent collection script * - * @last_modified Nov 23, 2019 - * @version 1.9.8 Alpha + * @last_modified Nov 24, 2019 + * @version 1.9.8 * @author SuperMonster003 * * @tutorial {@link https://github.com/SuperMonster003/Auto.js_Projects/tree/Ant_Forest} @@ -22,11 +22,12 @@ checkModulesMap([ "MODULE_UNLOCK", ]); -// given that there are bugs with dialogs modules in old auto.js versions like 4.1.0/5 and 4.1.1/2 +// given that there are bugs with dialogs modules +// in auto.js versions like 4.1.0/5 and 4.1.1/2 // in another way, dialogs.builds() could make things easier sometimes let dialogs = require("./Modules/__dialogs__pro_v6")(runtime, __global__); -// better compatibility for both free version and pro version +// better compatibility for both free and pro versions let timers = require("./Modules/__timers__pro_v37")(runtime, __global__); // more functions offered by Stardust and some others by myself diff --git a/Ant_Forest_Settings.js b/Ant_Forest_Settings.js index 3c24698..752e44b 100644 --- a/Ant_Forest_Settings.js +++ b/Ant_Forest_Settings.js @@ -1,6 +1,20 @@ -"ui"; -auto(); // auto.waitFor() was abandoned here, as it may cause problems sometimes +"ui"; // indicate a ui mode and defined __global__.activity +// window mostly for browser, global mostly for Node.js, and __global__ for Auto.js +__global__ = typeof __global__ === "undefined" ? this : __global__; + +// not necessary [ˈsɛksi] and i know it +let {auto, threads, events, files, runtime, activity, android, ui, java} = __global__; + +// script will not go on without a normal state of accessibility service +// auto.waitFor() was abandoned here, as it may cause problems sometimes +auto(); + +// set up the device screen in a portrait orientation +activity.setRequestedOrientation(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); + +// friendly error message will be shown in console +// if one of these specified modules was not able to locate checkModulesMap([ "__dialogs__pro_v6", "__timers__pro_v37", @@ -11,26 +25,25 @@ checkModulesMap([ "MODULE_TREASURY_VAULT", ]); -// set up the device screen in a portrait orientation -activity.setRequestedOrientation(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); - -// window mostly for browser, global mostly for Node.js, and __global__ for Auto.js -__global__ = typeof __global__ === "undefined" ? this : __global__; - -// better compatibility for both free version and pro version +// better compatibility for both free and pro versions let timers = require("./Modules/__timers__pro_v37")(runtime, __global__); -// given that there are bugs with dialogs modules in old auto.js versions like 4.1.0/5 and 4.1.1/2 +// given that there are bugs with dialogs modules +// in auto.js versions like 4.1.0/5 and 4.1.1/2 // in another way, dialogs.builds() could make things easier sometimes let dialogs = require("./Modules/__dialogs__pro_v6")(runtime, __global__); -threads.starts = (f, error_msg_consume_flag) => { - try { - return threads.start(f); - } catch (e) { - if (!e.message.match(/script exiting/) && !error_msg_consume_flag) throw Error(e); +// prevent script exiting error from showing up +// (both console and toast window) if threads were interrupted +Object.assign(threads, { + starts: (f, error_msg_consume_flag) => { + try { + return threads.start(f); + } catch (e) { + if (!e.message.match(/script exiting/) && !error_msg_consume_flag) throw Error(e); + } } -}; +}); let { getDisplayParams, @@ -57,6 +70,7 @@ let dynamic_views = []; let rolling_pages = []; let sub_page_views = []; let def = undefined; +let page_buttons = getPageButtons(); let {WIDTH, HEIGHT, USABLE_HEIGHT, cX, cY, status_bar_height, action_bar_default_height, navigation_bar_height} = getDisplayParams(); let {DEFAULT_AF, DEFAULT_UNLOCK, DEFAULT_SETTINGS} = getDefaultConfigParams(); @@ -170,6 +184,49 @@ let list_heads = { ], }; +let pages_tree = { + self_collect_page: { + homepage_monitor_page: null, + homepage_background_monitor_page: null, + }, + friend_collect_page: { + rank_list_samples_collect_page: { + rank_list_auto_expand_page: null, + rank_list_review_page: null + }, + }, + help_collect_page: { + six_balls_review_page: null, + rank_list_samples_collect_page: null, + }, + auto_unlock_page: null, + message_showing_page: null, + timers_page: { + homepage_monitor_page: null, + rank_list_review_page: null, + timers_self_manage_page: { + timers_uninterrupted_check_sections_page: null, + }, + timers_control_panel_page: null, + }, + account_page: { + account_log_back_in_page: null, + }, + blacklist_page: { + cover_blacklist_page: null, + self_def_blacklist_page: null, + foreground_app_blacklist_page: null, + }, + script_security_page: { + kill_when_done_page: null, + phone_call_state_monitor_page: null, + }, + local_project_backup_restore_page: { + restore_projects_from_local_page: null, + restore_projects_from_server_page: null, + }, +}; + // entrance // initUI(); @@ -602,12 +659,14 @@ let homepage = setHomePage(defs.homepage_title) view._hint.text(current_local_version_name); }, })) + .ready() ; -let addPage = addFunc => sub_page_views.push(addFunc); +let pages_buffer_obj = {}; +let addPage = (page_name, addFunc) => pages_buffer_obj[page_name] = addFunc; -addPage(() => { - setPage(["自收功能", "self_collect_page"]) +addPage("self_collect_page", (name) => { + setPage(["自收功能", name]) .add("switch", new Layout("总开关", { config_conj: "self_collect_switch", listeners: { @@ -709,9 +768,9 @@ addPage(() => { }, })) .ready(); -}); // self_collect_page -addPage(() => { - setPage(["主页能量球循环监测", "homepage_monitor_page"]) +}); +addPage("homepage_monitor_page", (name) => { + setPage(["主页能量球循环监测", name]) .add("switch", new Layout("总开关", { config_conj: "homepage_monitor_switch", listeners: { @@ -757,9 +816,9 @@ addPage(() => { .add("split_line") .add("info", new Layout("\"自收功能\"与\"定时循环\"共用此页面配置")) .ready(); -}); // homepage_monitor_page -addPage(() => { - setPage(["主页能量球返检监控", "homepage_background_monitor_page"]) +}); +addPage("homepage_background_monitor_page", (name) => { + setPage(["主页能量球返检监控"]) .add("switch", new Layout("总开关", { config_conj: "homepage_background_monitor_switch", listeners: { @@ -788,9 +847,9 @@ addPage(() => { }, })) .ready(); -}); // homepage_background_monitor_page -addPage(() => { - setPage(["收取功能", "friend_collect_page"]) +}); +addPage("friend_collect_page", (name) => { + setPage(["收取功能", name]) .add("switch", new Layout("总开关", { config_conj: "friend_collect_switch", listeners: { @@ -912,9 +971,9 @@ addPage(() => { }, })) .ready(); -}); // friend_collect_page -addPage(() => { - setPage(["排行榜样本采集", "rank_list_samples_collect_page"]) +}); +addPage("rank_list_samples_collect_page", (name) => { + setPage(["排行榜样本采集", name]) .add("sub_head", new Layout("基本设置")) .add("button", new Layout("滑动距离", { config_conj: "rank_list_swipe_distance", @@ -1167,9 +1226,9 @@ addPage(() => { }, })) .ready(); -}); // rank_list_samples_collect_page -addPage(() => { - setPage(["排行榜列表自动展开", "rank_list_auto_expand_page"]) +}); +addPage("rank_list_auto_expand_page", (name) => { + setPage(["排行榜列表自动展开", name]) .add("switch", new Layout("总开关", { config_conj: "rank_list_auto_expand_switch", listeners: { @@ -1213,9 +1272,9 @@ addPage(() => { }, })) .ready(); -}); // rank_list_auto_expand_page -addPage(() => { - setPage(["排行榜样本复查", "rank_list_review_page"], def, def, { +}); +addPage("rank_list_review_page", (name) => { + setPage(["排行榜样本复查", name], def, def, { check_page_state: (view) => { let samples = [ "rank_list_review_threshold_switch", @@ -1314,9 +1373,9 @@ addPage(() => { .add("split_line") .add("info", new Layout("\"收取\/帮收功能\"与\"定时循环\"共用此页面配置")) .ready(); -}); // rank_list_review_page -addPage(() => { - setPage(["帮收功能", "help_collect_page"]) +}); +addPage("help_collect_page", (name) => { + setPage(["帮收功能", name]) .add("switch", new Layout("总开关", { config_conj: "help_collect_switch", listeners: { @@ -1583,9 +1642,9 @@ addPage(() => { }, })) .ready(); -}); // help_collect_page -addPage(() => { - setPage(["六球复查", "six_balls_review_page"]) +}); +addPage("six_balls_review_page", (name) => { + setPage(["六球复查", name]) .add("switch", new Layout("总开关", { config_conj: "six_balls_review_switch", listeners: { @@ -1638,9 +1697,9 @@ addPage(() => { }, })) .ready(); -}); // six_balls_review_page -addPage(() => { - setPage(["自动解锁", "auto_unlock_page"]) +}); +addPage("auto_unlock_page", (name) => { + setPage(["自动解锁", name]) .add("switch", new Layout("总开关", { config_conj: "auto_unlock_switch", listeners: { @@ -1912,9 +1971,9 @@ addPage(() => { }, })) .ready(); -}); // auto_unlock_page -addPage(() => { - setPage(["消息提示", "message_showing_page"]) +}); +addPage("message_showing_page", (name) => { + setPage(["消息提示", name]) .add("switch", new Layout("总开关", { config_conj: "message_showing_switch", listeners: { @@ -2104,9 +2163,9 @@ addPage(() => { }, })) .ready(); -}); // message_showing_page -addPage(() => { - setPage(["定时循环", "timers_page"], def, def, { +}); +addPage("timers_page", (name) => { + setPage(["定时循环", name], def, def, { check_page_state: (view) => { // this is just a simple check let switches = [ @@ -2169,9 +2228,9 @@ addPage(() => { next_page: "timers_control_panel_page", })) .ready(); -}); // timers_page -addPage(() => { - setPage(["定时任务自动管理", "timers_self_manage_page"], def, def, { +}); +addPage("timers_self_manage_page", (name) => { + setPage(["定时任务自动管理", name], def, def, { check_page_state: (view) => { return checkCurrentPageSwitches() && checkAutoUnlockSwitch(); @@ -2481,9 +2540,9 @@ addPage(() => { }, })) .ready(); -}); // timers_self_manage_page -addPage(() => { - setPage(["定时任务控制面板", "timers_control_panel_page"], def, parent_view => setTimersControlPanelPageButtons(parent_view, "timed_tasks", wizardFunc), {no_margin_bottom: true, no_scroll_view: true}) +}); +addPage("timers_control_panel_page", (name) => { + setPage(["定时任务控制面板", name], def, parent_view => setTimersControlPanelPageButtons(parent_view, "timed_tasks", wizardFunc), {no_margin_bottom: true, no_scroll_view: true}) .add("list", new Layout("/*管理本项目定时任务*/", { list_head: list_heads.timed_tasks, data_source_key_name: "timed_tasks", @@ -2784,9 +2843,9 @@ addPage(() => { }); } } -}); // timers_control_panel_page -addPage(() => { - setPage(["延时接力管理", "timers_uninterrupted_check_sections_page"], def, parent_view => setTimersUninterruptedCheckAreasPageButtons(parent_view, "timers_uninterrupted_check_sections"), {no_margin_bottom: true, no_scroll_view: true}) +}); +addPage("timers_uninterrupted_check_sections_page", (name) => { + setPage(["延时接力管理", name], def, parent_view => setTimersUninterruptedCheckAreasPageButtons(parent_view, "timers_uninterrupted_check_sections"), {no_margin_bottom: true, no_scroll_view: true}) .add("list", new Layout("/*延时接力时间区间*/", { list_head: list_heads.timers_uninterrupted_check_sections, data_source_key_name: "timers_uninterrupted_check_sections", @@ -2947,9 +3006,9 @@ addPage(() => { }, })) .ready(); -}); // timers_uninterrupted_check_sections_page -addPage(() => { - setPage(["账户功能", "account_page"], def, def, { +}); +addPage("account_page", (name) => { + setPage(["账户功能", name], def, def, { check_page_state: (view) => { let {main_account_info} = session_config; if (!view._switch.checked) return true; @@ -3194,9 +3253,9 @@ addPage(() => { }, })) .ready(); -}); // account_page -addPage(() => { - setPage(["旧账户回切", "account_log_back_in_page"]) +}); +addPage("account_log_back_in_page", (name) => { + setPage(["旧账户回切", name]) .add("switch", new Layout("总开关", { config_conj: "account_log_back_in_switch", listeners: { @@ -3242,9 +3301,9 @@ addPage(() => { }, })) .ready(); -}); // account_log_back_in_page -addPage(() => { - setPage(["黑名单管理", "blacklist_page"]) +}); +addPage("blacklist_page", (name) => { + setPage(["黑名单管理", name]) .add("sub_head", new Layout("蚂蚁森林名单簿", {sub_head_color: defs.sub_head_highlight_color})) .add("options", new Layout("能量罩黑名单", { hint: "加载中...", @@ -3287,9 +3346,9 @@ addPage(() => { }, })) .ready(); -}); // blacklist_page -addPage(() => { - setPage(["能量罩黑名单", "cover_blacklist_page"], def, def, {no_margin_bottom: true, no_scroll_view: true}) +}); +addPage("cover_blacklist_page", (name) => { + setPage(["能量罩黑名单", name], def, def, {no_margin_bottom: true, no_scroll_view: true}) .add("list", new Layout("/*能量罩黑名单成员*/", { list_head: list_heads.blacklist_protect_cover, data_source_key_name: "blacklist_protect_cover", @@ -3304,9 +3363,9 @@ addPage(() => { })) .add("info", new Layout("能量罩黑名单由脚本自动管理")) .ready(); -}); // cover_blacklist_page -addPage(() => { - setPage(["自定义黑名单", "self_def_blacklist_page"], def, parent_view => setListPageButtons(parent_view, "blacklist_by_user"), {no_margin_bottom: true, no_scroll_view: true}) +}); +addPage("self_def_blacklist_page", (name) => { + setPage(["自定义黑名单", name], def, parent_view => setListPageButtons(parent_view, "blacklist_by_user"), {no_margin_bottom: true, no_scroll_view: true}) .add("list", new Layout("/*自定义黑名单成员*/", { list_head: list_heads.blacklist_by_user, data_source_key_name: "blacklist_by_user", @@ -3464,9 +3523,9 @@ addPage(() => { }, })) .ready(); -}); // self_def_blacklist_page -addPage(() => { - setPage(["前置应用黑名单", "foreground_app_blacklist_page"], def, parent_view => setListPageButtons(parent_view, "foreground_app_blacklist"), {no_margin_bottom: true, no_scroll_view: true}) +}); +addPage("foreground_app_blacklist_page", (name) => { + setPage(["前置应用黑名单", name], def, parent_view => setListPageButtons(parent_view, "foreground_app_blacklist"), {no_margin_bottom: true, no_scroll_view: true}) .add("list", new Layout("/*前置应用黑名单项目*/", { list_head: list_heads.foreground_app_blacklist, data_source_key_name: "foreground_app_blacklist", @@ -3535,9 +3594,9 @@ addPage(() => { }, })) .ready(); -}); // foreground_app_blacklist_page -addPage(() => { - setPage(["运行与安全", "script_security_page"]) +}); +addPage("script_security_page", (name) => { + setPage(["运行与安全", name]) .add("sub_head", new Layout("基本设置")) .add("button", new Layout("运行失败自动重试", { config_conj: "max_retry_times_global", @@ -3696,9 +3755,9 @@ addPage(() => { }, })) .ready(); -}); // script_security_page -addPage(() => { - setPage(["支付宝应用及页面保留", "kill_when_done_page"]) +}); +addPage("kill_when_done_page", (name) => { + setPage(["支付宝应用及页面保留", name]) .add("switch", new Layout("总开关", { config_conj: "kill_when_done_switch", listeners: { @@ -3764,9 +3823,9 @@ addPage(() => { }, })) .ready(); -}); // kill_when_done_page -addPage(() => { - setPage(["通话状态监测", "phone_call_state_monitor_page"]) +}); +addPage("phone_call_state_monitor_page", (name) => { + setPage(["通话状态监测", name]) .add("switch", new Layout("总开关", { config_conj: "phone_call_state_monitor_switch", listeners: { @@ -3827,9 +3886,9 @@ addPage(() => { }, })) .ready(); -}); // phone_call_state_monitor_page -addPage(() => { - setPage(["项目备份还原", "local_project_backup_restore_page"]) +}); +addPage("local_project_backup_restore_page", (name) => { + setPage(["项目备份还原", name]) .add("sub_head", new Layout("备份", {sub_head_color: defs.sub_head_highlight_color})) .add("button", new Layout("备份至本地", { newWindow: function () { @@ -3876,8 +3935,8 @@ addPage(() => { .add("sub_head", new Layout("还原", {sub_head_color: defs.sub_head_highlight_color})) .add("options", new Layout("从本地还原", { hint: "加载中...", - view_label: "restore_projects_from_local", - next_page: "restore_projects_from_local", + view_label: "restore_projects_from_local_page", + next_page: "restore_projects_from_local_page", updateOpr: function (view) { let amount = session_config.project_backup_info.length; view._hint.text(amount ? "共计备份: " + amount + " 项" : "无备份"); @@ -3886,19 +3945,19 @@ addPage(() => { .add("options", new Layout("从服务器还原", { hint: "加载中...", next_page: null, - view_label: "restore_projects_from_server", + view_label: "restore_projects_from_server_page", updateOpr: function (view) { let view_label = this.view_label; let clearClickListener = () => view.setClickListener(() => null); let restoreClickListener = () => { - session_params.restore_projects_from_server_updated_flag = false; + session_params.restore_projects_from_server_page_updated_flag = false; view.setClickListener(() => updateViewByLabel(view_label)); }; - if (session_params.restore_projects_from_server_updated_flag) return; + if (session_params.restore_projects_from_server_page_updated_flag) return; view._chevron_btn.setVisibility(8); view._hint.text("正在从服务器获取数据..."); clearClickListener(); - session_params.restore_projects_from_server_updated_flag = true; + session_params.restore_projects_from_server_page_updated_flag = true; threads.starts(function () { let setViewText = text => ui.post(() => view._hint.text(text)); let max_try_times = 5; @@ -3911,7 +3970,7 @@ addPage(() => { restoreClickListener(); return setViewText("无备份 (点击可重新检查)"); } - view.setNextPage("restore_projects_from_server"); + view.setNextPage("restore_projects_from_server_page"); ui.post(() => view._chevron_btn.setVisibility(0)); view.restoreClickListener(); setViewText("共计备份: " + amount + " 项"); @@ -3999,9 +4058,9 @@ addPage(() => { }, })) .ready(); -}); // local_project_backup_restore_page -addPage(() => { - setPage(["从本地还原项目", "restore_projects_from_local"], def, def, {no_margin_bottom: true, no_scroll_view: true}) +}); +addPage("restore_projects_from_local_page", (name) => { + setPage(["从本地还原项目", name], def, def, {no_margin_bottom: true, no_scroll_view: true}) .add("list", new Layout("/*本地项目还原*/", { list_head: list_heads.project_backup_info, data_source_key_name: "project_backup_info", @@ -4024,7 +4083,7 @@ addPage(() => { let {data_source_key_name} = this; updateDataSource(data_source_key_name, "splice", [idx, 1], "quiet"); - updateViewByLabel("restore_projects_from_local"); + updateViewByLabel("restore_projects_from_local_page"); // write to storage right away storage_af.put(data_source_key_name, storage_config[data_source_key_name] = deepCloneObject(session_config[data_source_key_name])); @@ -4088,23 +4147,25 @@ addPage(() => { }, })) .add("info", new Layout("dynamic_info", { - view_label: "restore_projects_from_local", + view_label: "restore_projects_from_local_page", updateOpr: function (view) { view._info_text.setText(session_config.project_backup_info.length ? "点击列表项可还原项目或删除备份项目" : "暂无备份项目"); }, })) .add("info", new Layout("长按列表项可删除备份项目", { - view_label: "restore_projects_from_local", + view_label: "restore_projects_from_local_page", updateOpr: function (view) { view.setVisibility(session_config.project_backup_info.length ? 0 : 8); }, })) .ready(); -}); // restore_projects_from_local -addPage(() => { - setPage(["从服务器还原项目", "restore_projects_from_server"], def, def, {no_margin_bottom: true, no_scroll_view: true}) +}); +addPage("restore_projects_from_server_page", (name) => { + setPage(["从服务器还原项目", name], def, def, {no_margin_bottom: true, no_scroll_view: true}) .ready(); -}); // restore_projects_from_server +}); + +flushPagesBuffer(pages_buffer_obj, pages_tree); ui.emitter.on("back_pressed", e => { if (session_params.back_btn_consumed) { @@ -4163,17 +4224,40 @@ events.on("exit", () => { ui.main.removeAllViews(); ui.finish(); }); -listener.emit("sub_page_views_add"); -setTimeout(function () { +// layout function(s) // + +function flushPagesBuffer(pages, tree) { + let _pages_buffer = []; + let _pages_buffered_name = {}; + pickupPage(pages, tree); + _pages_buffer.forEach(o => sub_page_views.push(() => o.addFunc(o.page_name))); + + listener.emit("sub_page_views_add"); + let interval_add_sub_page = setInterval(function () { session_params.sub_page_view_idx < sub_page_views.length ? listener.emit("sub_page_views_add") : clearInterval(interval_add_sub_page); }, 50); -}, 3000); -// layout function(s) // + // tool function(s) // + + function pickupPage(pages, tree) { + let sub_trees = []; + let keys = Object.keys(tree); + for (let i = 0, len = keys.length; i < len; i += 1) { + let key = keys[i]; + if (key in pages && !(key in _pages_buffered_name)) { + _pages_buffer.push({page_name: key, addFunc: pages[key]}); + _pages_buffered_name[key] = true; + } + let sub_tree = (tree[key]); + if (classof(sub_tree, "Object")) sub_trees.push(sub_tree); + } + if (sub_trees.length) sub_trees.forEach(sub_tree => pickupPage(pages, sub_tree)); + } +} function setListPageButtons(parent_view, data_source_key_name) { let scenarios = { @@ -5585,92 +5669,102 @@ function initUI(status_bar_color) { } function setHomePage(home_title, title_bg_color) { - let homepage = setPage(home_title, title_bg_color, parent_view => setButtons(parent_view, "homepage", - ["save", "SAVE", "OFF", (btn_view) => { - if (!needSave()) return; - saveNow(); - btn_view.switch_off(); - toast("已保存"); - }] - )); + let _homepage = setPage(home_title, title_bg_color, page_buttons.homepage); + + _homepage.ready = function () { + ui.main.getParent().addView(_homepage); + _homepage._back_btn_area.setVisibility(8); + rolling_pages[0] = _homepage; //// PENDING //// + }; - ui.main.getParent().addView(homepage); - homepage._back_btn_area.setVisibility(8); - rolling_pages[0] = homepage; - return homepage; + return _homepage; +} + +function getPageButtons() { + return { + homepage: function (parent_view) { + return setButtons(parent_view, "homepage", + ["save", "SAVE", "OFF", (btn_view) => { + if (needSave()) { + saveNow(); + btn_view.switch_off(); + toast("已保存"); + } + }] + ); + } + }; } function setPage(title_param, title_bg_color, additions, options) { - let {no_margin_bottom, no_scroll_view, check_page_state} = options || {}; - let title = title_param; - let view_page_name = ""; - if (classof(title_param, "Array")) [title, view_page_name] = title_param; - session_params.page_title = title; title_bg_color = title_bg_color || defs["title_bg_color"]; - let new_view = ui.inflate(); - new_view.addView(ui.inflate( - - - - - - - - - )); - new_view._back_btn_area.on("click", () => checkPageState() && pageJump("back")); - new_view._title_text.text(title); - new_view._title_text.getPaint().setFakeBoldText(true); - let title_bg = typeof title_bg_color === "string" ? colors.parseColor(title_bg_color) : title_bg_color; - new_view._title_bg.setBackgroundColor(title_bg); + let {no_margin_bottom, no_scroll_view, check_page_state} = options || {}; + let [page_title_name, page_label_name] = classof(title_param, "Array") ? title_param : [title_param, ""]; + + let page_view = ui.inflate(); + page_view.addView(ui.inflate( + + + + + + + + )); + page_view._back_btn_area.on("click", () => checkPageState() && pageJump("back")); + page_view._title_text.text(page_title_name); + page_view._title_text.getPaint().setFakeBoldText(true); - if (additions) typeof additions === "function" ? additions(new_view) : additions.forEach(f => f(new_view)); + let title_bg = typeof title_bg_color === "string" ? colors.parseColor(title_bg_color) : title_bg_color; + page_view._title_bg.setBackgroundColor(title_bg); + + if (additions) typeof additions === "function" ? additions(page_view) : additions.forEach(f => f(page_view)); + + page_view.addView(no_scroll_view + ? ui.inflate( + + ) + : ui.inflate( + + )); + + no_margin_bottom || page_view._page_content_view.addView( + ui.inflate( + + ) + ); - if (!no_scroll_view) { - new_view.addView(ui.inflate( - - - - )); - } else { - new_view.addView(ui.inflate( - - - - )); - } - if (!no_margin_bottom) { - new_view._page_content_view.addView(ui.inflate( - - - - )); - } - new_view.add = (type, item_params) => { + page_view.add = (type, item_params) => { let sub_view = setItem(type, item_params); - new_view._page_content_view.addView(sub_view); - if (sub_view.updateOpr) dynamic_views.push(sub_view); - return new_view; + page_view._page_content_view.addView(sub_view); + let {updateOpr} = sub_view; + if (updateOpr) { + updateOpr.bind(sub_view)(sub_view); + dynamic_views.push(sub_view); + } + return page_view; }; - if (view_page_name) { - view_pages[view_page_name] = new_view; - new_view.setTag(view_page_name); - } - - new_view.ready = () => { - session_params["ready_signal_" + view_page_name] = true; - listener.emit("sub_page_views_add"); - updateAllValues("only_new"); + page_view.ready = () => { + session_params["ready_signal_" + page_label_name] = true; + // listener.emit("sub_page_views_add"); + // updateAllValues("only_new"); }; - new_view.checkPageState = () => { + page_view.checkPageState = () => { if (typeof check_page_state === "boolean") return check_page_state; - if (typeof check_page_state === "function") return check_page_state(new_view); + if (typeof check_page_state === "function") return check_page_state(page_view); return true; }; - return new_view; + page_view.page_name = page_view.page_title_name = page_title_name; + if (page_label_name) { + page_view.label_name = page_view.page_label_name = page_label_name; + view_pages[page_label_name] = page_view; + page_view.setTag(page_label_name); + } + + return page_view; // tool function(s) // @@ -5759,7 +5853,6 @@ function setPage(title_param, title_bg_color, additions, options) { }); }); } else if (type.match(/^options/)) { - let is_lazy = type.match(/lazy/); let opt_view = ui.inflate( @@ -5773,19 +5866,20 @@ function setPage(title_param, title_bg_color, additions, options) { new_view._item_area.on("click", listener); }; new_view.restoreClickListener = () => new_view.setClickListener(() => { - if (__global__._monster_$_page_scrolling_flag) return; let next_page = item_params.next_page; if (next_page && view_pages[next_page]) pageJump("next", next_page); }); - is_lazy ? (new_view.setClickListener(), new_view._chevron_btn.setVisibility(8)) : new_view.restoreClickListener(); - threads.starts(function () { - if (waitForAction(() => session_params["ready_signal_" + item_params.next_page], 8000)) { + new_view.setClickListener(); + new_view._chevron_btn.setVisibility(8); + let sub_page_ready_interval = setInterval(function () { + if (session_params["ready_signal_" + item_params.next_page]) { ui.post(() => { new_view.restoreClickListener(); new_view._chevron_btn.setVisibility(0); }); + clearInterval(sub_page_ready_interval); } - }); + }, 200); } else if (type === "button") { let help_view = ui.inflate( @@ -6039,16 +6133,13 @@ function setPage(title_param, title_bg_color, additions, options) { } function setButtons(parent_view, data_source_key_name, button_params_arr) { - let buttons_view = ui.inflate(); let buttons_count = 0; for (let i = 2, len = arguments.length; i < len; i += 1) { let arg = arguments[i]; if (typeof arg !== "object") continue; // just in case - buttons_view.btn.addView(getButtonLayout.apply(null, arg)); + parent_view._title_btn.addView(getButtonLayout.apply(null, arg)); buttons_count += 1; } - parent_view._title_text.setWidth(~~((650 - 100 * buttons_count - (session_params.page_title !== defs.homepage_title ? 52 : 5)) * WIDTH / 720)); - parent_view._title_bg.addView(buttons_view); // tool function(s) // @@ -6086,7 +6177,7 @@ function setButtons(parent_view, data_source_key_name, button_params_arr) { function buttonView() { return ui.inflate( - + @@ -6097,6 +6188,10 @@ function setButtons(parent_view, data_source_key_name, button_params_arr) { function pageJump(direction, next_page) { if (__global__._monster_$_page_scrolling_flag) return; + + // necessary so far + if (next_page === (rolling_pages[rolling_pages.length - 1] || {}).label_name) return; + if (direction.match(/back|previous|last/)) { smoothScrollView("full_right", null, rolling_pages); return rolling_pages.pop(); @@ -6448,7 +6543,7 @@ function backupProjectFiles(local_backup_path, version_name, dialog, auto_flag) timestamp: now.getTime(), remark: auto_flag ? "自动备份" : (session_params["project_backup_info_remark"] || "手动备份"), }, "quiet"); - updateViewByLabel("restore_projects_from_local"); + updateViewByLabel("restore_projects_from_local_page"); // write to storage right away storage_af.put(data_source_key_name, storage_config[data_source_key_name] = deepCloneObject(session_config[data_source_key_name])); @@ -6866,10 +6961,10 @@ function updateDataSource(data_source_key_name, operation, data_params, quiet_fl } function updateViewByLabel(view_label) { - ui.post(() => { - let aims = dynamic_views.filter(view => view.view_label === view_label); - aims.forEach(view => view.updateOpr(view)); - }); + ui.post(() => dynamic_views + .filter(view => view.view_label === view_label) + .forEach(view => view.updateOpr(view)) + ); } function okHttpRequest(url, path, listener, params) { diff --git a/Modules/MODULE_MONSTER_FUNC.js b/Modules/MODULE_MONSTER_FUNC.js index 946d10c..1a2e5d4 100644 --- a/Modules/MODULE_MONSTER_FUNC.js +++ b/Modules/MODULE_MONSTER_FUNC.js @@ -61,7 +61,7 @@ __global__ = typeof __global__ === "undefined" ? this : __global__; function parseAppName(name, params) { if (!name) return {app_name: "", package_name: ""}; - __global__ = typeof __global__ === "undefined" ? {} : __global__; + __global__ = typeof __global__ === "undefined" ? this : __global__; __global__._monster_$_app_name_cache = __global__._monster_$_app_name_cache || {}; __global__._monster_$_app_package_name_cache = __global__._monster_$_app_package_name_cache || {}; @@ -204,7 +204,7 @@ function getVerName(name, params) { * @return {boolean} */ function launchThisApp(trigger, params) { - __global__ = typeof __global__ === "undefined" ? {} : __global__; + __global__ = typeof __global__ === "undefined" ? this : __global__; if (typeof __global__._monster_$_first_time_run === "undefined") __global__._monster_$_first_time_run = 1; @@ -809,7 +809,7 @@ function runJsFile(file_name) { * @return {boolean} - if msg_level including 3 or 4, then return false; anything else, including undefined, return true **/ function messageAction(msg, msg_level, if_toast, if_arrow, if_split_line, params) { - __global__ = typeof __global__ === "undefined" ? {} : __global__; + __global__ = typeof __global__ === "undefined" ? this : __global__; let _msg = msg || ""; if (msg_level && msg_level.toString().match(/^t(itle)?$/)) { @@ -988,7 +988,7 @@ function showSplitLine(extra_str, style, params) { * @return {boolean} - if not timed out */ function waitForAction(f, timeout_or_times, interval) { - __global__ = typeof __global__ === "undefined" ? {} : __global__; + __global__ = typeof __global__ === "undefined" ? this : __global__; if (typeof timeout_or_times !== "number") timeout_or_times = 10000; let _timeout = Infinity; @@ -1472,7 +1472,7 @@ function refreshObjects(strategy, params) { * @return {boolean} */ function tryRequestScreenCapture(params) { - __global__ = typeof __global__ === "undefined" ? {} : __global__; + __global__ = typeof __global__ === "undefined" ? this : __global__; if (__global__._monster_$_request_screen_capture_flag) return true; sleep(200); // why are you always a naughty boy... how can i get along well with you... @@ -2026,7 +2026,7 @@ function keycode(keycode_name, params_str) { * @param [forcible_flag] {boolean} - forcibly enable with true value */ function debugInfo(msg, info_flag, forcible_flag) { - __global__ = typeof __global__ === "undefined" ? {} : __global__; + __global__ = typeof __global__ === "undefined" ? this : __global__; let global_flag = __global__._monster_$_debug_info_flag; if (!global_flag && !forcible_flag) return; if (global_flag === false || forcible_flag === false) return; @@ -2263,7 +2263,7 @@ function deepCloneObject(obj) { * @param [base_view=ui.main] {View} - specified view for attaching parent views */ function smoothScrollView(shifting, duration, pages_pool, base_view) { - __global__ = typeof __global__ === "undefined" ? {} : __global__; + __global__ = typeof __global__ === "undefined" ? this : __global__; if (pages_pool.length < 2) return; if (__global__._monster_$_page_scrolling_flag) return; @@ -2364,7 +2364,7 @@ function smoothScrollView(shifting, duration, pages_pool, base_view) { * @param [duration=3000] {number} - time duration before message dismissed (0 for non-auto dismiss) */ function alertTitle(dialog, message, duration) { - __global__ = typeof __global__ === "undefined" ? {} : __global__; + __global__ = typeof __global__ === "undefined" ? this : __global__; __global__._monster_$_alert_title_info = __global__._monster_$_alert_title_info || {}; let alert_title_info = __global__._monster_$_alert_title_info; @@ -2474,7 +2474,7 @@ function observeToastMessage(observed_app_pkg_name, observed_msg, timeout, aim_a * @see messageAction */ function captureErrScreen(key_name, log_level) { - __global__ = typeof __global__ === "undefined" ? {} : __global__; + __global__ = typeof __global__ === "undefined" ? this : __global__; let _messageAction = typeof messageAction === "undefined" ? messageActionRaw : messageAction; let _tryRequestScreenCapture = typeof tryRequestScreenCapture === "undefined" ? tryRequestScreenCaptureRaw : tryRequestScreenCapture; @@ -2532,7 +2532,7 @@ function captureErrScreen(key_name, log_level) { * @returns {UiSelector} - with additional function(s) */ function getSelector(params) { - __global__ = typeof __global__ === "undefined" ? {} : __global__; + __global__ = typeof __global__ === "undefined" ? this : __global__; let parent_params = params || {}; let classof = o => Object.prototype.toString.call(o).slice(8, -1); @@ -2939,7 +2939,7 @@ function phoneCallingState() { * timeRecorder("study"); timeRecorder("study", "load", "auto") - eg: "7分钟8.16秒" (means 7m 8.16s) */ function timeRecorder(keyword, operation, divisor, fixed, suffix, override_timestamp) { - __global__ = typeof __global__ === "undefined" ? {} : __global__; + __global__ = typeof __global__ === "undefined" ? this : __global__; if (!__global__._monster_$_timestamp_records) { __global__._monster_$_timestamp_records = {}; @@ -3195,7 +3195,7 @@ function setDeviceProto(params) { let _params = params || {}; let _debugInfo = (_msg, _info_flag) => (typeof debugInfo === "undefined" ? debugInfoRaw : debugInfo)(_msg, _info_flag, _params.debug_info_flag); - __global__ = typeof __global__ === "undefined" ? {} : __global__; + __global__ = typeof __global__ === "undefined" ? this : __global__; if (typeof __global__.device === "undefined") __global__.device = {}; @@ -3314,7 +3314,7 @@ function timedTaskTimeFlagConverter(timeFlag) { function baiduOcr(src, params) { if (!src) return []; - __global__ = typeof __global__ === "undefined" ? {} : __global__; + __global__ = typeof __global__ === "undefined" ? this : __global__; params = params || {}; let timeout = params.timeout || 60000; diff --git a/Modules/MODULE_UNLOCK.js b/Modules/MODULE_UNLOCK.js index 5da8296..5f5286f 100644 --- a/Modules/MODULE_UNLOCK.js +++ b/Modules/MODULE_UNLOCK.js @@ -992,7 +992,7 @@ function loadInternalModuleMonsterFunc() { } function messageAction(msg, msg_level, if_toast, if_arrow, if_split_line, params) { - __global__ = typeof __global__ === "undefined" ? {} : __global__; + __global__ = typeof __global__ === "undefined" ? this : __global__; let _msg = msg || ""; if (msg_level && msg_level.toString().match(/^t(itle)?$/)) { @@ -1128,7 +1128,7 @@ function loadInternalModuleMonsterFunc() { } function waitForAction(f, timeout_or_times, interval) { - __global__ = typeof __global__ === "undefined" ? {} : __global__; + __global__ = typeof __global__ === "undefined" ? this : __global__; if (typeof timeout_or_times !== "number") timeout_or_times = 10000; let _timeout = Infinity; @@ -1379,7 +1379,7 @@ function loadInternalModuleMonsterFunc() { } function tryRequestScreenCapture(params) { - __global__ = typeof __global__ === "undefined" ? {} : __global__; + __global__ = typeof __global__ === "undefined" ? this : __global__; if (__global__._monster_$_request_screen_capture_flag) return true; sleep(200); // why are you always a naughty boy... how can i get along well with you... @@ -1644,7 +1644,7 @@ function loadInternalModuleMonsterFunc() { } function debugInfo(msg, info_flag, forcible_flag) { - __global__ = typeof __global__ === "undefined" ? {} : __global__; + __global__ = typeof __global__ === "undefined" ? this : __global__; let global_flag = __global__._monster_$_debug_info_flag; if (!global_flag && !forcible_flag) return; if (global_flag === false || forcible_flag === false) return; @@ -1851,7 +1851,7 @@ function loadInternalModuleMonsterFunc() { } function captureErrScreen(key_name, log_level) { - __global__ = typeof __global__ === "undefined" ? {} : __global__; + __global__ = typeof __global__ === "undefined" ? this : __global__; let _messageAction = typeof messageAction === "undefined" ? messageActionRaw : messageAction; let _tryRequestScreenCapture = typeof tryRequestScreenCapture === "undefined" ? tryRequestScreenCaptureRaw : tryRequestScreenCapture; @@ -1902,7 +1902,7 @@ function loadInternalModuleMonsterFunc() { } function getSelector(params) { - __global__ = typeof __global__ === "undefined" ? {} : __global__; + __global__ = typeof __global__ === "undefined" ? this : __global__; let parent_params = params || {}; let classof = o => Object.prototype.toString.call(o).slice(8, -1); @@ -2215,7 +2215,7 @@ function loadInternalModuleMonsterFunc() { let _params = params || {}; let _debugInfo = _msg => (typeof debugInfo === "undefined" ? debugInfoRaw : debugInfo)(_msg, "", _params.debug_info_flag); - __global__ = typeof __global__ === "undefined" ? {} : __global__; + __global__ = typeof __global__ === "undefined" ? this : __global__; if (typeof __global__.device === "undefined") __global__.device = {}; diff --git a/README.md b/README.md index 8abdea9..56f81a1 100644 --- a/README.md +++ b/README.md @@ -99,10 +99,13 @@ ### 版本历史 ****** # v1.9.8 -###### 2019/11/23 +###### 2019/11/24 * `修复` 好友森林数据面板可能返回错误统计结果的问题 +* `修复` 图形配置工具可能出现页面加载不完全的问题 _[`issue #137`](https://github.com/SuperMonster003/Auto.js_Projects/issues/137)_ +* `修复` 图形配置工具部分机型按钮控件没有右对齐显示的问题 * `修复` 工具函数模块的debugInfo()可能出现传入参数无效的问题 * `优化` 图形配置工具下载项目进度增加正常显示概率并显示文件大小 +* `优化` 图形配置工具主页面控件加载逻辑及显示速度 _[`issue #137`](https://github.com/SuperMonster003/Auto.js_Projects/issues/137#issuecomment-555830567)_ * `优化` timeRecorder()增加智能结果参数 # v1.9.7 diff --git a/Tools/Unlock_Config_Tool.js b/Tools/Unlock_Config_Tool.js index ed4cb99..b527f0a 100644 --- a/Tools/Unlock_Config_Tool.js +++ b/Tools/Unlock_Config_Tool.js @@ -1264,7 +1264,7 @@ function loadInternalModuleMonsterFunc() { // monster function(s) // function alertTitle(dialog, message, duration) { - __global__ = typeof __global__ === "undefined" ? {} : __global__; + __global__ = typeof __global__ === "undefined" ? this : __global__; __global__._monster_$_alert_title_info = __global__._monster_$_alert_title_info || {}; let alert_title_info = __global__._monster_$_alert_title_info; @@ -1312,7 +1312,7 @@ function loadInternalModuleMonsterFunc() { } function messageAction(msg, msg_level, if_toast, if_arrow, if_split_line, params) { - __global__ = typeof __global__ === "undefined" ? {} : __global__; + __global__ = typeof __global__ === "undefined" ? this : __global__; let _msg = msg || ""; if (msg_level && msg_level.toString().match(/^t(itle)?$/)) { @@ -1448,7 +1448,7 @@ function loadInternalModuleMonsterFunc() { } function waitForAction(f, timeout_or_times, interval) { - __global__ = typeof __global__ === "undefined" ? {} : __global__; + __global__ = typeof __global__ === "undefined" ? this : __global__; if (typeof timeout_or_times !== "number") timeout_or_times = 10000; let _timeout = Infinity; @@ -1613,7 +1613,7 @@ function loadInternalModuleMonsterFunc() { } function debugInfo(msg, info_flag, forcible_flag) { - __global__ = typeof __global__ === "undefined" ? {} : __global__; + __global__ = typeof __global__ === "undefined" ? this : __global__; let global_flag = __global__._monster_$_debug_info_flag; if (!global_flag && !forcible_flag) return; if (global_flag === false || forcible_flag === false) return; @@ -1820,7 +1820,7 @@ function loadInternalModuleMonsterFunc() { } function getSelector(params) { - __global__ = typeof __global__ === "undefined" ? {} : __global__; + __global__ = typeof __global__ === "undefined" ? this : __global__; let parent_params = params || {}; let classof = o => Object.prototype.toString.call(o).slice(8, -1); @@ -2133,7 +2133,7 @@ function loadInternalModuleMonsterFunc() { let _params = params || {}; let _debugInfo = _msg => (typeof debugInfo === "undefined" ? debugInfoRaw : debugInfo)(_msg, "", _params.debug_info_flag); - __global__ = typeof __global__ === "undefined" ? {} : __global__; + __global__ = typeof __global__ === "undefined" ? this : __global__; if (typeof __global__.device === "undefined") __global__.device = {};