-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.js
More file actions
122 lines (101 loc) · 3.27 KB
/
main.js
File metadata and controls
122 lines (101 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
const { app, ipcMain, Menu } = require('electron');
let wm = null;
let _quitting = false;
app.whenReady().then(() => {
try {
require('@electron/remote/main').initialize();
} catch { }
const template = [
...(process.platform === 'darwin' ? [{
label: app.name,
submenu: [
{ role: 'about' },
{ type: 'separator' },
{ role: 'hide' },
{ role: 'hideOthers' },
{ role: 'unhide' },
{ type: 'separator' },
{ role: 'quit' },
],
}] : []),
{
label: '编辑', submenu: [
{ role: 'undo' }, { role: 'redo' }, { type: 'separator' },
{ role: 'cut' }, { role: 'copy' }, { role: 'paste' },
{ role: 'selectAll' },
]
},
{
label: '窗口', submenu: [
{ role: 'minimize' }, { role: 'zoom' }, { role: 'close' },
...(process.platform === 'darwin' ? [
{ type: 'separator' }, { role: 'front' },
] : []),
]
},
];
Menu.setApplicationMenu(Menu.buildFromTemplate(template));
const db = require('./db');
const WindowManager = require('./window/window_manager');
db.init();
wm = new WindowManager();
wm.showHome();
// Tool-call relay: chat renderer → editor
ipcMain.on('tool-call', (_event, data) => {
const editorWC = wm.getEditorWebContents();
if (editorWC && !editorWC.isDestroyed()) {
editorWC.send('tool-call', data);
}
});
// Tool-result relay: editor → chat renderer
ipcMain.on('tool-result', (_event, result) => {
const chatWC = wm.getChatWebContents();
if (chatWC && !chatWC.isDestroyed()) {
chatWC.send('tool-result', result);
}
});
ipcMain.on('open-project', (_event, { uuid, configPath, isNew = false }) => {
if (!wm.mainWindow) {
wm.createMainWindow();
wm.mainWindow.on('closed', () => {
wm.closeEditor();
if (!_quitting) wm.showHome();
});
}
wm.closeHome();
const editorWC = wm.getEditorWebContents();
const chatWC = wm.getChatWebContents();
const sendLoad = () => {
editorWC.send('load-project', { uuid, configPath });
};
const notifyChat = () => {
chatWC.executeJavaScript(
`window.__onProjectOpened && window.__onProjectOpened(${JSON.stringify(uuid)}, ${JSON.stringify({ isNewThread: isNew })})`
);
};
if (editorWC.isLoading()) {
editorWC.once('did-finish-load', sendLoad);
} else {
sendLoad();
}
if (chatWC.isLoading()) {
chatWC.once('did-finish-load', notifyChat);
} else {
notifyChat();
}
});
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit();
});
app.on('activate', () => {
if (wm && !wm.homeWindow && !wm.mainWindow) {
wm.showHome();
}
});
app.on('before-quit', () => {
_quitting = true;
});
app.on('will-quit', () => {
try { require('./db').close(); } catch { }
});