From 6be445cc7598abf9e2aa4029a8810888659aa3a7 Mon Sep 17 00:00:00 2001 From: kepper104 <67190416+kepper104@users.noreply.github.com> Date: Thu, 14 Nov 2024 17:19:49 +0300 Subject: [PATCH 1/3] Refactor getDeviceName() for readability Refactored a long if-else into a cleaner, easier to extend mapping --- CONTRIBUTORS.md | 1 + src/components/apphost.js | 63 +++++++++++++++++++-------------------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 4e5e14b87386..f73bfe3d4e1c 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -93,6 +93,7 @@ - [Connor Smith](https://github.com/ConnorS1110) - [iFraan](https://github.com/iFraan) - [Ali](https://github.com/bu3alwa) +- [K. Kyle Puchkov](https://github.com/kepper104) ## Emby Contributors diff --git a/src/components/apphost.js b/src/components/apphost.js index b92bb6faa082..8abd300728f2 100644 --- a/src/components/apphost.js +++ b/src/components/apphost.js @@ -132,42 +132,41 @@ function getDeviceId() { } function getDeviceName() { - if (!deviceName) { - if (browser.tizen) { - deviceName = 'Samsung Smart TV'; - } else if (browser.web0s) { - deviceName = 'LG Smart TV'; - } else if (browser.operaTv) { - deviceName = 'Opera TV'; - } else if (browser.xboxOne) { - deviceName = 'Xbox One'; - } else if (browser.ps4) { - deviceName = 'Sony PS4'; - } else if (browser.chrome) { - deviceName = 'Chrome'; - } else if (browser.edgeChromium) { - deviceName = 'Edge Chromium'; - } else if (browser.edge) { - deviceName = 'Edge'; - } else if (browser.firefox) { - deviceName = 'Firefox'; - } else if (browser.opera) { - deviceName = 'Opera'; - } else if (browser.safari) { - deviceName = 'Safari'; - } else { - deviceName = 'Web Browser'; - } + if (deviceName) { + return deviceName; + } + + const deviceMappings = { + tizen: 'Samsung Smart TV', + web0s: 'LG Smart TV', + operaTv: 'Opera TV', + xboxOne: 'Xbox One', + ps4: 'Sony PS4', + chrome: 'Chrome', + edgeChromium: 'Edge Chromium', + edge: 'Edge', + firefox: 'Firefox', + opera: 'Opera', + safari: 'Safari', + }; + + deviceName = 'Web Browser'; // Default device name - if (browser.ipad) { - deviceName += ' iPad'; - } else if (browser.iphone) { - deviceName += ' iPhone'; - } else if (browser.android) { - deviceName += ' Android'; + for (const key in deviceMappings) { + if (browser[key]) { + deviceName = deviceMappings[key]; + break; } } + if (browser.ipad) { + deviceName += ' iPad'; + } else if (browser.iphone) { + deviceName += ' iPhone'; + } else if (browser.android) { + deviceName += ' Android'; + } + return deviceName; } From 9f0d93fdcaeb8ce8f1d45743426ec0ba8820e03a Mon Sep 17 00:00:00 2001 From: "K. Kyle Puchkov" Date: Thu, 14 Nov 2024 17:33:55 +0300 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/components/apphost.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/components/apphost.js b/src/components/apphost.js index 8abd300728f2..707a87986057 100644 --- a/src/components/apphost.js +++ b/src/components/apphost.js @@ -135,7 +135,6 @@ function getDeviceName() { if (deviceName) { return deviceName; } - const deviceMappings = { tizen: 'Samsung Smart TV', web0s: 'LG Smart TV', @@ -147,7 +146,7 @@ function getDeviceName() { edge: 'Edge', firefox: 'Firefox', opera: 'Opera', - safari: 'Safari', + safari: 'Safari' }; deviceName = 'Web Browser'; // Default device name @@ -166,7 +165,6 @@ function getDeviceName() { } else if (browser.android) { deviceName += ' Android'; } - return deviceName; } From a4ca63c8496775d4e742df23d4850f0128a953df Mon Sep 17 00:00:00 2001 From: kepper104 <67190416+kepper104@users.noreply.github.com> Date: Fri, 22 Nov 2024 02:02:26 +0300 Subject: [PATCH 3/3] Move BrowserName to the top of the file Renamed deviceMappings to BrowserName and moved it under the appName declaration as requested --- src/components/apphost.js | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/components/apphost.js b/src/components/apphost.js index 707a87986057..984c3a77bf68 100644 --- a/src/components/apphost.js +++ b/src/components/apphost.js @@ -8,6 +8,20 @@ import profileBuilder from '../scripts/browserDeviceProfile'; const appName = 'Jellyfin Web'; +const BrowserName = { + tizen: 'Samsung Smart TV', + web0s: 'LG Smart TV', + operaTv: 'Opera TV', + xboxOne: 'Xbox One', + ps4: 'Sony PS4', + chrome: 'Chrome', + edgeChromium: 'Edge Chromium', + edge: 'Edge', + firefox: 'Firefox', + opera: 'Opera', + safari: 'Safari' +}; + function getBaseProfileOptions(item) { const disableHlsVideoAudioCodecs = []; @@ -135,25 +149,12 @@ function getDeviceName() { if (deviceName) { return deviceName; } - const deviceMappings = { - tizen: 'Samsung Smart TV', - web0s: 'LG Smart TV', - operaTv: 'Opera TV', - xboxOne: 'Xbox One', - ps4: 'Sony PS4', - chrome: 'Chrome', - edgeChromium: 'Edge Chromium', - edge: 'Edge', - firefox: 'Firefox', - opera: 'Opera', - safari: 'Safari' - }; deviceName = 'Web Browser'; // Default device name - for (const key in deviceMappings) { + for (const key in BrowserName) { if (browser[key]) { - deviceName = deviceMappings[key]; + deviceName = BrowserName[key]; break; } }