import { AService } from '@/core/service/kernel/AService.ts' interface IWindow { id: string; title: string; x: number; y: number; width: number; height: number; zIndex: number; minimized: boolean; maximized: boolean; } export class WindowFormService extends AService { private windows: Map = new Map(); private zCounter = 1; constructor() { super("WindowForm"); console.log('WindowFormService - 服务注册') } createWindow(title: string, config?: Partial): IWindow { const id = `win-${Date.now()}-${Math.random()}`; const win: IWindow = { id, title, x: config?.x ?? 100, y: config?.y ?? 100, width: config?.width ?? 400, height: config?.height ?? 300, zIndex: this.zCounter++, minimized: false, maximized: false }; this.windows.set(id, win); this.sm.broadcast("WindowFrom:created", win); return win; } closeWindow(id: string) { if (this.windows.has(id)) { this.windows.delete(id); this.sm.broadcast("WindowFrom:closed", id); } } focusWindow(id: string) { const win = this.windows.get(id); if (win) { win.zIndex = this.zCounter++; this.sm.broadcast("WindowFrom:focused", win); } } minimizeWindow(id: string) { const win = this.windows.get(id); if (win) { win.minimized = true; this.sm.broadcast("WindowFrom:minimized", win); } } maximizeWindow(id: string) { const win = this.windows.get(id); if (win) { win.maximized = !win.maximized; this.sm.broadcast("WindowFrom:maximized", win); } } getWindows(): IWindow[] { return Array.from(this.windows.values()).sort((a, b) => a.zIndex - b.zIndex); } onMessage(event: string, data?: any) { console.log(`[WindowService] 收到事件:`, event, data); } } // ==================== DesktopProcess ==================== // class DesktopProcess implements IProcess { // id = "desktop"; // private windows: IWindow[] = []; // // constructor(private sm: ServiceManager) { // sm.registerProcess(this); // } // // render() { // console.log("\n[Desktop 渲染]"); // this.windows // .sort((a, b) => a.zIndex - b.zIndex) // .forEach(win => { // console.log( // `- ${win.title} (${win.id}) at (${win.x},${win.y}) size(${win.width}x${win.height}) z=${win.zIndex} ${win.minimized ? "[最小化]" : win.maximized ? "[最大化]" : ""}` // ); // }); // } // // onMessage(event: string, data?: any) { // if (event.startsWith("window:")) { // // 更新桌面维护的窗口列表 // const ws = this.sm.getService("window"); // if (ws) { // this.windows = ws.getWindows(); // this.render(); // } // } // } // }