fix: honour browser.toast=false when browser.native=true - #2
Open
fengfanfan-max wants to merge 1 commit into
Open
fengfanfan-max wants to merge 1 commit into
fengfanfan-max wants to merge 1 commit into
Conversation
The engine reads the two browser settings as independent switches:
var showToast = cfg.browser?.enabled !== false && cfg.browser?.toast !== false;
var showNative = cfg.browser?.native === true;
if (!showToast && !showNative) return;
but `showToast` was only ever used for that early return — it was never passed
on, and `fireBrowserNotification` pushed to the banner store unconditionally:
function fireBrowserNotification(message, toastStore, options) {
if (options && options.native === true) fireNativeNotification(...);
if (document.visibilityState === "hidden") return;
if (toastStore === undefined) return;
toastStore.push(message.title, message.body); // always
}
So disabling "浏览器通知" while "系统原生通知" stayed on still produced the
in-page banner. Only turning BOTH off suppressed it.
Reproduction: with browser = { enabled: true, toast: false, native: true },
end a turn while the page is visible — a banner appears even though the banner
switch is off.
Pass the flag through and short-circuit on it, restoring the independence the
comment on those two variables already promises. The settings page's own test
buttons still call fireBrowserNotification without options, so they keep showing
a banner, which is what they are for.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is broken
「浏览器通知」和「系统原生通知」这两个开关并不独立。只要「系统原生通知」开着,把「浏览器通知」关掉,页面内的文字横幅照样会弹。
Reproduction
让页面保持可见,然后等一轮对话结束(或切走再回来触发一次
turn/end)。Expected: 只弹系统原生通知,页面内没有横幅。
Actual: 页面内横幅也弹出来了。
只有两个开关都关,横幅才真的不出现。
Root cause
引擎里那两个变量的注释声称二者独立:
但
showToast只参与了那个提前 return,从来没被传下去;而fireBrowserNotification里推横幅是无条件的:所以
native: true时toast: false完全失效。The fix
把
toast传下去,并在fireBrowserNotification里短路,恢复注释已经承诺的独立性。设置页里那两个测试按钮仍以无options的方式调用,因此继续会弹横幅——那正是它们的用途。Tests
改了 3 行,没有带测试:
lib/client.js目前在node --test下零覆盖,要驱动它需要一个 DOM(bundle 加载过程中会用到document.querySelector等),仓库里没有 jsdom 之类的 devDependency。为一个三行的布尔短路把测试框架引进来,我觉得不该塞进这个 PR。如果你希望带上测试,我可以单独提一个 PR 加上客户端测试骨架(jsdom + 桩
window.__ModuleLoader__),然后在这个 PR 里补上行为断言。你说一声就行。验证
已在真实环境复现:
{ enabled: true, toast: false, native: true }下轮次结束时页内横幅确实出现。