stremio-web/src/index.js
Ignacio Lizana 57571cf1fc
fix: Handle boolean value for SERVICE_WORKER_DISABLED
The `webpack.EnvironmentPlugin` provides the default value for `SERVICE_WORKER_DISABLED` as a boolean (`false`).

The previous implementation only checked for the string `'true'`, which would fail to correctly identify the boolean `true` case, causing the feature to not work as intended when the variable was set without being explicitly a string.

This commit updates the conditional check to handle both the boolean `true` and the string `'true'` to ensure the service worker is reliably disabled.

Co-authored-by: Tim <tymmesyde@gmail.com>
2025-10-07 17:44:23 +02:00

46 lines
1.5 KiB
JavaScript
Executable file

// Copyright (C) 2017-2023 Smart code 203358507
if (typeof process.env.SENTRY_DSN === 'string') {
const Sentry = require('@sentry/browser');
Sentry.init({ dsn: process.env.SENTRY_DSN });
}
const Bowser = require('bowser');
const browser = Bowser.parse(window.navigator?.userAgent || '');
if (browser?.platform?.type === 'desktop') {
document.querySelector('meta[name="viewport"]')?.setAttribute('content', '');
}
const React = require('react');
const ReactDOM = require('react-dom/client');
const i18n = require('i18next');
const { initReactI18next } = require('react-i18next');
const stremioTranslations = require('stremio-translations');
const App = require('./App');
const translations = Object.fromEntries(Object.entries(stremioTranslations()).map(([key, value]) => [key, {
translation: value
}]));
i18n
.use(initReactI18next)
.init({
resources: translations,
lng: 'en-US',
fallbackLng: 'en-US',
interpolation: {
escapeValue: false
}
});
const root = ReactDOM.createRoot(document.getElementById('app'));
root.render(<App />);
if (process.env.NODE_ENV === 'production' && process.env.SERVICE_WORKER_DISABLED !== 'true' && process.env.SERVICE_WORKER_DISABLED !== true && 'serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker.register('service-worker.js')
.catch((registrationError) => {
console.error('SW registration failed: ', registrationError);
});
});
}