Skip to content

Commit e417782

Browse files
committed
Add application menu with About, Edit, View, Window, Help
1 parent ba22b57 commit e417782

File tree

1 file changed

+103
-1
lines changed

1 file changed

+103
-1
lines changed

electron/main.js

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { app, BrowserWindow, ipcMain, session, shell, net } = require('electron')
1+
const { app, BrowserWindow, ipcMain, session, shell, net, Menu } = require('electron')
22
const path = require('path')
33
const Database = require('./database')
44

@@ -142,12 +142,114 @@ function createDetachedWindow(nodeId, nodeTitle) {
142142
return { success: true, focused: false }
143143
}
144144

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+
145246
app.whenReady().then(async () => {
146247
// Initialize database
147248
const dbPath = path.join(app.getPath('userData'), 'graph.db')
148249
db = new Database(dbPath)
149250
await db.ready // Wait for async initialization
150251

252+
createMenu()
151253
createWindow()
152254

153255
app.on('activate', () => {

0 commit comments

Comments
 (0)