Repository navigation
Conversation
Collaborator
|
竟然有這個了! |
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 / 检查清单
背景
#1018 希望脚本能直接拿到用户在脚本猫里设置的界面语言,按它决定脚本自身的显示语言,而不必每个脚本各自做一个语言选项。
本次改动
GM_info新增userLanguage: string,值为脚本猫当前界面语言(SystemConfig.getLanguage()的解析结果,如"zh-CN"、"en-US"、"ja-JP";设置为「自动」时即自动匹配出的语言)。三条执行路径都覆盖:getScriptsForTab组装envInfo时带上语言,随 pageLoad 下发。@early-start):与isIncognito相同的模式——同步执行时页面环境尚未到达,值为"";updateEarlyScriptGMInfo收到 envInfo 后补上真实值(CAT_scriptLoaded()之后可读到)。Runtime记录setSandboxLanguage收到的语言,构造BgExecScriptWarp时传入。类型声明
scriptcat.d.ts/scriptcat.zh-CN.d.ts/ 编辑器用scriptcat.d.tpl同步新增字段。实现考虑
user_lang,这里采用userLanguage,与GM_info现有字段(isIncognito、userAgentData、scriptHandler)的 camelCase 风格一致。若维护者倾向 issue 原名,改名只涉及类型声明与gm_info.ts一处取值。GM_info是脚本启动时的快照。切换语言后,页面脚本在下次加载页面时生效,后台/定时脚本在下次执行时生效(每次执行都会新建BgExecScriptWarp),已在运行的实例不会被改写。handlePreparationOffscreen改为先发布setSandboxLanguage再发布enableScripts。原顺序下语言之所以能先到沙盒,只是因为 offscreen 处理enableScripts时先await了一次 SW 往返;现在由发布顺序直接保证,浏览器启动即运行的后台脚本也能读到语言。已知限制
navigator.language。""(见上)。GM_info说明不在本仓库,未同步更新。验证
均在
4dc6613a(基于main58309d5e)上执行:GM_info.userLanguage取值、早期脚本更新、BgExecScriptWarp取值、沙盒传参 ×2、语言先于enableScripts发布),实现前全部失败、实现后通过。pnpm exec vitest run --no-coverage受影响的 7 个文件(SW/沙盒 runtime、exec_script、exec_warp、gm_api、offscreen base、script_executor):165/165 通过。pnpm run lint:通过(prettier、tsc、check:i18n、check:issue-templates、eslint)。CI=true pnpm run test:ci全量:5001/5003 通过,失败 2 个是src/pages/下与本改动无关的 UI 用例 850ms 超时(SettingsPane.test.tsx、NetworkRules/index.test.tsx),单独重跑 55/55 通过。本机当时负载很高(load avg 25~50),三次全量跑每次超时的 UI 文件都不同,未改动的main在同样条件下也有不同的 UI 文件超时。不带CI=true时,fast项目单 worker 共享 VM 会出现大量与顺序相关的失败,main上同样存在,不作为本 PR 的证据。pnpm run build)+ 一次性 Playwright 脚本(未入库),Chromium:zh-CN;在设置页切到日本語后刷新 →ja-JP"",CAT_scriptLoaded()后为zh-CN,切换后为ja-JPGM_setValue写入de-DE关联
Close #1018