MCPcopy Create free account
hub / github.com/chieapp/chie / WindowManager

Class WindowManager

src/controller/window-manager.ts:19–134  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17type NamedWindowType = new () => BaseWindow;
18
19export class WindowManager extends ConfigStoreItem {
20 // Do not quit when all windows are closed.
21 quitOnAllWindowsClosed = true;
22
23 // Saves all windows.
24 windows: BaseWindow[] = [];
25 // Chat windows, using assistant id as name.
26 #chatWindows: WindowStore;
27 // Global windows, each window has its own type.
28 #registeredWindows: Record<string, NamedWindowType> = {};
29 #namedWindows: WindowStore;
30
31 constructor() {
32 super();
33 this.#chatWindows = new WindowStore((id) => {
34 const ChatWindow = require('../view/chat-window').default;
35 return new ChatWindow(assistantManager.getAssistantById(id));
36 });
37 this.#namedWindows = new WindowStore((name) => {
38 const windowType = this.#registeredWindows[name];
39 if (!windowType)
40 throw new Error(`There is no window named "${name}".`);
41 return new windowType();
42 });
43 assistantManager.onRemoveAssistant.connect(this.#onRemoveAssistant.bind(this));
44 }
45
46 deserialize(data: WindowManagerData) {
47 if (typeof data != 'object') // accepts empty data
48 data = {};
49 this.#chatWindows.deserialize(data.chatWindows);
50 this.#namedWindows.deserialize(data.windows);
51 }
52
53 serialize(): WindowManagerData {
54 return {
55 chatWindows: this.#chatWindows.serialize(),
56 windows: this.#namedWindows.serialize(),
57 };
58 }
59
60 showChatWindow(id: string) {
61 return this.#chatWindows.showWindow(id);
62 }
63
64 registerNamedWindow(name: string, windowType: NamedWindowType) {
65 if (name in this.#registeredWindows)
66 throw new Error(`Window name "${name}" has already been registered.`);
67 this.#registeredWindows[name] = windowType;
68 }
69
70 getNamedWindow(name: string) {
71 return this.#namedWindows.getWindow(name);
72 }
73
74 getOrCreateNamedWindow(name: string) {
75 return this.#namedWindows.getOrCreateWindow(name);
76 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected