【已审核】feat(theme): 新增按真实日出日落自动切换深浅色主题模式#1065
Open
climashscape wants to merge 1 commit into
Open
Conversation
根据本地经纬度和时区计算每日日出日落时刻,自动在 light/dark 主题间切换;跨日出日落临界点修复切换不生效问题。 - apps/electron/src/renderer/lib/solar.ts: 日出日落计算与 solar 模式切换调度 - apps/electron/src/renderer/lib/cities.ts: 内置城市经纬度数据 - apps/electron/src/renderer/atoms/theme.ts: theme atom 接入 solar 切换 - apps/electron/src/renderer/components/settings/AppearanceSettings.tsx: 外观设置新增 solar 模式选项与城市选择 - apps/electron/src/renderer/main.tsx: 启动时初始化 solar 调度 - apps/electron/src/types/settings.ts: 新增 solar 相关设置类型 - apps/electron/src/main/ipc.ts + src/preload/index.ts: solar 相关 IPC 通道
3835568 to
fb45a80
Compare
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.
概述
新增「日出日落」主题模式(
themeMode='solar')。应用自身根据用户选定城市的经纬度与当前日期,离线计算真实日出日落时刻,在日出时切到浅色、日落时切到深色,不依赖操作系统的深浅色切换能力,跨平台行为一致。现有的「跟随系统」模式被动跟随 OS,依赖 macOS / Windows 11 22H2+ 的系统层日落切换,Linux 及更早 Windows 无此能力,且多设备需各自在 OS 层配置。本模式由应用主动按真实天文时刻切换,弥补这一缺口。
改动
types/settings.ts:ThemeMode新增'solar';AppSettings新增solarLocation?: { lat, lng, name }renderer/lib/solar.ts(新增):NOAA 日出日落算法(零依赖),导出getSunriseSunset/isDaytime/nextTransition;极昼/极夜返回 null 并 fallbackrenderer/lib/cities.ts(新增):内置 ~170 个全球主要城市经纬度表 +searchCitiesrenderer/atoms/theme.ts:新增solarLocationAtom与solarIsDaytimeAtom;resolvedThemeAtom增加 solar 分支;applyThemeToDOM增加 solar 分支;initializeTheme加载并监听位置;新增updateSolarLocationrenderer/main.tsx:ThemeInitializer增加 solar 模式每分钟轮询(首次立即执行 +visibilitychange监听,窗口从睡眠/后台恢复时即时刷新),写入solarIsDaytimeAtom驱动resolvedThemeAtom重算,使 diff/toast 等消费方配色同步切换renderer/components/settings/AppearanceSettings.tsx:THEME_OPTIONS增加「日出日落」;新增SolarLocationPicker(城市搜索 + 选择 + 今日日出日落时刻 + 下次切换预览)main/ipc.ts/preload/index.ts:主题设置广播的条件与 payload 增加solarLocation,跨窗口(如 Quick Task 面板)同步位置测试
bun run typecheck全包通过bun run dev启动开发版,设置 → 外观 → 主题模式选「日出日落」→ 选择城市(如北京)→ 验证当前白天切浅色 / 夜晚切深色solarLocation持久化与主题恢复紧急度
常规
备注
Closes #1057
位置获取采用纯手动选城市(零体积、零隐私外发、一次配置)。IP 库自动定位、旅行换网络自动重定位等增强留作后续 PR。