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
This commit is contained in:
parent
137622931b
commit
0d16be9560
10 changed files with 294 additions and 3 deletions
|
@ -1,5 +1,9 @@
|
|||
import { expect } from 'chai'
|
||||
import { nativeTheme } from 'electron'
|
||||
import { nativeTheme, systemPreferences } from 'electron'
|
||||
import * as os from 'os'
|
||||
import * as semver from 'semver'
|
||||
|
||||
import { ifdescribe } from './spec-helpers'
|
||||
|
||||
describe('nativeTheme module', () => {
|
||||
describe('nativeTheme.shouldUseDarkColors', () => {
|
||||
|
@ -8,6 +12,52 @@ describe('nativeTheme module', () => {
|
|||
})
|
||||
})
|
||||
|
||||
describe('nativeTheme.themeSource', () => {
|
||||
afterEach(() => {
|
||||
nativeTheme.themeSource = 'system'
|
||||
})
|
||||
|
||||
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', () => {
|
||||
nativeTheme.themeSource = 'dark'
|
||||
let called = false
|
||||
nativeTheme.once('updated', () => {
|
||||
called = true
|
||||
})
|
||||
nativeTheme.themeSource = 'light'
|
||||
expect(called).to.equal(true)
|
||||
})
|
||||
|
||||
it('should not emit the "updated" event when it is set and the resulting "shouldUseDarkColors" value is the same', () => {
|
||||
nativeTheme.themeSource = 'dark'
|
||||
let called = false
|
||||
nativeTheme.once('updated', () => {
|
||||
called = true
|
||||
})
|
||||
nativeTheme.themeSource = 'dark'
|
||||
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')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue