Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WiP] Add top menu to app #557

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
<body>
<div id="root"></div>
<script type="module" src="/index.ts"></script>
<script src="../desktop/renderer.js"></script>
</body>
</html>
5 changes: 4 additions & 1 deletion desktop/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
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'
import { join } from 'path'
import log from 'electron-log'
import * as settings from './settings'
import mainMenu from './menu'

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
Expand Down Expand Up @@ -55,3 +56,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)
103 changes: 103 additions & 0 deletions desktop/menu.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { app, Menu, MenuItemConstructorOptions, BrowserWindow } from 'electron'

const template = [
{
label: app.name,
submenu: [
{ role: 'about' },
{ role: 'quit' }
] as MenuItemConstructorOptions[]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to use type validation instead of type inforcement like:

const template: Electron.MenuItemConstructorOptions[] // or what is correct here

Otherwise using as will silently hide all configuration errors

},
{
label: 'File',
submenu: [
{
label: 'Add',
submenu: [
{
label: 'New file',
click: async () => {
// TODO
}
},
{
label: 'New folder',
click: async () => {
// console.log( BrowserWindow.getAllWindows()[0].webContents )
BrowserWindow.getAllWindows()[0].webContents.send('menu-clicked', 'add-new-folder')
}
},
{
label: 'External data',
click: async () => {
// TODO
}
},
]
},
{
label: 'Delete',
click: async () => {
// TODO
}
},
{
label: 'Publish',
click: async () => {
// TODO
}
},
] as MenuItemConstructorOptions[]
},
{
label: 'Edit',
submenu: [
{ role: 'undo' },
{ role: 'redo' },
] as MenuItemConstructorOptions[]
},
{
label: 'View',
submenu: [
{
label: 'Metadata',
click: async () => {
// TODO
}
},
{
label: 'Errors panel',
click: async () => {
// TODO
}
},
{
label: 'Source',
click: async () => {
// TODO
}
},
] as MenuItemConstructorOptions[]
},
{
label: 'Help',
submenu: [
{
label: 'ODE User guide',
click: async () => {
const { shell } = require('electron')
await shell.openExternal('https://opendataeditor.okfn.org/documentation/getting-started/')
}
},
{
label: 'Report an issue',
click: async () => {
const { shell } = require('electron')
await shell.openExternal('https://github.com/okfn/opendataeditor/')
}
}
] as MenuItemConstructorOptions[]
},
]

export default Menu.buildFromTemplate(template)
1 change: 1 addition & 0 deletions desktop/preload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { contextBridge, ipcRenderer } from 'electron'
contextBridge.exposeInMainWorld('opendataeditor', {
sendFatalError: (message: string) => ipcRenderer.invoke('sendFatalError', message),
openDirectoryDialog: () => ipcRenderer.invoke('openDirectoryDialog'),
createNewFolder: (callback: (value: string) => {}) => ipcRenderer.on('menu-clicked', (_event, value) => callback(value)),

ensureLogs: (callback: any) => ipcRenderer.on('ensureLogs', (_event, message: string) => callback(message)),
openPathInExplorer: (path: string) => ipcRenderer.send('openPathInExplorer', path),
Expand Down
7 changes: 7 additions & 0 deletions desktop/renderer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { openDialog } from '../client/store/actions/dialog'

// @ts-ignore
window?.opendataeditor?.createNewFolder( ( value: string ) => {
console.log('value', value)
openDialog('addEmptyFolder')
})
2 changes: 1 addition & 1 deletion desktop/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ export async function createWindow() {

const mainWindow = new BrowserWindow({
show: false,
autoHideMenuBar: true,
...(process.platform === 'linux' ? { icon } : {}),
webPreferences: {
preload: join(__dirname, 'preload', 'index.js'),
contextIsolation: true,
},
})

Expand Down
Loading