Skip to content

feat: 允许没有背景#636

Open
ShadowLemoon wants to merge 2 commits into
AlkaidLab:masterfrom
ShadowLemoon:feat/no-background
Open

feat: 允许没有背景#636
ShadowLemoon wants to merge 2 commits into
AlkaidLab:masterfrom
ShadowLemoon:feat/no-background

Conversation

@ShadowLemoon
Copy link
Copy Markdown
Collaborator

No description provided.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 9, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6b0a9dde-e700-4d5a-be61-369c81740db0

📥 Commits

Reviewing files that changed from the base of the PR and between 44b710b and 1efc08b.

📒 Files selected for processing (2)
  • src_assets/common/assets/web/components/LogsSection.vue
  • src_assets/common/assets/web/composables/useBackground.js
🚧 Files skipped from review as they are similar to previous changes (2)
  • src_assets/common/assets/web/components/LogsSection.vue
  • src_assets/common/assets/web/composables/useBackground.js

Summary by CodeRabbit

发布说明

  • 新功能
    • 在页头新增一个隐藏触发,可通过快速连续点击切换“开发者模式”(状态会持久保存并广播变更)。
    • 启用开发者模式时,界面将绕过背景图像应用以恢复默认背景;模式切换会触发背景加载/还原逻辑并在组件销毁时正确移除相关监听与清理。

Walkthrough

在 LogsSection.vue 添加不可见的触发元素与 7 次/3 秒的切换逻辑,状态用 localStorage 持久化并派发 sunshine-background-bypass 事件;在 useBackground.js 中增加 dev-mode 绕过、事件响应与 Vue 作用域清理。

变更

开发者模式触发和背景绕过

层级 / 文件 摘要
UI触发器定义与状态管理
src_assets/common/assets/web/components/LogsSection.vue
新增 ref 导入、阈值与超时常量、readDevMode/writeDevMode(含 try/catch)、devMode/devTapCount/devTapTimer 状态与 handleDevTap 处理器。在模板中加入不可见的 .dev-trigger 可点击元素;达到阈值时翻转 devMode、持久化到 localStorage 并派发 sunshine-background-bypass CustomEvent。添加 .dev-trigger 的 scoped CSS。
背景绕过逻辑实现
src_assets/common/assets/web/composables/useBackground.js
引入 getCurrentScopeonScopeDispose 以便清理副作用。新增基于 localStorage.sunshine_dev_mode 的判断与清除逻辑:当启用时 setBackground 清除内联背景并提前返回;saveBackgroundclearBackground 在写入/移除前先清除绕过标记。注册 windowsunshine-background-bypass 事件监听:启用时清空内联背景,禁用时调用 loadBackground 重新加载。作用域销毁时断开 MutationObserver 并移除事件监听。

Sequence Diagram

sequenceDiagram
  participant User
  participant LogsSection
  participant localStorage
  participant Window
  participant useBackground
  participant document as document.body.style
  User->>LogsSection: 点击隐藏触发器(最多 7 次)
  LogsSection->>LogsSection: 累加点击计数并在 3s 内判断阈值
  LogsSection->>localStorage: writeDevMode(enabled)
  LogsSection->>Window: dispatchEvent('sunshine-background-bypass', {enabled})
  Window->>useBackground: 事件到达
  alt enabled = true
    useBackground->>document: 清除内联 background
  else enabled = false
    useBackground->>useBackground: loadBackground() 重新应用
  end
Loading

预估代码审查工作量

🎯 3 (中等) | ⏱️ ~20 分钟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive 作者未提供拉取请求描述,无法评估其与变更内容的相关性。 建议添加拉取请求描述,说明该功能的目的、实现原理(7次点击触发开发模式)和使用方式。
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed 标题准确反映了主要变更内容——允许用户禁用背景,通过开发者模式触发器实现背景绕过功能。
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
src_assets/common/assets/web/composables/useBackground.js (1)

198-205: ⚡ Quick win

建议把 dev key 和事件名抽成共享常量,避免跨文件漂移

这里与 LogsSection.vue 使用同一组字符串字面量;建议集中定义后统一引用,减少未来改名或拼写不一致导致的隐性故障。

建议修复
+// src_assets/common/assets/web/constants/devMode.js
+export const DEV_MODE_STORAGE_KEY = 'sunshine_dev_mode'
+export const BACKGROUND_BYPASS_EVENT = 'sunshine-background-bypass'
-const isDevMode = () => localStorage.getItem('sunshine_dev_mode') === '1'
+import { DEV_MODE_STORAGE_KEY, BACKGROUND_BYPASS_EVENT } from '../constants/devMode'
+const isDevMode = () => localStorage.getItem(DEV_MODE_STORAGE_KEY) === '1'
@@
-    if (localStorage.getItem('sunshine_dev_mode') === '1') {
-      localStorage.setItem('sunshine_dev_mode', '0')
+    if (localStorage.getItem(DEV_MODE_STORAGE_KEY) === '1') {
+      localStorage.setItem(DEV_MODE_STORAGE_KEY, '0')
@@
-    window.addEventListener('sunshine-background-bypass', onBackgroundBypass)
+    window.addEventListener(BACKGROUND_BYPASS_EVENT, onBackgroundBypass)

As per coding guidelines src_assets/**/*.{vue,js,html}: 基于 Vue.js 的 Web 配置面板。审查 XSS/CSRF 安全性、 组件设计、状态管理和可访问性。

Also applies to: 340-346

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src_assets/common/assets/web/composables/useBackground.js` around lines 198 -
205, Extract the literal key and event name used for dev bypass into shared
constants and update usages: create a small constants export (e.g., DEV_MODE_KEY
and DEV_MODE_EVENT) and replace the string literals in useBackground.js
(functions isDevMode and clearDevBypass) and in LogsSection.vue so both files
import and reference the same symbols; ensure the constants file is co-located
with other web composables and exported for reuse to avoid future drift and
typos.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src_assets/common/assets/web/components/LogsSection.vue`:
- Around line 174-187: The code directly accesses localStorage in the devMode
initialization and inside handleDevTap (symbols: DEV_STORAGE_KEY, devMode,
handleDevTap, devTapTimer, DEV_TAP_TIMEOUT, DEV_TAP_THRESHOLD); wrap both the
read and write operations in try-catch blocks (or guard with a safe localStorage
helper) so SecurityError in privacy/locked environments won't throw—on read
return a safe default (devMode false) when access fails and on write silently
ignore failures (or update an in-memory fallback), keep the rest of handleDevTap
logic intact and still dispatch the toggle event after updating the safe state.

In `@src_assets/common/assets/web/composables/useBackground.js`:
- Around line 339-346: The global event listener ('sunshine-background-bypass')
and the MutationObserver created inside useBackground are not cleaned up,
causing leaks; update useBackground to store references to the
window.addEventListener handler and the MutationObserver instance and register a
cleanup using Vue's onScopeDispose: remove the window event listener via
window.removeEventListener('sunshine-background-bypass', handler) and call
observer.disconnect() inside the onScopeDispose callback so both the listener
and observer are properly released when the component using useBackground is
unmounted.

---

Nitpick comments:
In `@src_assets/common/assets/web/composables/useBackground.js`:
- Around line 198-205: Extract the literal key and event name used for dev
bypass into shared constants and update usages: create a small constants export
(e.g., DEV_MODE_KEY and DEV_MODE_EVENT) and replace the string literals in
useBackground.js (functions isDevMode and clearDevBypass) and in LogsSection.vue
so both files import and reference the same symbols; ensure the constants file
is co-located with other web composables and exported for reuse to avoid future
drift and typos.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: bd047fed-7b9f-49e8-9967-c160e0fa32e2

📥 Commits

Reviewing files that changed from the base of the PR and between 1543450 and 44b710b.

📒 Files selected for processing (2)
  • src_assets/common/assets/web/components/LogsSection.vue
  • src_assets/common/assets/web/composables/useBackground.js
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Windows
🧰 Additional context used
📓 Path-based instructions (1)
src_assets/**/*.{vue,js,html}

⚙️ CodeRabbit configuration file

src_assets/**/*.{vue,js,html}: 基于 Vue.js 的 Web 配置面板。审查 XSS/CSRF 安全性、 组件设计、状态管理和可访问性。

Files:

  • src_assets/common/assets/web/components/LogsSection.vue
  • src_assets/common/assets/web/composables/useBackground.js
🔇 Additional comments (1)
src_assets/common/assets/web/components/LogsSection.vue (1)

80-83: 阈值、超时和存储键提为常量是个不错的改动

这段改动提升了可读性和后续调整成本。

Comment thread src_assets/common/assets/web/components/LogsSection.vue Outdated
Comment thread src_assets/common/assets/web/composables/useBackground.js Outdated
@ShadowLemoon
Copy link
Copy Markdown
Collaborator Author

@copilot 帮我解决一下在我仓库开个pr pr到这个分支

@qiin2333 qiin2333 force-pushed the master branch 2 times, most recently from 4db4aa3 to e5579b9 Compare June 4, 2026 07:31
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.

2 participants