Conversation
There was a problem hiding this comment.
Pull request overview
此 PR 将 background 权限从必需权限改为可选权限,并添加了后台运行功能的用户界面控制。主要目的是让用户可以选择是否启用浏览器后台运行功能,以支持后台脚本和定时脚本的持续运行。
关键变更
- 将
background权限从 manifest.json 的 permissions 移至 optional_permissions - 重构 GMApiSetting 组件为 RuntimeSetting,新增后台运行开关
- 在脚本安装页面添加后台运行提示对话框,引导用户启用该功能
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 21 comments.
Show a summary per file
| File | Description |
|---|---|
| src/manifest.json | 将 background 权限从必需改为可选 |
| src/pages/options/routes/Setting.tsx | 使用新的 RuntimeSetting 组件替换 GMApiSetting |
| src/pages/components/RuntimeSetting/index.tsx | 新建运行时设置组件,包含后台运行开关和文件系统配置 |
| src/pages/components/GMApiSetting/index.tsx | 删除旧的 GMApiSetting 组件 |
| src/pages/install/App.tsx | 添加后台运行提示对话框和相关逻辑 |
| src/locales/zh-CN/translation.json | 添加后台运行相关的中文翻译 |
| src/locales/zh-TW/translation.json | 添加后台运行相关的繁体中文翻译 |
| src/locales/en-US/translation.json | 添加后台运行相关的英文翻译 |
| src/locales/de-DE/translation.json | 添加后台运行相关的德语翻译 |
| src/locales/ja-JP/translation.json | 添加后台运行相关的日语翻译 |
| src/locales/ru-RU/translation.json | 添加后台运行相关的俄语翻译 |
| src/locales/vi-VN/translation.json | 添加后台运行相关的越南语翻译 |
src/locales/zh-TW/translation.json
Outdated
| "title": "啟用後台運行", | ||
| "description": "啟用後,瀏覽器會延遲關閉縮小到托盤,後台腳本可以持續運行", | ||
| "enable_faild": "啟用失敗", | ||
| "disable_faild": "禁用失敗", |
There was a problem hiding this comment.
拼写错误:键名 "disable_faild" 应该是 "disable_failed"(failed 拼写错误)。
| "disable_faild": "禁用失敗", | |
| "disable_failed": "禁用失敗", |
src/locales/ru-RU/translation.json
Outdated
| "enable_faild": "Не удалось включить", | ||
| "disable_faild": "Не удалось отключить", |
There was a problem hiding this comment.
拼写错误:键名 "enable_faild" 应该是 "enable_failed"(failed 拼写错误)。
| "enable_faild": "Не удалось включить", | |
| "disable_faild": "Не удалось отключить", | |
| "enable_failed": "Не удалось включить", | |
| "disable_failed": "Не удалось отключить", |
src/pages/install/App.tsx
Outdated
| const hasShown = localStorage.getItem("background_prompt_shown"); | ||
|
|
||
| if (hasShown !== "true") { | ||
| // 检查是否已经有后台权限 | ||
| if (!(await chrome.permissions.contains({ permissions: ["background"] }))) { | ||
| localStorage.setItem("background_prompt_shown", "true"); |
There was a problem hiding this comment.
逻辑问题:localStorage 设置时机不正确。当前在检测到需要提示时立即设置 "background_prompt_shown",这会导致如果用户刷新页面或关闭对话框而不做选择,将永远不会再看到提示。应该将 localStorage.setItem 移到用户实际做出选择后(在 Modal 的 onOk 或 onCancel 回调中),确保用户至少看到一次提示。
| Message.error(t("enable_background.enable_faild")!); | ||
| } | ||
| }} | ||
| onCancel={() => { |
There was a problem hiding this comment.
可维护性建议:onCancel 回调中缺少 localStorage 设置。为了确保提示逻辑的一致性,无论用户选择"立即启用"还是"暂不启用",都应该设置 localStorage.setItem("background_prompt_shown", "true"),以配合第 319 行的逻辑修复。
| onCancel={() => { | |
| onCancel={() => { | |
| localStorage.setItem("background_prompt_shown", "true"); |
| onOk={async () => { | ||
| try { | ||
| const granted = await chrome.permissions.request({ permissions: ["background"] }); | ||
| if (granted) { | ||
| Message.success(t("enable_background.title")!); | ||
| } else { | ||
| Message.info(t("enable_background.maybe_later")!); | ||
| } | ||
| setShowBackgroundPrompt(false); | ||
| } catch (e) { | ||
| console.error(e); | ||
| Message.error(t("enable_background.enable_faild")!); | ||
| } | ||
| }} |
There was a problem hiding this comment.
可维护性建议:onOk 回调中缺少 localStorage 设置。为了确保提示逻辑的一致性,应该在此处添加 localStorage.setItem("background_prompt_shown", "true"),并从第 319 行移除该设置,以确保只有在用户做出选择后才标记为已显示。
src/locales/de-DE/translation.json
Outdated
| "enable_background": { | ||
| "title": "Hintergrundausführung aktivieren", | ||
| "description": "Wenn aktiviert, verzögert der Browser das Schließen und minimiert in den Tray, sodass Hintergrundskripte weiterlaufen können", | ||
| "enable_faild": "Aktivierung fehlgeschlagen", |
There was a problem hiding this comment.
拼写错误:键名 "enable_faild" 应该是 "enable_failed"(failed 拼写错误)。
| "enable_faild": "Aktivierung fehlgeschlagen", | |
| "enable_failed": "Aktivierung fehlgeschlagen", |
src/locales/vi-VN/translation.json
Outdated
| "enable_faild": "Bật thất bại", | ||
| "disable_faild": "Tắt thất bại", |
There was a problem hiding this comment.
拼写错误:键名 "enable_faild" 应该是 "enable_failed"(failed 拼写错误)。
| "enable_faild": "Bật thất bại", | |
| "disable_faild": "Tắt thất bại", | |
| "enable_failed": "Bật thất bại", | |
| "disable_failed": "Tắt thất bại", |
| chrome.permissions.request({ permissions: ["background"] }, (granted) => { | ||
| if (chrome.runtime.lastError) { | ||
| console.error(chrome.runtime.lastError); | ||
| Message.error(t("enable_background.enable_faild")!); |
There was a problem hiding this comment.
拼写错误:翻译键 "enable_background.enable_faild" 应该是 "enable_background.enable_failed"(failed 拼写错误)。
| Message.error(t("enable_background.enable_faild")!); | |
| Message.error(t("enable_background.enable_failed")!); |
src/locales/zh-CN/translation.json
Outdated
| "title": "启用后台运行", | ||
| "description": "启用后,浏览器会延迟关闭缩小到托盘,后台脚本可以持续运行", | ||
| "enable_faild": "启用失败", | ||
| "disable_faild": "禁用失败", |
There was a problem hiding this comment.
拼写错误:键名 "disable_faild" 应该是 "disable_failed"(failed 拼写错误)。建议在所有语言文件中将此键重命名为 "disable_failed"。
| "disable_faild": "禁用失败", | |
| "disable_failed": "禁用失败", |
src/locales/zh-TW/translation.json
Outdated
| "enable_faild": "啟用失敗", | ||
| "disable_faild": "禁用失敗", |
There was a problem hiding this comment.
拼写错误:键名 "enable_faild" 应该是 "enable_failed"(failed 拼写错误)。
| "enable_faild": "啟用失敗", | |
| "disable_faild": "禁用失敗", | |
| "enable_failed": "啟用失敗", | |
| "disable_failed": "禁用失敗", |
src/locales/zh-CN/translation.json
Outdated
| "runtime": "运行时", | ||
| "enable_background": { | ||
| "title": "启用后台运行", | ||
| "description": "启用后,浏览器会延迟关闭缩小到托盘,后台脚本可以持续运行", |
There was a problem hiding this comment.
此處的延遲關閉是什麼意思
有background就會縮小一直跑不會關閉吧
There was a problem hiding this comment.
There was a problem hiding this comment.
呀,好像它原文就這樣怪怪的
他想說的話是,即使在關掉所有頁面,也會缩小到托盘,所以要在托盘那裡也確認關閉才會關掉吧
Makes Chrome start up early (as soon as the user logs into their computer, before they launch Chrome), and shut down late (even after its last window is closed, until the user explicitly quits Chrome).
英文原本沒有 "delay" 一詞
原文的意思只是 較早開啟 較遲關閉
不過算了我也沒太大執著
我覺得各語言直接用官方的文字就好
Makes Chrome start up early (as soon as the user logs into their computer, before they launch Chrome), and shut down late (even after its last window is closed, until the user explicitly quits Chrome).
使 Chrome 提前启动(用户登录计算机后立即启动,在用户启动 Chrome 之前),并延迟关闭(即使在其最后一个窗口关闭后,也要等到用户明确退出 Chrome)。
讓 Chrome 提早啟動 (使用者登入電腦後,在啟動 Chrome 前),並延後關閉 (即使最後一個視窗關閉後,也要等到使用者明確關閉 Chrome)。
(繁体中文的寫法用了延後)
Chrome の起動を早め(ユーザーがパソコンにログインするとすぐに、Chrome を起動する前に)、シャットダウンを遅らせます(最後のウィンドウが閉じても、ユーザーが Chrome を明示的に終了するまで)。
Заставляет Chrome запускаться раньше (как только пользователь входит в свой компьютер, прежде чем он запустит Chrome) и позже закрываться (даже после закрытия последнего окна, пока пользователь явно не выйдет из Chrome).
Chrome wird früh gestartet (sobald sich der Nutzer auf dem Computer anmeldet, bevor er Chrome startet) und spät heruntergefahren (auch nach dem Schließen des letzten Fensters, bis der Nutzer Chrome explizit beendet).
Làm cho Chrome khởi động sớm (ngay khi người dùng đăng nhập vào máy tính, trước khi họ khởi chạy Chrome) và tắt muộn (ngay cả sau khi cửa sổ cuối cùng của Chrome đóng, cho đến khi người dùng thoát Chrome một cách rõ ràng).
There was a problem hiding this comment.
改了繁体和英文,其它语言的不知道如何下手了,chrome文档里面的大部分应该也是机翻
Co-authored-by: cyfung1031 <44498510+cyfung1031@users.noreply.github.com>
Co-authored-by: cyfung1031 <44498510+cyfung1031@users.noreply.github.com>
Co-authored-by: cyfung1031 <44498510+cyfung1031@users.noreply.github.com>
概述 Descriptions
close #1047
变更内容 Changes
截图 Screenshots