Skip to content

Follow system theme - #45

Merged
Tkaixiang merged 7 commits into
Tkaixiang:trunkfrom
vredesbyyrd:separate-theme-dark-mode
Dec 4, 2025
Merged

Tkaixiang merged 7 commits into
Tkaixiang:trunkfrom
vredesbyyrd:separate-theme-dark-mode

Conversation

@vredesbyyrd

Copy link
Copy Markdown

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

  • Separate theme selection: Choose any theme for light mode and any theme for dark mode (e.g., Graphite + Material Dark)
  • Immediate switching: Theme changes apply instantly when system theme changes or preferences are toggled
  • No startup flash: Fixed white flash on Linux by waiting for theme system to initialize
  • Better UX: Replaced confusing enum dropdown with simple toggle + dropdowns

Changes

  • Runtime theme switching now works without restart
  • Window background color matches selected theme from startup (no flash)

Config Migration

autoSwitchTheme preference replaced with followSystemTheme + lightModeTheme + darkModeTheme. Existing settings are automatically migrated.

Files Changed

Core files (8):

  • src/main/app/index.js - Theme switching logic

  • src/main/preferences/schema.json - New preferences

  • src/main/preferences/index.js - Migration logic

  • src/renderer/src/prefComponents/theme/config.js

  • src/renderer/src/prefComponents/theme/index.vue - UI

  • src/renderer/src/store/preferences.js - State management

  • static/preference.json - Defaults

Translation 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

…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)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 autoSwitchTheme settings 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.

Comment thread static/locales/en.json Resolved
Comment thread src/main/app/index.js Resolved
Comment thread src/main/app/index.js Resolved
Comment thread src/main/preferences/index.js Resolved
@vredesbyyrd

Copy link
Copy Markdown
Author

I'll take a closer look at this copilot review tomorrow and make any changes if necessary.

@Tkaixiang Tkaixiang left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

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 :)

Comment thread src/main/preferences/index.js Resolved
Comment thread src/main/app/index.js Resolved
Comment thread src/main/app/index.js Resolved
Comment thread src/main/app/index.js Resolved
Comment thread static/locales/en.json Resolved
Comment thread src/main/app/index.js Resolved
Comment thread src/main/app/index.js Resolved
- 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 Tkaixiang left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

LGTM, thank you for the prompt and to the crux changes 😄 . Merging this now

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.

3 participants