2023-11-23 03:22:47 -08:00
|
|
|
import { useCloudPlanStore } from '@/stores/cloudPlan.store';
|
|
|
|
import { useNodeTypesStore } from '@/stores/nodeTypes.store';
|
2024-06-18 10:15:12 -07:00
|
|
|
import { useRootStore } from '@/stores/root.store';
|
2023-11-23 03:22:47 -08:00
|
|
|
import { useSettingsStore } from '@/stores/settings.store';
|
|
|
|
import { useSourceControlStore } from '@/stores/sourceControl.store';
|
|
|
|
import { useUsersStore } from '@/stores/users.store';
|
|
|
|
import { initializeCloudHooks } from '@/hooks/register';
|
2023-12-20 02:49:40 -08:00
|
|
|
import { useVersionsStore } from '@/stores/versions.store';
|
2024-06-06 06:30:17 -07:00
|
|
|
import { useProjectsStore } from '@/stores/projects.store';
|
2024-05-17 01:53:15 -07:00
|
|
|
import { useRolesStore } from './stores/roles.store';
|
2023-11-23 03:22:47 -08:00
|
|
|
|
|
|
|
let coreInitialized = false;
|
|
|
|
let authenticatedFeaturesInitialized = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes the core application stores and hooks
|
|
|
|
* This is called once, when the first route is loaded.
|
|
|
|
*/
|
|
|
|
export async function initializeCore() {
|
|
|
|
if (coreInitialized) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const settingsStore = useSettingsStore();
|
|
|
|
const usersStore = useUsersStore();
|
2023-12-20 02:49:40 -08:00
|
|
|
const versionsStore = useVersionsStore();
|
2023-11-23 03:22:47 -08:00
|
|
|
|
|
|
|
await settingsStore.initialize();
|
2024-04-04 06:53:34 -07:00
|
|
|
if (!settingsStore.isPreviewMode) {
|
|
|
|
await usersStore.initialize();
|
2023-11-29 01:51:15 -08:00
|
|
|
|
2024-04-04 06:53:34 -07:00
|
|
|
void versionsStore.checkForNewVersions();
|
2023-12-20 02:49:40 -08:00
|
|
|
|
2024-04-04 06:53:34 -07:00
|
|
|
if (settingsStore.isCloudDeployment) {
|
|
|
|
try {
|
|
|
|
await initializeCloudHooks();
|
|
|
|
} catch (e) {
|
|
|
|
console.error('Failed to initialize cloud hooks:', e);
|
|
|
|
}
|
2023-11-29 01:51:15 -08:00
|
|
|
}
|
2023-11-23 03:22:47 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
coreInitialized = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes the features of the application that require an authenticated user
|
|
|
|
*/
|
|
|
|
export async function initializeAuthenticatedFeatures() {
|
|
|
|
if (authenticatedFeaturesInitialized) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const usersStore = useUsersStore();
|
|
|
|
if (!usersStore.currentUser) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const sourceControlStore = useSourceControlStore();
|
|
|
|
const settingsStore = useSettingsStore();
|
|
|
|
const rootStore = useRootStore();
|
|
|
|
const nodeTypesStore = useNodeTypesStore();
|
2023-11-29 01:51:15 -08:00
|
|
|
const cloudPlanStore = useCloudPlanStore();
|
2024-05-17 01:53:15 -07:00
|
|
|
const projectsStore = useProjectsStore();
|
|
|
|
const rolesStore = useRolesStore();
|
2023-11-23 03:22:47 -08:00
|
|
|
|
|
|
|
if (sourceControlStore.isEnterpriseSourceControlEnabled) {
|
|
|
|
await sourceControlStore.getPreferences();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (settingsStore.isTemplatesEnabled) {
|
|
|
|
try {
|
|
|
|
await settingsStore.testTemplatesEndpoint();
|
|
|
|
} catch (e) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rootStore.defaultLocale !== 'en') {
|
|
|
|
await nodeTypesStore.getNodeTranslationHeaders();
|
|
|
|
}
|
|
|
|
|
2023-11-29 01:51:15 -08:00
|
|
|
if (settingsStore.isCloudDeployment) {
|
|
|
|
try {
|
|
|
|
await cloudPlanStore.initialize();
|
|
|
|
} catch (e) {
|
|
|
|
console.error('Failed to initialize cloud plan store:', e);
|
|
|
|
}
|
|
|
|
}
|
2024-05-17 01:53:15 -07:00
|
|
|
await Promise.all([
|
|
|
|
projectsStore.getMyProjects(),
|
|
|
|
projectsStore.getPersonalProject(),
|
|
|
|
projectsStore.getProjectsCount(),
|
|
|
|
rolesStore.fetchRoles(),
|
|
|
|
]);
|
2023-11-29 01:51:15 -08:00
|
|
|
|
2023-11-23 03:22:47 -08:00
|
|
|
authenticatedFeaturesInitialized = true;
|
|
|
|
}
|