Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lower-default-sound-volume.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'elden-ring-github': patch
---

Lower the default sound volume from 100% to 30% so the banner sound isn't jarring on first install
5 changes: 3 additions & 2 deletions src/content/banner.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { renderBanner, type BannerType } from './banner';
import { DEFAULT_SOUND_VOLUME } from '../types/settings';

describe('renderBanner', () => {
const soundUrl = 'chrome-extension://mock/sound.mp3';
Expand Down Expand Up @@ -112,7 +113,7 @@ describe('renderBanner', () => {
expect(onHide).toHaveBeenCalled();
});

it('defaults audio volume to 1 when soundVolume is not provided', () => {
it('falls back to the default volume when soundVolume is not provided', () => {
renderBanner({
type: 'merged',
soundUrl,
Expand All @@ -121,7 +122,7 @@ describe('renderBanner', () => {
});

expect(audioInstances).toHaveLength(1);
expect(audioInstances[0]!.volume).toBe(1);
expect(audioInstances[0]!.volume).toBe(DEFAULT_SOUND_VOLUME);
});

it.each([
Expand Down
3 changes: 2 additions & 1 deletion src/content/banner.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { generateBandDataUrl, generateSheenDataUrl, generateCaptionDataUrl } from './eldenBanner';
import { resolveBannerTheme } from './bannerThemes';
import { resolveCaption } from '../types/captions';
import { DEFAULT_SOUND_VOLUME } from '../types/settings';

export type BannerType = 'merged' | 'created' | 'approved' | 'closed';

Expand Down Expand Up @@ -61,7 +62,7 @@ export const renderBanner = ({

if (soundEnabled) {
const audio = new Audio(soundUrl);
audio.volume = Math.min(1, Math.max(0, soundVolume ?? 1));
audio.volume = Math.min(1, Math.max(0, soundVolume ?? DEFAULT_SOUND_VOLUME));
audio.play().catch((err) => console.log('Sound playback failed:', err));
}

Expand Down
4 changes: 2 additions & 2 deletions src/content/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import {
type GitHubFeature,
} from './features';
import { ShowSettings, type SettingsState } from './showSettings';
import type { SoundType } from '../types/settings';
import { DEFAULT_SOUND_VOLUME, type SoundType } from '../types/settings';
import { CAPTION_STORAGE_KEYS } from '../types/captions';

class EldenRingOrchestrator {
private bannerShown: boolean = false;
private soundEnabled: boolean = true;
private soundType: SoundType = 'you-die-sound';
private soundVolume: number = 1;
private soundVolume: number = DEFAULT_SOUND_VOLUME;
private soundUrl: string;
private captions: SettingsState = {} as SettingsState;
private features: GitHubFeature[] = [];
Expand Down
10 changes: 7 additions & 3 deletions src/content/showSettings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { SoundType } from '../types/sounds';
import type { CaptionSettings } from '../types/captions';
import { DEFAULT_SOUND_VOLUME } from '../types/settings';

export interface SettingsState extends CaptionSettings {
soundEnabled: boolean;
Expand Down Expand Up @@ -28,7 +29,7 @@ const STATE_KEY_MAP: Record<ShowSettingKey, keyof ShowSettingsFlags> = {
const defaultState: SettingsState = {
soundEnabled: true,
soundType: 'you-die-sound',
soundVolume: 1,
soundVolume: DEFAULT_SOUND_VOLUME,
showOnPRMerged: true,
showOnPRCreate: true,
showOnPRApprove: true,
Expand Down Expand Up @@ -68,7 +69,8 @@ export class ShowSettings {
this.state = {
soundEnabled: result.soundEnabled !== false,
soundType: result.soundType || 'you-die-sound',
soundVolume: typeof result.soundVolume === 'number' ? result.soundVolume : 1,
soundVolume:
typeof result.soundVolume === 'number' ? result.soundVolume : DEFAULT_SOUND_VOLUME,
showOnPRMerged: result.showOnPRMerged !== false,
showOnPRCreate: result.showOnPRCreate !== false,
showOnPRApprove: result.showOnPRApprove !== false,
Expand Down Expand Up @@ -96,7 +98,9 @@ export class ShowSettings {
}
if (changes.soundVolume) {
nextState.soundVolume =
typeof changes.soundVolume.newValue === 'number' ? changes.soundVolume.newValue : 1;
typeof changes.soundVolume.newValue === 'number'
? changes.soundVolume.newValue
: DEFAULT_SOUND_VOLUME;
updated = true;
}
if (changes.showOnPRMerged) {
Expand Down
7 changes: 4 additions & 3 deletions src/popup/useSettings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useState } from 'preact/hooks';
import type { EldenRingSettings, SoundType } from '../types/settings';
import { DEFAULT_SOUND_VOLUME, type EldenRingSettings, type SoundType } from '../types/settings';

export interface PopupSettings {
showOnPRMerged: boolean;
Expand All @@ -22,7 +22,7 @@ export const DEFAULT_SETTINGS: PopupSettings = {
showOnPRApprove: true,
showOnPRClose: true,
soundEnabled: true,
soundVolume: 1,
soundVolume: DEFAULT_SOUND_VOLUME,
soundType: 'you-die-sound',
duration: 5000,
captionMerged: '',
Expand Down Expand Up @@ -67,7 +67,8 @@ export const useSettings = () => {
showOnPRApprove: result.showOnPRApprove !== false,
showOnPRClose: result.showOnPRClose !== false,
soundEnabled: result.soundEnabled !== false,
soundVolume: typeof result.soundVolume === 'number' ? result.soundVolume : 1,
soundVolume:
typeof result.soundVolume === 'number' ? result.soundVolume : DEFAULT_SOUND_VOLUME,
soundType: (result.soundType as SoundType) || 'you-die-sound',
duration: typeof result.duration === 'number' ? result.duration : 5000,
captionMerged: result.captionMerged ?? '',
Expand Down
3 changes: 3 additions & 0 deletions src/types/settings.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import type { SoundType } from './sounds';
import type { CaptionSettings } from './captions';

/** Default playback volume (0..1) when the user hasn't set one. */
export const DEFAULT_SOUND_VOLUME = 0.3;

export interface EldenRingSettings extends CaptionSettings {
showOnPRMerged?: boolean;
soundEnabled?: boolean;
Expand Down
Loading