Conversation
扩展更新时会自动打开更新日志并同时发送系统通知,点击通知却会再开一个同样的页面。 现在先打开更新日志再发通知,并在通知缓存中记下该标签页;点击通知时若该标签页仍停留在 更新日志页面(忽略 hash),则激活它并聚焦其窗口,否则(已关闭、已跳走或未自动打开)照旧新开。
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.
Checklist / 检查清单
背景
Close #1769。扩展更新(次版本 / beta)时会自动打开更新日志页,同时发一条「点击查看更新日志」的系统通知;点击通知却会再
chrome.tabs.create一个同样的页面,更新日志被打开两次。按维护者在 issue 中的意见,点击通知时应激活已经自动打开的页面。本次改动
openChangelogAndNotify(service_worker/index.ts):从onInstalled里抽出,改为先打开更新日志页、再发通知,并把打开的标签页 id 一并写进通知缓存(NotificationOptionCache.tabId)。原来两者并行,发通知时还拿不到标签页。打开失败时照常发通知(不带tabId)并记录错误。openNotificationUrl(service_worker/utils.ts):通知点击处理(gm_api.ts的handlerNotification)改用它。若tabId对应的标签页仍存在且仍停留在该页面(比较 hash 之前的部分,加载中时看pendingUrl),就激活该标签页并聚焦其窗口;否则(未自动打开、已关闭、已跳到其他页面)照旧新开。1.5.1)本来就不自动打开页面,行为不变:点击通知仍新开页面。实现考虑
#版本号,用户在页面内点锚点只会改 hash,不应视为离开。标签页已被用户跳走时不抢占它,避免把用户正在看的其他页面切到前台。https://docs.scriptcat.org/docs/change/、/en/docs/change/、/docs/change/beta-changelog/均直接返回 200、无重定向,所以按 URL 比较不会因重定向误判而多开。tabId只由更新日志这一处写入,其他InfoNotification调用方不受影响。已知限制
chrome.tabs.get与chrome.tabs.update之间标签页恰好被关闭时,update会失败,此时只记录错误、不再补开页面。chrome.windows.update(windowId, { focused: true }))。验证
openNotificationUrl/openChangelogAndNotify不存在,9 个用例全部失败),实现后:pnpm exec vitest run --no-coverage src/app/service/service_worker/index.test.ts src/app/service/service_worker/utils.test.ts→ 36 passed。pnpm run build构建7c5b9cb1,以解压方式加载dist/ext;在扩展管理页点「重新加载」触发onInstalled(reason=update),版本1.5.0-beta.4会自动打开 beta 更新日志页并发出系统通知。pnpm run typecheck通过;pre-commit(prettier / typecheck / eslint / issue-templates)通过。pnpm exec vitest run --no-coverage src/app/service/service_worker→ 仅trash_event_partition.test.ts的 2 个用例失败;在origin/main(80854540)源码上用同一命令同样失败,与本改动无关。vitest run在并发负载下有大量随机超时(每次失败的文件都不同,基线origin/main同样出现,抽样单独重跑均通过),未能得到干净的全量结果。🤖 Generated with Claude Code