|
1 | | -const { app, BrowserWindow, ipcMain, session, shell, net } = require('electron') |
| 1 | +const { app, BrowserWindow, ipcMain, session, shell, net, Menu } = require('electron') |
2 | 2 | const path = require('path') |
3 | 3 | const Database = require('./database') |
4 | 4 |
|
@@ -142,12 +142,114 @@ function createDetachedWindow(nodeId, nodeTitle) { |
142 | 142 | return { success: true, focused: false } |
143 | 143 | } |
144 | 144 |
|
| 145 | +function createMenu() { |
| 146 | + const isMac = process.platform === 'darwin' |
| 147 | + const template = [ |
| 148 | + // App menu (macOS only) |
| 149 | + ...(isMac ? [{ |
| 150 | + label: app.name, |
| 151 | + submenu: [ |
| 152 | + { role: 'about' }, |
| 153 | + { type: 'separator' }, |
| 154 | + { |
| 155 | + label: 'Settings...', |
| 156 | + accelerator: 'CmdOrCtrl+,', |
| 157 | + click: () => { |
| 158 | + mainWindow?.webContents.send('open-settings') |
| 159 | + } |
| 160 | + }, |
| 161 | + { type: 'separator' }, |
| 162 | + { role: 'services' }, |
| 163 | + { type: 'separator' }, |
| 164 | + { role: 'hide' }, |
| 165 | + { role: 'hideOthers' }, |
| 166 | + { role: 'unhide' }, |
| 167 | + { type: 'separator' }, |
| 168 | + { role: 'quit' } |
| 169 | + ] |
| 170 | + }] : []), |
| 171 | + // Edit menu |
| 172 | + { |
| 173 | + label: 'Edit', |
| 174 | + submenu: [ |
| 175 | + { role: 'undo' }, |
| 176 | + { role: 'redo' }, |
| 177 | + { type: 'separator' }, |
| 178 | + { role: 'cut' }, |
| 179 | + { role: 'copy' }, |
| 180 | + { role: 'paste' }, |
| 181 | + { role: 'selectAll' } |
| 182 | + ] |
| 183 | + }, |
| 184 | + // View menu |
| 185 | + { |
| 186 | + label: 'View', |
| 187 | + submenu: [ |
| 188 | + { role: 'reload' }, |
| 189 | + { role: 'forceReload' }, |
| 190 | + { role: 'toggleDevTools' }, |
| 191 | + { type: 'separator' }, |
| 192 | + { role: 'resetZoom' }, |
| 193 | + { role: 'zoomIn' }, |
| 194 | + { role: 'zoomOut' }, |
| 195 | + { type: 'separator' }, |
| 196 | + { role: 'togglefullscreen' } |
| 197 | + ] |
| 198 | + }, |
| 199 | + // Window menu |
| 200 | + { |
| 201 | + label: 'Window', |
| 202 | + submenu: [ |
| 203 | + { role: 'minimize' }, |
| 204 | + { role: 'zoom' }, |
| 205 | + ...(isMac ? [ |
| 206 | + { type: 'separator' }, |
| 207 | + { role: 'front' }, |
| 208 | + { type: 'separator' }, |
| 209 | + { role: 'window' } |
| 210 | + ] : [ |
| 211 | + { role: 'close' } |
| 212 | + ]) |
| 213 | + ] |
| 214 | + }, |
| 215 | + // Help menu |
| 216 | + { |
| 217 | + role: 'help', |
| 218 | + submenu: [ |
| 219 | + { |
| 220 | + label: 'Documentation', |
| 221 | + click: async () => { |
| 222 | + await shell.openExternal('https://github.com/sorenwacker/graph-core#readme') |
| 223 | + } |
| 224 | + }, |
| 225 | + { |
| 226 | + label: 'Report Issue', |
| 227 | + click: async () => { |
| 228 | + await shell.openExternal('https://github.com/sorenwacker/graph-core/issues') |
| 229 | + } |
| 230 | + }, |
| 231 | + { type: 'separator' }, |
| 232 | + { |
| 233 | + label: 'Ollama Setup', |
| 234 | + click: async () => { |
| 235 | + await shell.openExternal('https://ollama.ai/download') |
| 236 | + } |
| 237 | + } |
| 238 | + ] |
| 239 | + } |
| 240 | + ] |
| 241 | + |
| 242 | + const menu = Menu.buildFromTemplate(template) |
| 243 | + Menu.setApplicationMenu(menu) |
| 244 | +} |
| 245 | + |
145 | 246 | app.whenReady().then(async () => { |
146 | 247 | // Initialize database |
147 | 248 | const dbPath = path.join(app.getPath('userData'), 'graph.db') |
148 | 249 | db = new Database(dbPath) |
149 | 250 | await db.ready // Wait for async initialization |
150 | 251 |
|
| 252 | + createMenu() |
151 | 253 | createWindow() |
152 | 254 |
|
153 | 255 | app.on('activate', () => { |
|
0 commit comments