Skip to content

Commit

Permalink
Proof of Concept testing Desktop menu options
Browse files Browse the repository at this point in the history
  • Loading branch information
guergana committed May 28, 2024
1 parent 0de6230 commit 638ac5c
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
5 changes: 4 additions & 1 deletion desktop/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { app, dialog, BrowserWindow } from 'electron'
import { app, dialog, BrowserWindow, Menu } from 'electron'
import { electronApp, optimizer } from '@electron-toolkit/utils'
import { createWindow } from './window'
import { createBridge } from './bridge'
Expand All @@ -10,6 +10,7 @@ import * as server from './server'
import * as python from './python'
import * as settings from './settings'
import * as resources from './resources'
const { mainMenu } = require('./menu.ts')

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
Expand Down Expand Up @@ -69,3 +70,5 @@ process.on('unhandledRejection', async (error: any) => {

// Configure logger to write to the app directory
log.transports.file.resolvePath = () => join(settings.APP_HOME, 'logger', 'main.log')

Menu.setApplicationMenu(mainMenu)
75 changes: 75 additions & 0 deletions desktop/menu.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { app, Menu, MenuItemConstructorOptions } from 'electron'

const isMac = process.platform === 'darwin'

const template = [
...(isMac ? [{
label: app.name,
submenu: [
{ role: 'about' },
{ type: 'separator' },
{ type: 'separator' },
{ role: 'quit' }
]
}]: []) as MenuItemConstructorOptions[],
// { role: fileMenu }
{
label: 'Fileyooo',
submenu: [
{
label: 'Open file',
click: async () => {
//doOpenFile()
}
}
] as MenuItemConstructorOptions[]
},
// { role: 'editMenu' }
{
label: 'Edituuuu',
submenu: [
{ role: 'undo' },
{ role: 'redo' },
{ type: 'separator' },
{ role: 'cut' },
{ role: 'copy' },
{ role: 'paste' },
...(isMac
? [
{ role: 'pasteAndMatchStyle' },
{ role: 'delete' },
{ role: 'selectAll' },
{ type: 'separator' },
{
label: 'Speech',
submenu: [
{ role: 'startSpeaking' },
{ role: 'stopSpeaking' }
]
}
]
: [
{ role: 'delete' },
{ type: 'separator' },
{ role: 'selectAll' }
])
] as MenuItemConstructorOptions[]
},
// { role: 'viewMenu' }
{
label: 'View',
submenu: [
{ role: 'reload' },
{ role: 'forceReload' },
{ role: 'toggleDevTools' },
{ type: 'separator' },
{ role: 'resetZoom' },
{ role: 'zoomIn' },
{ role: 'zoomOut' },
{ type: 'separator' },
{ role: 'togglefullscreen' }
] as MenuItemConstructorOptions[]
},
]

module.exports.mainMenu = Menu.buildFromTemplate(template)

0 comments on commit 638ac5c

Please sign in to comment.