Skip to content

Commit

Permalink
chore: appearance key constant
Browse files Browse the repository at this point in the history
Compute constant once as suggested in review.

Signed-off-by: Tim deBoer <[email protected]>
  • Loading branch information
deboer-tim committed Sep 6, 2024
1 parent 68b40e2 commit e4449b8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/main/src/plugin/appearance-init.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ test('Expect appearance configuration change to update native theme', async () =

expect(spyOnDidChange).toHaveBeenCalled();
// grab the anonymous function that is the first argument of the first call
const callback = spyOnDidChange.mock.calls[0][0];
const callback = spyOnDidChange.mock.calls[0]?.[0];
expect(callback).toBeDefined();

// call the callback
Expand All @@ -75,7 +75,7 @@ test('Expect unrelated configuration change not to update native theme', async (

expect(spyOnDidChange).toHaveBeenCalled();
// grab the anonymous function that is the first argument of the first call
const callback = spyOnDidChange.mock.calls[0][0];
const callback = spyOnDidChange.mock.calls[0]?.[0];
expect(callback).toBeDefined();

// call the callback
Expand Down
6 changes: 4 additions & 2 deletions packages/main/src/plugin/appearance-init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { nativeTheme } from 'electron';
import { AppearanceSettings } from './appearance-settings.js';
import type { IConfigurationNode, IConfigurationRegistry } from './configuration-registry.js';

const APPEARANCE_FULL_KEY = `${AppearanceSettings.SectionName}.${AppearanceSettings.Appearance}`;

export class AppearanceInit {
constructor(private configurationRegistry: IConfigurationRegistry) {}

Expand All @@ -30,7 +32,7 @@ export class AppearanceInit {
title: 'Appearance',
type: 'object',
properties: {
[AppearanceSettings.SectionName + '.' + AppearanceSettings.Appearance]: {
[APPEARANCE_FULL_KEY]: {
description: 'Select between light or dark mode, or use your system setting.',
type: 'string',
enum: ['system', 'dark', 'light'],
Expand All @@ -42,7 +44,7 @@ export class AppearanceInit {
this.configurationRegistry.registerConfigurations([appearanceConfiguration]);

this.configurationRegistry.onDidChangeConfiguration(async e => {
if (e.key === AppearanceSettings.SectionName + '.' + AppearanceSettings.Appearance) {
if (e.key === APPEARANCE_FULL_KEY) {
this.updateNativeTheme(e.value);
}
});
Expand Down

0 comments on commit e4449b8

Please sign in to comment.