Line data Source code
1 : import * as React from 'react';
2 :
3 : import { SELECT_SESSION, useRouteContext, useRouterNavigate } from '../router/router.js';
4 : import { useConnectionDispatch, useSessionConnections } from '../../connections/connection_registry.js';
5 : import { useLogger } from '../../platform/logger/logger_provider.js';
6 : import { AppLoadingPage } from '../app_loading_page.js';
7 : import { canShowSession } from './app_loading_logic.js';
8 : import { useAppConfig, useAppReconfigure } from '../../config/app_config.js';
9 : import { useAppSettingsReady } from '../../config/app_settings_sync.js';
10 : import { useHyperSetup } from '../../connections/hyper/hyper_connection_setup.js';
11 : import { useInitialMemorySetup } from './initial_memory_setup.js';
12 : import { SessionSetupStatus } from './session_setup_status.js';
13 : import { NarrowScreenWarning, useNarrowScreenWarning } from '../narrow_screen_warning.js';
14 : import { useAppSetup } from './app_setup.js';
15 : import { useSharedSessionImport } from './shared_session_import.js';
16 : import { useHyperLinks } from '../hyper_links.js';
17 :
18 : interface Props { }
19 :
20 1 : export const AppLoader: React.FC<React.PropsWithChildren<Props>> = (props: React.PropsWithChildren<Props>) => {
21 1 : const config = useAppConfig();
22 1 : const appSettingsReady = useAppSettingsReady();
23 1 : const reconfigure = useAppReconfigure();
24 1 : const showNarrowScreenWarning = useNarrowScreenWarning(appSettingsReady, config?.settings?.narrowScreenLayout ?? false);
25 1 : const logger = useLogger();
26 1 : const navigate = useRouterNavigate();
27 1 : const routeContext = useRouteContext();
28 1 : const sessionConnections = useSessionConnections(routeContext.sessionId ?? null);
29 1 : const dispatchDatabase = useConnectionDispatch();
30 1 : const hyperSetup = useHyperSetup();
31 :
32 : // The import of a session that the app was started with, the setup then doesn't open another one
33 1 : const initialImport = React.useRef<Promise<boolean> | null>(null);
34 1 : const setup = useAppSetup(initialImport);
35 1 : const sharedSessionCard = useSharedSessionImport(setup.done, initialImport);
36 1 : useHyperLinks(setup.opened);
37 :
38 1 : React.useEffect(() => {
39 1 : if (routeContext.sessionSetupStatus === SessionSetupStatus.OPENING && routeContext.sessionId != null) {
40 1 : navigate({ type: SELECT_SESSION, value: routeContext.sessionId });
41 : }
42 1 : }, [navigate, routeContext.sessionId, routeContext.sessionSetupStatus]);
43 :
44 1 : useInitialMemorySetup(
45 1 : routeContext.sessionId,
46 1 : sessionConnections,
47 1 : hyperSetup,
48 1 : dispatchDatabase,
49 1 : logger,
50 1 : );
51 :
52 1 : if (showNarrowScreenWarning) {
53 1 : return <NarrowScreenWarning onEnable={() => reconfigure(value => value == null ? null : {
54 1 : ...value,
55 1 : settings: { ...value.settings, narrowScreenLayout: true },
56 1 : })} />;
57 : }
58 1 : if (sharedSessionCard != null) {
59 1 : return sharedSessionCard;
60 : }
61 :
62 : // Setup done and session selected? Show main interface
63 1 : const pauseAfterSetup = config?.settings?.pauseAfterAppSetup ?? false;
64 1 : if (canShowSession(routeContext, pauseAfterSetup)) {
65 1 : return props.children;
66 : } else {
67 : // Otherwise show the app loading page
68 1 : return <AppLoadingPage
69 1 : pauseAfterSetup={pauseAfterSetup}
70 1 : progress={setup.progress}
71 1 : embeddedDatabaseStatus={setup.embeddedDatabaseStatus}
72 1 : />;
73 : }
74 1 : };
|