From e4449b88c56b69d6b50f18c4b3cf6afe584668cd Mon Sep 17 00:00:00 2001 From: Tim deBoer Date: Wed, 4 Sep 2024 09:28:43 -0400 Subject: [PATCH] chore: appearance key constant Compute constant once as suggested in review. Signed-off-by: Tim deBoer --- packages/main/src/plugin/appearance-init.spec.ts | 4 ++-- packages/main/src/plugin/appearance-init.ts | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/main/src/plugin/appearance-init.spec.ts b/packages/main/src/plugin/appearance-init.spec.ts index 83c4f54d9..8861511eb 100644 --- a/packages/main/src/plugin/appearance-init.spec.ts +++ b/packages/main/src/plugin/appearance-init.spec.ts @@ -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 @@ -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 diff --git a/packages/main/src/plugin/appearance-init.ts b/packages/main/src/plugin/appearance-init.ts index 6483f9598..8d4927e8a 100644 --- a/packages/main/src/plugin/appearance-init.ts +++ b/packages/main/src/plugin/appearance-init.ts @@ -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) {} @@ -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'], @@ -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); } });