mirror of
https://github.com/electron/electron.git
synced 2026-02-26 03:01:17 -05:00
* feat: add nativeTheme.themeSource to allow apps to override Chromiums theme choice (#19960) * feat: add nativeTheme.shouldUseDarkColorsOverride to allow apps to override Chromiums theme choice * spec: add tests for shouldUseDarkColorsOverride * chore: add missing forward declarations * refactor: rename overrideShouldUseDarkColors to themeSource * chore: only run appLevelAppearance specs on Mojave and up * chore: update patch with more info and no define * Update spec-main/api-native-theme-spec.ts Co-Authored-By: Jeremy Apthorp <jeremya@chromium.org> * Update api-native-theme-spec.ts * Update api-native-theme-spec.ts * Update api-native-theme-spec.ts * fix: don't expose nativeTheme in the renderer process (#20139) Exposing these in the renderer didn't make sense as they weren't backed by the same instance / value store. This API should be browser only especially now that we have nativeTheme.themeSource. Exposing in //common was a mistake from the beginning. * fix: emit updated on NativeTheme on the UI thread to avoid DCHECK (#20137) * fix: emit updated on NativeTheme on the UI thread to avoid DCHECK * Update atom_api_native_theme.cc * spec: wait a few ticks for async events to emit so that test events do not leak into each other * chore: add SetGTKDarkThemeEnabled(enabled) internal helper to allow dynamic theme selection on linux (#19964) This is just a after-creation setter for the `darkTheme` constructor option. This is delibrately a method and not a property as there is no getter. * spec: remove leftover .only
79 lines
2.7 KiB
TypeScript
79 lines
2.7 KiB
TypeScript
import { expect } from 'chai'
|
|
import { nativeTheme, systemPreferences } from 'electron'
|
|
import * as os from 'os'
|
|
import * as semver from 'semver'
|
|
|
|
import { delay, ifdescribe } from './spec-helpers'
|
|
import { emittedOnce } from './events-helpers';
|
|
|
|
describe('nativeTheme module', () => {
|
|
describe('nativeTheme.shouldUseDarkColors', () => {
|
|
it('returns a boolean', () => {
|
|
expect(nativeTheme.shouldUseDarkColors).to.be.a('boolean')
|
|
})
|
|
})
|
|
|
|
describe('nativeTheme.themeSource', () => {
|
|
afterEach(async () => {
|
|
nativeTheme.themeSource = 'system'
|
|
// Wait for any pending events to emit
|
|
await delay(20)
|
|
})
|
|
|
|
it('is system by default', () => {
|
|
expect(nativeTheme.themeSource).to.equal('system')
|
|
})
|
|
|
|
it('should override the value of shouldUseDarkColors', () => {
|
|
nativeTheme.themeSource = 'dark'
|
|
expect(nativeTheme.shouldUseDarkColors).to.equal(true)
|
|
nativeTheme.themeSource = 'light'
|
|
expect(nativeTheme.shouldUseDarkColors).to.equal(false)
|
|
})
|
|
|
|
it('should emit the "updated" event when it is set and the resulting "shouldUseDarkColors" value changes', async () => {
|
|
let updatedEmitted = emittedOnce(nativeTheme, 'updated')
|
|
nativeTheme.themeSource = 'dark'
|
|
await updatedEmitted
|
|
updatedEmitted = emittedOnce(nativeTheme, 'updated')
|
|
nativeTheme.themeSource = 'light'
|
|
await updatedEmitted
|
|
})
|
|
|
|
it('should not emit the "updated" event when it is set and the resulting "shouldUseDarkColors" value is the same', async () => {
|
|
nativeTheme.themeSource = 'dark'
|
|
// Wait a few ticks to allow an async events to flush
|
|
await delay(20)
|
|
let called = false
|
|
nativeTheme.once('updated', () => {
|
|
called = true
|
|
})
|
|
nativeTheme.themeSource = 'dark'
|
|
// Wait a few ticks to allow an async events to flush
|
|
await delay(20)
|
|
expect(called).to.equal(false)
|
|
})
|
|
|
|
ifdescribe(process.platform === 'darwin' && semver.gte(os.release(), '18.0.0'))('on macOS 10.14', () => {
|
|
it('should update appLevelAppearance when set', () => {
|
|
nativeTheme.themeSource = 'dark'
|
|
expect(systemPreferences.appLevelAppearance).to.equal('dark')
|
|
nativeTheme.themeSource = 'light'
|
|
expect(systemPreferences.appLevelAppearance).to.equal('light')
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('nativeTheme.shouldUseInvertedColorScheme', () => {
|
|
it('returns a boolean', () => {
|
|
expect(nativeTheme.shouldUseInvertedColorScheme).to.be.a('boolean')
|
|
})
|
|
})
|
|
|
|
describe('nativeTheme.shouldUseHighContrastColors', () => {
|
|
it('returns a boolean', () => {
|
|
expect(nativeTheme.shouldUseHighContrastColors).to.be.a('boolean')
|
|
})
|
|
})
|
|
})
|