Repository navigation
Follow system theme - #45
Conversation
…e toggle
Replace the "Auto switch theme" enum dropdown with a simpler "Follow system theme"
boolean toggle and fix runtime theme switching bug.
BREAKING CHANGE: `autoSwitchTheme` preference replaced with `followSystemTheme`.
Old settings are automatically migrated (0 → true, 2 → false).
Changes:
- Replace dropdown UI with toggle switch (Bool component)
- Rename autoSwitchTheme → followSystemTheme (enum → boolean)
- Fix runtime switching: set nativeTheme.themeSource = 'system'
- Add nativeTheme.on('updated') listener for theme change detection
- Add migration logic for existing users
- Update all 9 locale files with new translation keys (claude ai translation, needs confirmation)
Benefits:
- Runtime theme switching works without restart
- Clearer UX
Files changed: 15 files (8 core + 7 locales)
Tested on: Linux/Arch (Niri/Wayland), Windows 11, Node.js 22.19.0
Fix two issues with the followSystemTheme feature: 1. White flash on startup: Wait for nativeTheme.shouldUseDarkColors to settle before creating windows (with 150ms timeout fallback for cases where 'updated' event doesn't fire). 2. Toggle takes effect immediately: Apply system theme when user enables followSystemTheme without requiring restart. Changes: - Delay window creation when followSystemTheme enabled until theme is ready - Apply system theme immediately when followSystemTheme toggled on NOTE: Reading the Electron theme documentation, I can not find a better way of preventing the "white flash", but I very well could be missing something. Personally, I do not see/feel any delay, and I would prefer an imperceptible delay if it prevents a white flash bomb. Tested on: Linux/Arch (Niri/Wayland)
Allow users to select different themes for light and dark system modes. When "Use separate theme in dark mode" is enabled, users can choose any theme for light mode (e.g., Graphite) and any theme for dark mode (e.g., Material Dark). Themes switch automatically when system theme changes. Changes: - Add lightModeTheme and darkModeTheme preferences with dropdown selectors - Apply theme changes immediately when preferences are toggled or changed - Fix theme card overflow by using outline instead of border, hmm. - Update 9 translation files (de, en, es, fr, ja, ko, pt, zh-CN, zh-TW) Files changed: 15 (schema, preferences, app logic, Vue components, store, translations) Tested on: Linux/Arch (Niri/Wayland)
There was a problem hiding this comment.
Pull request overview
This PR implements a "Follow system theme" feature for MarkText, replacing the previous enum-based autoSwitchTheme setting with a more intuitive boolean toggle (followSystemTheme) and separate theme selections for light and dark modes (lightModeTheme and darkModeTheme). Users can now select different themes for each mode (e.g., Graphite for light mode and Material Dark for dark mode), with automatic switching when the system theme changes.
Key changes:
- Runtime theme switching without application restart
- Separate theme preferences for light and dark system modes
- Migration logic to convert old
autoSwitchThemesettings to the new structure
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
src/main/app/index.js |
Implements core theme switching logic with system theme listener and startup delay mechanism to prevent flash |
src/main/preferences/schema.json |
Replaces autoSwitchTheme enum with boolean followSystemTheme and string-based lightModeTheme/darkModeTheme |
src/main/preferences/index.js |
Adds migration logic from old enum-based setting to new boolean + theme preferences |
src/renderer/src/prefComponents/theme/config.js |
Removes deprecated getAutoSwitchThemeOptions function |
src/renderer/src/prefComponents/theme/index.vue |
Updates UI with boolean toggle and conditional theme dropdowns with disabled states |
src/renderer/src/store/preferences.js |
Updates state to use new preference keys |
static/preference.json |
Sets default values for new preferences |
static/locales/*.json (9 files) |
Updates translations for all supported languages |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
I'll take a closer look at this copilot review tomorrow and make any changes if necessary. |
Co-authored-by: Copilot <[email protected]>
Tkaixiang
left a comment
There was a problem hiding this comment.
Hey, thank you so much for this PR. I have consolidated all the comments here so there is no need to look at the GPT ones.
Overall, great job, just a few nitpicks and edge cases :)
- Prevent duplicate listener registration: Add flag to register nativeTheme listener only once (prevents multiple registrations on macOS) - Remove unused isDarkMode variable (updated but never read) - createWindow: Declare once outside if/else to avoid duplication - Optimize condition ordering: Check followSystemTheme before theme changes (short-circuit optimization) - Platform-specific startup delay: Change from followSystemTheme check to isLinux check (white flash only occurs on Linux regardless of setting) - Generate theme dropdown options from config to avoid duplication - Update translations: Change to "Follow System Theme" for clarity - Remove duplicate customCss key in translation files - Remove config migration code, sane defaults suffice. - Change default: Set followSystemTheme to true (existing cleanup code handles removal of deprecated autoSwitchTheme setting) Files changed: 3 core files, 9 locale files, 1 static config
Tkaixiang
left a comment
There was a problem hiding this comment.
LGTM, thank you for the prompt and to the crux changes 😄 . Merging this now
Follow system theme, Light/Dark Mode Theme Selection
Summary
Adds the ability to select different themes for light and dark system modes, with automatic switching when the system theme changes. This replaces the previous "Auto switch theme" dropdown with a more intuitive toggle and separate theme selectors. Fixes #42
Features
Changes
Config Migration
autoSwitchThemepreference replaced withfollowSystemTheme+lightModeTheme+darkModeTheme. Existing settings are automatically migrated.Files Changed
Core files (8):
src/main/app/index.js- Theme switching logicsrc/main/preferences/schema.json- New preferencessrc/main/preferences/index.js- Migration logicsrc/renderer/src/prefComponents/theme/config.jssrc/renderer/src/prefComponents/theme/index.vue- UIsrc/renderer/src/store/preferences.js- State managementstatic/preference.json- DefaultsTranslation files (9):
de, en, es, fr, ja, ko, pt, zh-CN, zh-TW
Testing
Tested on Linux/Arch (Niri) and minimal testing in Windows 11 vm. Needs testing on OSX
NOTE
Javascript is not a strength of mine! The minimal programming I do is usually lua, python and a little golang. So code quality might be lacking. But after a fair amount of testing on linux this appears to work well and really would be a net positive to marktext imho. The option to follow the system theme without a restart is a standard in most programs nowadays. All non-english translation files were done with claude, so no guarantees regarding accuracy.
screenrecord.mp4