mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 16:04:21 +00:00
Native auxiliary windows (settings, comparison, diff, deployment) all booted src/main.tsx, which statically imported the Workbench and every workbench feature (CodeMirror, xterm, editor extensions) even when the Settings window rendered none of them. main.tsx is now a small window-kind router with one boot module per window kind, and the settings pages, core plugin points and plugin theme runtime are registered from editor-free modules, so the Settings window loads no Workbench, @codemirror, @xterm or @/editor modules (about 57% less JS and a third less heap per Settings window). A static test keeps the Settings boot isolated. Part of #3942 Co-authored-by: dengliu <5108773+dengliu@users.noreply.github.com>
102 lines
4.2 KiB
TypeScript
102 lines
4.2 KiB
TypeScript
/**
|
|
* Shell services and built-in contributions. Call before `activateFeatures()`
|
|
* so features can rely on the tool window and notification services.
|
|
*/
|
|
import { openPolicy } from "./projectWindow";
|
|
import { setContext } from "@/platform/context";
|
|
import { isRemoteWindow, useRemote } from "@/platform/remote";
|
|
import { useProject } from "@/platform/project";
|
|
import {
|
|
provideNotificationService,
|
|
provideToolWindowService,
|
|
registerOverlay,
|
|
registerStatusItem,
|
|
registerToolWindow,
|
|
} from "./contributions";
|
|
import { installBrowserGuards } from "./browserGuards";
|
|
import { installDistractionFree } from "./distractionFree";
|
|
import { installNarrowWindow } from "./narrowWindow";
|
|
import { installFileDrop } from "./fileDrop";
|
|
import { installFocusTracking } from "./focus";
|
|
import { installFocusScopeTracking } from "@/ui/focusScope";
|
|
import { clearProjectNotifications, installNotifyEvents, notificationServiceImpl } from "./notificationStore";
|
|
import {
|
|
NOTIFICATIONS_TOOL_WINDOW,
|
|
NotificationsHeaderActions,
|
|
NotificationsToolWindow,
|
|
useUnreadNotifications,
|
|
} from "./Notifications";
|
|
import { loadPlatformInfo } from "@/platform/platformInfo";
|
|
import { registerShellActions } from "./shellActions";
|
|
import { MainToolbarDialogHost } from "./MainToolbarDialog";
|
|
import { BackgroundTasksHost, StatusInfo, TaskStatus } from "./StatusBar";
|
|
import { installTaskEvents } from "./tasks";
|
|
import { installToolWindowActions } from "./toolwindows/actions";
|
|
import {
|
|
installToolWindowLayoutSync,
|
|
loadToolWindowLayout,
|
|
setFocusedToolWindow,
|
|
toolWindowServiceImpl,
|
|
} from "./toolwindows/store";
|
|
|
|
export function activateWorkbench(): () => void {
|
|
provideToolWindowService(toolWindowServiceImpl);
|
|
provideNotificationService(notificationServiceImpl);
|
|
void loadPlatformInfo();
|
|
|
|
const syncProjectContext = () => {
|
|
const project = useProject.getState().project;
|
|
setContext("projectLocal", !!project && !isRemoteWindow() && !useProject.getState().lightEdit);
|
|
setContext("workspaceOpen", !!project?.workspace);
|
|
setContext("projectAttached", !!project?.workspace && project.workspace.projects[0] === project.root);
|
|
setContext("workspaceContainer", !!project?.workspace && project.workspace.projects[0] !== project.root);
|
|
setContext("projectOpenAsk", openPolicy() === "ask");
|
|
};
|
|
// Synchronous so the frame's first render after opening already has the project's layout.
|
|
const onProject = (root: string | null) => {
|
|
setContext("projectOpen", root !== null);
|
|
syncProjectContext();
|
|
setContext("lightEdit", useProject.getState().lightEdit);
|
|
if (root !== null) loadToolWindowLayout(root);
|
|
};
|
|
onProject(useProject.getState().project?.root ?? null);
|
|
const unsubProject = useProject.subscribe((s, prev) => {
|
|
syncProjectContext();
|
|
if (s.project?.root === prev.project?.root && s.lightEdit === prev.lightEdit) return;
|
|
// The previous project's notifications (and their actions) no longer apply.
|
|
if (prev.project) clearProjectNotifications();
|
|
onProject(s.project?.root ?? null);
|
|
});
|
|
|
|
const disposers = [
|
|
unsubProject,
|
|
useRemote.subscribe(syncProjectContext),
|
|
registerShellActions(),
|
|
installToolWindowActions(),
|
|
installToolWindowLayoutSync(),
|
|
installDistractionFree(),
|
|
installNarrowWindow(),
|
|
installFocusTracking(setFocusedToolWindow),
|
|
installFocusScopeTracking(),
|
|
installTaskEvents(),
|
|
installNotifyEvents(),
|
|
installBrowserGuards(),
|
|
installFileDrop(),
|
|
registerOverlay({ id: "workbench.customizeToolbar", component: MainToolbarDialogHost }),
|
|
registerOverlay({ id: "workbench.backgroundTasks", component: BackgroundTasksHost }),
|
|
registerStatusItem({ id: "workbench.tasks", align: "right", priority: 0, component: TaskStatus, lightEdit: true }),
|
|
registerStatusItem({ id: "workbench.info", align: "left", priority: 5, component: StatusInfo, lightEdit: true }),
|
|
registerToolWindow({
|
|
id: NOTIFICATIONS_TOOL_WINDOW,
|
|
title: "Notifications",
|
|
icon: "bell",
|
|
anchor: "right",
|
|
order: 0,
|
|
component: NotificationsToolWindow,
|
|
headerActions: NotificationsHeaderActions,
|
|
useBadge: useUnreadNotifications,
|
|
}),
|
|
];
|
|
return () => disposers.reverse().forEach((d) => d());
|
|
}
|