mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2025-11-16 01:21:16 +01:00
# Description of Changes <!-- Please provide a summary of the changes, including: - What was changed - Why the change was made - Any challenges encountered Closes #(issue_number) --> --- ## Checklist ### General - [ ] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md) (if applicable) - [ ] I have performed a self-review of my own code - [ ] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [ ] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md#6-testing) for more details.
70 lines
2.2 KiB
TypeScript
70 lines
2.2 KiB
TypeScript
import '@mantine/core/styles.css';
|
|
import '@mantine/dates/styles.css';
|
|
import '../vite-env.d.ts';
|
|
import './index.css'; // Import Tailwind CSS
|
|
import React from 'react';
|
|
import ReactDOM from 'react-dom/client';
|
|
import { ColorSchemeScript } from '@mantine/core';
|
|
import { BrowserRouter } from 'react-router-dom';
|
|
import App from './App';
|
|
import './i18n'; // Initialize i18next
|
|
import posthog from 'posthog-js';
|
|
import { PostHogProvider } from 'posthog-js/react';
|
|
import { BASE_PATH } from './constants/app';
|
|
|
|
// Compute initial color scheme
|
|
function getInitialScheme(): 'light' | 'dark' {
|
|
const stored = localStorage.getItem('stirling-theme');
|
|
if (stored === 'light' || stored === 'dark') return stored;
|
|
try {
|
|
const prefersDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
|
|
return prefersDark ? 'dark' : 'light';
|
|
} catch {
|
|
return 'light';
|
|
}
|
|
}
|
|
|
|
posthog.init(import.meta.env.VITE_PUBLIC_POSTHOG_KEY, {
|
|
api_host: import.meta.env.VITE_PUBLIC_POSTHOG_HOST,
|
|
defaults: '2025-05-24',
|
|
capture_exceptions: true, // This enables capturing exceptions using Error Tracking, set to false if you don't want this
|
|
debug: false,
|
|
opt_out_capturing_by_default: false, // We handle opt-out via cookie consent
|
|
});
|
|
|
|
function updatePosthogConsent(){
|
|
if(typeof(posthog) == "undefined") {
|
|
return;
|
|
}
|
|
const optIn = (window.CookieConsent as any).acceptedCategory('analytics');
|
|
if (optIn) {
|
|
posthog.opt_in_capturing();
|
|
} else {
|
|
posthog.opt_out_capturing();
|
|
}
|
|
|
|
console.log("Updated analytics consent: ", optIn? "opted in" : "opted out");
|
|
}
|
|
|
|
window.addEventListener("cc:onConsent", updatePosthogConsent);
|
|
window.addEventListener("cc:onChange", updatePosthogConsent);
|
|
|
|
const container = document.getElementById('root');
|
|
if (!container) {
|
|
throw new Error("Root container missing in index.html");
|
|
}
|
|
|
|
const root = ReactDOM.createRoot(container); // Finds the root DOM element
|
|
root.render(
|
|
<React.StrictMode>
|
|
<ColorSchemeScript defaultColorScheme={getInitialScheme()} />
|
|
<PostHogProvider
|
|
client={posthog}
|
|
>
|
|
<BrowserRouter basename={BASE_PATH}>
|
|
<App />
|
|
</BrowserRouter>
|
|
</PostHogProvider>
|
|
</React.StrictMode>
|
|
);
|