Skip to content

为脚本增加独立于系统 Toast 的提示能力,通过全局对象 toastX 使用,不改动现有 toast() 行为 - #231

Open
xcl199f wants to merge 3 commits into
aiselp:setup-v7from
xcl199f:pr/custom-toast
Open

xcl199f wants to merge 3 commits into
aiselp:setup-v7from
xcl199f:pr/custom-toast

Conversation

@xcl199f

@xcl199f xcl199f commented Nov 14, 2026

Copy link
Copy Markdown
  • 全局 toastX,提供 toastX.init(config) 设置默认样式、toastX.show(msg[, config]) 显示提示。
  • 可配置显示时长、位置与偏移、透明度、背景色、文字颜色与字号、圆角、内边距、图标,以及是否同时输出到控制台。
  • 多次调用按队列顺序依次显示,避免连续提示互相覆盖;override: true 可清空队列并立即显示最新一条。

- CustomToastView 使用独立 HandlerThread 串行展示,避免连续 toast 互相覆盖
- 支持文字大小/颜色、背景色、圆角、显示时长、边距等配置
- 新增 layout_custom_toast.xml 布局
原来在 showFull() 里直接 toastHandler.postDelayed(dismiss, duration),
而 wm.addView 通过 mainHandler.post 异步排到主线程。主线程排队与加窗口的
几十到几百毫秒被算进 duration,500ms 这类短时长实际可见时间明显偏短。

把 postDelayed 移进 mainHandler.post、放在 addView 之后,计时从真正上屏
开始;pending dismiss 仍在 toastHandler 上,dismissAll() 可正常取消。
顺带删掉重复调用一次的 toastViews.add(view)(原本导致 list 只增不减、
第 11 个 toast 就误触发 dismissAll 清掉队列)。
CustomToastView 类本身不足以让脚本使用 toastX:__globals__.js 里
global.toastX = runtime.toastX 需要 ScriptRuntime 上有对应字段。
原本地基线 2d08665 里这段存在于别处,rebase 到纯上游 4c396b2
后丢失,导致 toastX 为 undefined。补齐 import、@ScriptVariable 字段
与构造函数初始化,使该 PR 单独合并也能正常工作。
@codacy-production

Copy link
Copy Markdown

Not up to standards ⛔

🔴 Issues 2 high

Alerts:
⚠ 2 issues (≤ 0 issues of at least minor severity)

Results:
2 new issues

Category Results
ErrorProne 2 high

View in Codacy

🟢 Metrics 41 complexity · 0 duplication

Metric Results
Complexity 41
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant