| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- import { BrowserWindow } from 'electron';
- import { logger } from 'ee-core/log';
- import { getMainWindow } from 'ee-core/electron';
- import { getSmartWindowOptions, smartWindowSize } from '../../config/windowOptions';
- import { createSubWindowController, focusWindow, type SubWindowOpenOptions } from './subWindow';
- /** 智能窗口只承载工作台,非该路径一律改写 */
- const WORKBENCH_PATH = '/workbench';
- /** 主进程 → 主窗口的窗口开关状态通道 */
- export const SMART_WINDOW_STATE_CHANNEL = 'smart-window:state';
- export type OpenSmartWindowOptions = SubWindowOpenOptions;
- /** 单例:应用内最多一个智能工作台窗口 */
- const smartWindowController = createSubWindowController({
- pathPrefix: WORKBENCH_PATH,
- boundsKey: 'smartWindowBounds',
- minSize: smartWindowSize,
- createWindowOptions: getSmartWindowOptions,
- stateChannel: SMART_WINDOW_STATE_CHANNEL,
- // 工作台普通打开只聚焦;?newChat=1 / ?view=agent 这类明确意图才导航
- navigateOnlyWhenQuery: true,
- });
- export function getSmartWindow(): BrowserWindow | null {
- return smartWindowController.getWindow();
- }
- export function isSmartWindowOpen(): boolean {
- return smartWindowController.isOpen();
- }
- /** 判断某个窗口是不是智能工作台窗口(IPC 解析窗口角色用) */
- export function isSmartWindow(win: BrowserWindow | null | undefined): boolean {
- return smartWindowController.matches(win);
- }
- /**
- * 打开/聚焦智能工作台窗口。
- *
- * 已存在时只做 restore/show/focus(reloadIfOpen 时再 reload),保证单例。
- */
- export function openSmartWindow(options: OpenSmartWindowOptions = {}): BrowserWindow {
- return smartWindowController.open(options);
- }
- export function closeSmartWindow(): void {
- smartWindowController.close();
- }
- /** 把已打开的智能窗口拉到前台;没打开返回 false */
- export function focusSmartWindow(): boolean {
- return smartWindowController.focus();
- }
- /** 把主窗口拉到前台(智能窗口遇到登录/授权失效时,由主窗口负责提示) */
- export function focusMainWindow(): void {
- try {
- focusWindow(getMainWindow());
- } catch (e) {
- logger.warn('[smartWindow] focusMainWindow failed:', e instanceof Error ? e.message : String(e));
- }
- }
|