refactor(platform-detection): add platform-detection.ts for browser and platform detection
This commit is contained in:
parent
c315d2dfcd
commit
393491e2c8
4 changed files with 24 additions and 13 deletions
13
js/app.js
13
js/app.js
|
|
@ -1,4 +1,5 @@
|
|||
//js/app.js
|
||||
import { isIos, isSafari } from './platform-detection.js';
|
||||
import { MusicAPI } from './music-api.js';
|
||||
import {
|
||||
apiSettings,
|
||||
|
|
@ -28,7 +29,6 @@ import { registerSW } from 'virtual:pwa-register';
|
|||
import { openEditProfile } from './profile.js';
|
||||
import { ThemeStore } from './themeStore.js';
|
||||
import './commandPalette.js';
|
||||
|
||||
import { initTracker } from './tracker.js';
|
||||
import {
|
||||
initAnalytics,
|
||||
|
|
@ -65,8 +65,6 @@ import {
|
|||
// Capture real iOS state before spoofing (needed for background audio)
|
||||
if (typeof window !== 'undefined') {
|
||||
const _ua = navigator.userAgent.toLowerCase();
|
||||
window.__IS_IOS__ = /iphone|ipad|ipod/.test(_ua) || (_ua.includes('mac') && navigator.maxTouchPoints > 1);
|
||||
|
||||
// Spoof User-Agent to bypass Google's embedded browser check
|
||||
Object.defineProperty(navigator, 'userAgent', {
|
||||
get: function () {
|
||||
|
|
@ -388,13 +386,8 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|||
const audioPlayer = document.getElementById('audio-player');
|
||||
|
||||
// i love ios and macos!!!! webkit fucking SUCKS BULLSHIT sorry ios/macos heads yall getting lossless only
|
||||
// Use window.__IS_IOS__ (set before UA spoof in index.html) so detection works on real iOS.
|
||||
const isIOS = typeof window !== 'undefined' && window.__IS_IOS__ === true;
|
||||
const ua = navigator.userAgent.toLowerCase();
|
||||
const isSafari =
|
||||
ua.includes('safari') && !ua.includes('chrome') && !ua.includes('crios') && !ua.includes('android');
|
||||
|
||||
if (isIOS || isSafari) {
|
||||
// Use isIos from platform-detection (set before UA spoof in index.html) so detection works on real iOS.
|
||||
if (isIos || isSafari) {
|
||||
const qualitySelect = document.getElementById('streaming-quality-setting');
|
||||
const downloadSelect = document.getElementById('download-quality-setting');
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
// Shared Audio Context Manager - handles EQ and provides context for visualizer
|
||||
// Supports 3-32 parametric EQ bands
|
||||
|
||||
import { isIos } from './platform-detection.js';
|
||||
import { equalizerSettings, monoAudioSettings } from './storage.js';
|
||||
|
||||
// Generate frequency array for given number of bands using logarithmic spacing
|
||||
|
|
@ -300,8 +301,7 @@ class AudioContextManager {
|
|||
this.audio = audioElement;
|
||||
|
||||
// Detect iOS - skip Web Audio initialization on iOS to avoid lock screen audio issues
|
||||
const isIOS = typeof window !== 'undefined' && window.__IS_IOS__ === true;
|
||||
if (isIOS) {
|
||||
if (isIos) {
|
||||
console.log('[AudioContext] Skipping Web Audio initialization on iOS for lock screen compatibility');
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
17
js/platform-detection.ts
Normal file
17
js/platform-detection.ts
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
/** The original user agent string before spoofing. */
|
||||
export const originalUserAgent = navigator.userAgent;
|
||||
|
||||
/** A lowercase version of the original user agent string. */
|
||||
const lowerCaseOriginalUserAgent = originalUserAgent.toLowerCase();
|
||||
|
||||
/** If the device is an iOS device. */
|
||||
export const isIos =
|
||||
/iphone|ipad|ipod/.test(lowerCaseOriginalUserAgent) ||
|
||||
(lowerCaseOriginalUserAgent.includes('mac') && navigator.maxTouchPoints > 1);
|
||||
|
||||
/** If the browser is Safari (excluding Chrome, Chromium-based browsers, and Android browsers). */
|
||||
export const isSafari =
|
||||
lowerCaseOriginalUserAgent.includes('safari') &&
|
||||
!lowerCaseOriginalUserAgent.includes('chrome') &&
|
||||
!lowerCaseOriginalUserAgent.includes('crios') &&
|
||||
!lowerCaseOriginalUserAgent.includes('android');
|
||||
|
|
@ -21,6 +21,7 @@ import {
|
|||
import { audioContextManager } from './audio-context.js';
|
||||
import { db } from './db.js';
|
||||
import Hls from 'hls.js';
|
||||
import { isIos } from './platform-detection.js';
|
||||
|
||||
export class Player {
|
||||
constructor(audioElement, api, quality = 'HI_RES_LOSSLESS') {
|
||||
|
|
@ -42,7 +43,7 @@ export class Player {
|
|||
this.isFallbackRetry = false;
|
||||
this.isFallbackInProgress = false;
|
||||
this.autoplayBlocked = false;
|
||||
this.isIOS = typeof window !== 'undefined' && window.__IS_IOS__ === true;
|
||||
this.isIOS = isIos;
|
||||
this.isPwa =
|
||||
typeof window !== 'undefined' &&
|
||||
(window.matchMedia?.('(display-mode: standalone)')?.matches || window.navigator?.standalone === true);
|
||||
|
|
|
|||
Loading…
Reference in a new issue