index.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //全局变量
  2. import './Global';
  3. import React from 'react';
  4. import ReactDOM from 'react-dom/client';
  5. import App from './App';
  6. import { BrowserRouter } from 'react-router-dom';
  7. import { ThemeProvider } from '@contexts/themeContext';
  8. import { ShopProvider } from '@contexts/shopContext';
  9. import { Provider } from 'react-redux';
  10. import store from './app/store';
  11. import * as Sentry from "@sentry/react";
  12. import { Capacitor } from '@capacitor/core';
  13. import { TextZoom } from '@capacitor/text-zoom';
  14. import { installClientErrorLogging } from '@utils/clientLog';
  15. installClientErrorLogging();
  16. // Explicitly retain the current v6 behaviour while silencing the opt-in notices.
  17. // Revisit these flags together with the eventual React Router v7 migration.
  18. const routerFuture = {
  19. v7_startTransition: false,
  20. v7_relativeSplatPath: false,
  21. };
  22. if (!Capacitor.isNativePlatform()) {
  23. // 只有在纯浏览器/PWA 才注册 SW
  24. window.addEventListener('load', () => {
  25. navigator.serviceWorker?.register('/service-worker.js')
  26. .catch(err => console.error('SW register failed', err));
  27. });
  28. }
  29. else
  30. {
  31. TextZoom.set({ value: 1 });
  32. }
  33. global.dispatch = store.dispatch;
  34. Sentry.init({
  35. dsn: "https://4686ef0d926e140fb482e63efcde1cdf@o4507102375641088.ingest.us.sentry.io/4507102380687360",
  36. integrations: [
  37. Sentry.browserTracingIntegration(),
  38. Sentry.feedbackIntegration({
  39. // Additional SDK configuration goes in here, for example:
  40. colorScheme: "dark",
  41. autoInject: false,
  42. isEmailRequired: true,
  43. }),
  44. ],
  45. sampleRate: 0.02,
  46. tracesSampleRate: 0.001,
  47. replaysSessionSampleRate: 0,
  48. replaysOnErrorSampleRate: 0.01,
  49. beforeSend(event) {
  50. const level = event.level || "error";
  51. if (level !== "error" && level !== "fatal") return null;
  52. const exception = event.exception?.values?.[0];
  53. if (!exception) return null;
  54. const handled = exception.mechanism?.handled;
  55. if (handled === true) return null;
  56. return event;
  57. },
  58. });
  59. const root = ReactDOM.createRoot(document.getElementById('root'));
  60. root.render(
  61. <Provider store={store}>
  62. <BrowserRouter future={routerFuture}>
  63. <ThemeProvider>
  64. <ShopProvider>
  65. <App />
  66. </ShopProvider>
  67. </ThemeProvider>
  68. </BrowserRouter>
  69. </Provider>
  70. );