# dsh-autotheme **Repository Path**: doublecheese/dsh-autotheme ## Basic Information - **Project Name**: dsh-autotheme - **Description**: dsh 外观插件:浅色 / 深色 / 自动(按当地日出日落切换) - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-09-23 - **Last Updated**: 2026-10-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # dsh-autotheme 给 DSH 界面的「设置 → 通用设置」提供一行 **外观**(Web / 桌面版通用):**浅色 / 深色 / 自动**。 **自动** = 联网取当地日出日落时间:**日出之后切浅色,日落之后切深色**。 ![设置界面](screenshot-settings.png) ## 为什么是独立插件 官方 `@deepseek-ai/dsh-client-ui-theme` 只支持 `light` / `dark` / `system`,而 npx 每次升级 都会把包目录**原地覆盖**,任何对官方文件的改动都会在升级后消失(并且旧值会让插件启动即报 `ValidationError: invalid config`)。本插件不改官方任何文件: - 它只通过公开服务 `ctx.theme.setTheme('light' | 'dark')` 驱动配色; - 「自动」这个偏好存在**本插件自己的 config** 里(profile 的 `cordis.patch.yml` 条目 `autotheme`); - 官方那一行「外观(浅色/深色/跟随系统)」由本插件隐藏,避免两行冲突。 因此 dsh 升级不会影响它,官方 schema 也永远不会收到非法值。 ## 安装 **推荐:在 DSH 的插件页里装(`dsh` 0.2.x)** 侧栏「插件」→「添加插件」→「安装第三方插件」,粘贴: ``` git+https://gitee.com/doublecheese/dsh-autotheme.git ``` 装完出现在「已安装插件」里,可随时**启用 / 停用 / 卸载**;需要重启时页面会提示。 **命令行(等价)** ```powershell dsh plugin --profile add git+https://gitee.com/doublecheese/dsh-autotheme.git ``` **本地包(离线可用,不推荐)** ```powershell pwsh -NoProfile -File <本目录>\install-dsh-autotheme.ps1 ``` > 仓库地址: `dsh plugin add` / 插件页安装会把本包登记进 profile 的 `dsh.profile.bundles`,随包提供的 `cordis.patch.yml` 会自动插入 `autotheme` 行。本地脚本则是手工复制包并往 profile 的 `cordis.patch.yml` 塞 insert 行——这样装出来的插件**不会出现在插件页**(插件管理器只认 profile 依赖),且脚本还会把历史上被写成非法值的 `ui-theme` 偏好(例如 `preference: auto`)改回 `light`,避免官方主题插件启动即报 `ValidationError`。 ## 使用 - **自动**:按当地日出日落切换(默认)。悬停方块可看到当天解析到的日出/日落时刻。 - **浅色 / 深色**:固定配色,此时插件不发任何网络请求。 - 配置字段 `mode`(`auto` / `off`)写在 profile 的 `cordis.patch.yml`: ```yaml - id: autotheme name: 'dsh-autotheme' config: mode: auto ``` ## 自动是怎么算出来的 1. IP 定位取经纬度:`ipinfo.io` → `ipwho.is`(逐个尝试;`ipapi.co` / `bigdatacloud` 在浏览器里被 CORS 挡,不用)。 2. 取当天日照:`api.open-meteo.com`(`sunrise` / `sunset` / `daylight_duration`)→ `api.sunrise-sunset.org`。 3. 结果写进 localStorage `dsh-autotheme-sun`:既存当天的绝对时刻,也存设备本地的分钟数, 因此**跨天、离线、接口被限流**时仍按上一天的时刻继续切换;极昼/极夜按日照时长整日浅/深。 4. 在每个日出/日落边界和页面重新可见时重判;`Host` 半边还会在首屏(JS 未跑起来时) 读同一条记录上色,避免闪色。 5. 完全没有数据时:先等这一次请求;**请求失败则回落到官方 `system`(`prefers-color-scheme`)**, 不会把上一晚的深色留到第二天早上。 6. 每分钟一次兜底自愈:官方 config 的写入按 revision 串行、可能被拒,运行时偏好与画面也可能 脱节(回滚路径不一定再发 `theme/change`)。自愈会核对「运行时偏好」与「DOM 配色」, 必要时用空 token 覆盖层强制官方展示器重绘。 ## 排查(debug) 在 profile 配置里打开 `debug: true`,客户端会在启动约 4 秒后把状态摘要写回同一个条目: ```yaml - id: autotheme name: dsh-autotheme config: mode: auto debug: true diag: at=2026-09-28T01:48:05.426Z mode=auto pref=light scheme=light fetching=false media=dark tz=Asia/Shanghai record={"day":"2026-09-28","sunrise":353,"sunset":1072,...} ``` `diag` 中 `pref` 是官方运行时偏好、`scheme` 是日出日落判定、`media` 是系统主题、 `record` 是当前缓存的日照记录。开着 `debug` 时页面还会挂 `window.__dshatAutoTheme.state()`。 ## 卸载 在插件页里点「卸载」,或按安装方式卸载: ```powershell dsh plugin --profile remove dsh-autotheme # 插件页 / 命令行安装 pwsh -NoProfile -File <本目录>\uninstall-dsh-autotheme.ps1 # 本地脚本安装 ``` 移出 `node_modules` 并删掉登记;官方那一行「外观」会自动回来。 ## 已知限制 - 官方行的隐藏依赖 DOM 结构(按「三个偏好方块」识别)。若某次升级改了设置页结构, 最坏情况是多出一行官方「外观」,功能本身不受影响。 - 定位是 IP 级(城市精度,对日出日落足够);用 VPN 时会跟随出口 IP 的城市。 - 「自动」会在每个边界把官方偏好写成 `light` / `dark`(这是驱动官方展示层的唯一公开方式), 因此卸载后官方设置里保留的是最后一次切换的结果。 MIT.