feat: auto set client package on _app

This commit is contained in:
httpjamesm 2024-01-13 01:18:45 -05:00
parent 5b1cf9f823
commit f2edd73b86
No known key found for this signature in database
3 changed files with 37 additions and 15 deletions

View file

@ -1,24 +1,26 @@
import React, { createContext, useState, useEffect } from 'react';
import { ThemeProvider } from '@mui/material/styles';
import { getTheme } from '@ente/shared/themes';
import { useLocalState } from '@ente/shared/hooks/useLocalState';
import { LS_KEYS } from '@ente/shared/storage/localStorage';
import { THEME_COLOR } from '@ente/shared/themes/constants';
import { APPS } from '@ente/shared/apps/constants';
import { CssBaseline, useMediaQuery } from '@mui/material';
import { EnteAppProps } from '@ente/shared/apps/types';
import createEmotionCache from '@ente/shared/themes/createEmotionCache';
import { CacheProvider } from '@emotion/react'; import { CacheProvider } from '@emotion/react';
import 'styles/global.css'; import { APPS, CLIENT_PACKAGE_NAMES } from '@ente/shared/apps/constants';
import { setupI18n } from '@ente/shared/i18n'; import { EnteAppProps } from '@ente/shared/apps/types';
import { Overlay } from '@ente/shared/components/Container'; import { Overlay } from '@ente/shared/components/Container';
import EnteSpinner from '@ente/shared/components/EnteSpinner'; import DialogBoxV2 from '@ente/shared/components/DialogBoxV2';
import AppNavbar from '@ente/shared/components/Navbar/app';
import { import {
DialogBoxAttributesV2, DialogBoxAttributesV2,
SetDialogBoxAttributesV2, SetDialogBoxAttributesV2,
} from '@ente/shared/components/DialogBoxV2/types'; } from '@ente/shared/components/DialogBoxV2/types';
import DialogBoxV2 from '@ente/shared/components/DialogBoxV2'; import EnteSpinner from '@ente/shared/components/EnteSpinner';
import AppNavbar from '@ente/shared/components/Navbar/app';
import { useLocalState } from '@ente/shared/hooks/useLocalState';
import { setupI18n } from '@ente/shared/i18n';
import HTTPService from '@ente/shared/network/HTTPService';
import { LS_KEYS, getData } from '@ente/shared/storage/localStorage';
import { getTheme } from '@ente/shared/themes';
import { THEME_COLOR } from '@ente/shared/themes/constants';
import createEmotionCache from '@ente/shared/themes/createEmotionCache';
import { CssBaseline, useMediaQuery } from '@mui/material';
import { ThemeProvider } from '@mui/material/styles';
import { useRouter } from 'next/router';
import { createContext, useEffect, useState } from 'react';
import 'styles/global.css';
interface AppContextProps { interface AppContextProps {
isMobile: boolean; isMobile: boolean;
@ -49,6 +51,8 @@ export default function App(props: EnteAppProps) {
const isMobile = useMediaQuery('(max-width:428px)'); const isMobile = useMediaQuery('(max-width:428px)');
const router = useRouter();
const { const {
Component, Component,
emotionCache = clientSideEmotionCache, emotionCache = clientSideEmotionCache,
@ -61,6 +65,21 @@ export default function App(props: EnteAppProps) {
setupI18n().finally(() => setIsI18nReady(true)); setupI18n().finally(() => setIsI18nReady(true));
}, []); }, []);
const setupPackageName = () => {
const pkg = getData(LS_KEYS.CLIENT_PACKAGE);
if (!pkg) return;
HTTPService.setHeaders({
'X-Client-Package': CLIENT_PACKAGE_NAMES.get(APPS.AUTH),
});
};
useEffect(() => {
router.events.on('routeChangeComplete', setupPackageName);
return () => {
router.events.off('routeChangeComplete', setupPackageName);
};
}, [router.events]);
const closeDialogBoxV2 = () => setDialogBoxV2View(false); const closeDialogBoxV2 = () => setDialogBoxV2View(false);
const theme = getTheme(themeColor, APPS.PHOTOS); const theme = getTheme(themeColor, APPS.PHOTOS);
@ -103,3 +122,4 @@ export default function App(props: EnteAppProps) {
</CacheProvider> </CacheProvider>
); );
} }
a;

View file

@ -32,6 +32,7 @@ const AccountHandoff = () => {
const urlParams = new URLSearchParams(window.location.search); const urlParams = new URLSearchParams(window.location.search);
const pkg = urlParams.get('package'); const pkg = urlParams.get('package');
if (!pkg) return; if (!pkg) return;
setData(LS_KEYS.CLIENT_PACKAGE, { name: pkg });
HTTPService.setHeaders({ HTTPService.setHeaders({
'X-Client-Package': pkg, 'X-Client-Package': pkg,
}); });

View file

@ -28,6 +28,7 @@ export enum LS_KEYS {
OPT_OUT_OF_CRASH_REPORTS = 'optOutOfCrashReports', OPT_OUT_OF_CRASH_REPORTS = 'optOutOfCrashReports',
CF_PROXY_DISABLED = 'cfProxyDisabled', CF_PROXY_DISABLED = 'cfProxyDisabled',
REFERRAL_SOURCE = 'referralSource', REFERRAL_SOURCE = 'referralSource',
CLIENT_PACKAGE = 'clientPackage',
} }
export const setData = (key: LS_KEYS, value: object) => { export const setData = (key: LS_KEYS, value: object) => {