'use client' import { useEffect, useState } from 'react' import { Button } from '@janhq/joi' import { useAtom, useAtomValue, useSetAtom } from 'jotai' import posthog from 'posthog-js' import { twMerge } from 'tailwind-merge' import BottomPanel from '@/containers/Layout/BottomPanel' import RibbonPanel from '@/containers/Layout/RibbonPanel' import TopPanel from '@/containers/Layout/TopPanel' import { MainViewState } from '@/constants/screens' import { getImportModelStageAtom } from '@/hooks/useImportModel' import { SUCCESS_SET_NEW_DESTINATION } from '@/screens/Settings/Advanced/DataFolder' import CancelModelImportModal from '@/screens/Settings/CancelModelImportModal' import ChooseWhatToImportModal from '@/screens/Settings/ChooseWhatToImportModal' import EditModelInfoModal from '@/screens/Settings/EditModelInfoModal' import ImportModelOptionModal from '@/screens/Settings/ImportModelOptionModal' import ImportingModelModal from '@/screens/Settings/ImportingModelModal' import SelectingModelModal from '@/screens/Settings/SelectingModelModal' import { getAppDistinctId, updateDistinctId } from '@/utils/settings' import LoadingModal from '../LoadingModal' import MainViewContainer from '../MainViewContainer' import ModalAppUpdaterChangelog from '../ModalAppUpdaterChangelog' import ModalAppUpdaterNotAvailable from '../ModalAppUpdaterNotAvailable' import { mainViewStateAtom } from '@/helpers/atoms/App.atom' import { productAnalyticAtom, productAnalyticPromptAtom, reduceTransparentAtom, showScrollBarAtom, } from '@/helpers/atoms/Setting.atom' const BaseLayout = () => { const setMainViewState = useSetAtom(mainViewStateAtom) const importModelStage = useAtomValue(getImportModelStageAtom) const reduceTransparent = useAtomValue(reduceTransparentAtom) const [productAnalytic, setProductAnalytic] = useAtom(productAnalyticAtom) const [productAnalyticPrompt, setProductAnalyticPrompt] = useAtom( productAnalyticPromptAtom ) const showScrollBar = useAtomValue(showScrollBarAtom) const [showProductAnalyticPrompt, setShowProductAnalyticPrompt] = useState(false) useEffect(() => { const timer = setTimeout(() => { if (productAnalyticPrompt) { setShowProductAnalyticPrompt(true) } return () => clearTimeout(timer) }, 3000) // 3 seconds delay return () => clearTimeout(timer) // Cleanup timer on unmount }, [productAnalyticPrompt]) useEffect(() => { if (productAnalytic) { posthog.init(POSTHOG_KEY, { api_host: POSTHOG_HOST, autocapture: false, capture_pageview: false, capture_pageleave: false, disable_session_recording: true, person_profiles: 'always', persistence: 'localStorage', opt_out_capturing_by_default: true, // eslint-disable-next-line @typescript-eslint/naming-convention sanitize_properties: function (properties) { const denylist = [ '$pathname', '$initial_pathname', '$current_url', '$initial_current_url', '$host', '$initial_host', '$initial_person_info', ] denylist.forEach((key) => { if (properties[key]) { properties[key] = null // Set each denied property to null } }) return properties }, }) // Attempt to restore distinct Id from app global settings getAppDistinctId() .then((id) => { if (id) posthog.identify(id) }) .finally(() => { posthog.opt_in_capturing() posthog.register({ app_version: VERSION }) updateDistinctId(posthog.get_distinct_id()) }) } else { posthog.opt_out_capturing() } }, [productAnalytic]) useEffect(() => { if (localStorage.getItem(SUCCESS_SET_NEW_DESTINATION) === 'true') { setMainViewState(MainViewState.Settings) } }, [setMainViewState]) useEffect(() => { window.electronAPI?.onMainViewStateChange( (_event: string, route: string) => { if (route === 'Settings') { setMainViewState(MainViewState.Settings) } } ) }, [setMainViewState]) const handleProductAnalytics = (isAllowed: boolean) => { setProductAnalytic(isAllowed) setProductAnalyticPrompt(false) setShowProductAnalyticPrompt(false) if (isAllowed) { posthog.opt_in_capturing() } else { posthog.opt_out_capturing() } } return (
To improve Jan, we collect anonymous data to understand feature usage. Your chats and personal information are never tracked. You can change this anytime in {`Settings > Privacy.`}
Would you like to help us to improve Jan?