mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-03-30 19:08:48 +00:00
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>
46 lines
1.5 KiB
JavaScript
Executable file
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);
|
|
});
|
|
});
|
|
}
|