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
4 changes: 2 additions & 2 deletions src/services/web-audio-api.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ class WebAudioApiService {
const audioSounds = Object.values(AUDIO_SOUND);
const matchingAudioSound = audioSounds.find(({ ID }) => ID === id);

if (!matchingAudioSound) {
if (matchingAudioSound === undefined) {
// Fallback to default if sound not found
return this.playSound(audioSounds[0].ID, volume);
return this.playSound(DEFAULT_SETTINGS.audioSound, volume);
}

try {
Expand Down
20 changes: 3 additions & 17 deletions src/stores/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import LocalStorageService from '../services/local-storage.service.js';
import {
BROWSER,
CLIENT_ERROR_MESSAGE,
STORAGE_KEY_NAMESPACE,
} from '../utils/constants.js';
Expand All @@ -9,7 +10,7 @@ class AppStore {
/** @type {string} */
#visitedStorageKey = 'visited';
/** @type {import("../index.d.js").UserAgent} */
#userAgent = 'unknown';
#userAgent = BROWSER.UNKNOWN;
/** @type {boolean} */
#hasUserVisited = true;

Expand All @@ -22,22 +23,7 @@ class AppStore {
this.#hasUserVisited =
hasUserVisitedValue !== null ? Boolean(hasUserVisitedValue) : false;

const userAgent = detectUserAgent();
if (
[
'chrome',
'chromium',
'edge',
'firefox',
'opera',
'safari',
'seamonkey',
].includes(userAgent)
) {
this.#userAgent = userAgent;
} else {
this.#userAgent = 'unknown';
}
this.#userAgent = detectUserAgent();
}

get visitedStorageKey() {
Expand Down
13 changes: 13 additions & 0 deletions src/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ const AUDIO_VOLUME = Object.freeze({
ONE_HUNDRED_PERCENT: 100,
});

/** @type {Readonly<Record<string, import("../index.d.js").UserAgent>>} */
const BROWSER = Object.freeze({
CHROME: 'chrome',
CHROMIUM: 'chromium',
EDGE: 'edge',
FIREFOX: 'firefox',
OPERA: 'opera',
SAFARI: 'safari',
SEAMONKEY: 'seamonkey',
UNKNOWN: 'unknown',
});

const CLIENT_ERROR_MESSAGE = Object.freeze({
STORAGE_INVALID: 'Storage invalid.',
STORAGE_NAMESPACE_INVALID: 'Storage namespace invalid.',
Expand Down Expand Up @@ -191,6 +203,7 @@ export {
APP_EVENT,
AUDIO_SOUND,
AUDIO_VOLUME,
BROWSER,
CLIENT_ERROR_MESSAGE,
EXERCISES_BY_CATEGORY_MAP,
EXERCISE_CATEGORY,
Expand Down
21 changes: 13 additions & 8 deletions src/utils/detectUserAgent.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,39 @@
import { BROWSER } from './constants.js';

/** @returns {import("../index.d.js").UserAgent} */
function detectUserAgent() {
const userAgent = window.navigator.userAgent;
switch (true) {
case userAgent.includes('Firefox/') && !userAgent.includes('Seamonkey/'):
return 'firefox';
return BROWSER.FIREFOX;

case userAgent.includes('Seamonkey/'):
return 'seamonkey';
return BROWSER.SEAMONKEY;

case userAgent.includes('Chrome/') &&
!userAgent.includes('Chromium/') &&
!userAgent.includes('Edg/'):
return 'chrome';
return BROWSER.CHROME;

case userAgent.includes('Chromium/'):
return 'chromium';
return BROWSER.CHROMIUM;

case userAgent.includes('Edg/'):
return BROWSER.EDGE;

case userAgent.includes('Safari/') &&
!userAgent.includes('Chrome/') &&
!userAgent.includes('Chromium/'):
return 'safari';
return BROWSER.SAFARI;

case userAgent.includes('OPR/'):
return 'opera';
return BROWSER.OPERA;

case userAgent.includes('Opera/'):
return 'opera';
return BROWSER.OPERA;

default:
return 'unknown';
return BROWSER.UNKNOWN;
}
}

Expand Down
Loading