From e758078a8d3af16a21a946ed35a46d7e7d10c1d0 Mon Sep 17 00:00:00 2001 From: Gregory Ballantine Date: Wed, 12 Apr 2023 21:22:11 -0400 Subject: [PATCH] Started working on the app menu --- assets/twig/about.twig | 12 ++++++++++++ main.js | 8 ++++++-- src/menu/help.js | 15 +++++++++++++++ src/menu/index.js | 30 ++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 assets/twig/about.twig create mode 100644 src/menu/help.js create mode 100644 src/menu/index.js diff --git a/assets/twig/about.twig b/assets/twig/about.twig new file mode 100644 index 0000000..64c081f --- /dev/null +++ b/assets/twig/about.twig @@ -0,0 +1,12 @@ + + + + + + + About Sentry + + +

This is a test.

+ + diff --git a/main.js b/main.js index 65fcbdc..2bd741a 100644 --- a/main.js +++ b/main.js @@ -1,5 +1,5 @@ // Modules to control application life and create native browser window -const {app, BrowserWindow} = require('electron'); +const { app, BrowserWindow, Menu } = require('electron'); const path = require('path'); function createWindow () { @@ -7,7 +7,7 @@ function createWindow () { const mainWindow = new BrowserWindow({ width: 800, height: 700, - minWidth: 725, + minWidth: 735, minHeight: 600, webPreferences: { nodeIntegration: true, @@ -23,6 +23,10 @@ function createWindow () { // mainWindow.webContents.openDevTools() } +// Set the application menu +const menu = require('./src/menu').createMenu(app); +Menu.setApplicationMenu(menu); + // This method will be called when Electron has finished // initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs. diff --git a/src/menu/help.js b/src/menu/help.js new file mode 100644 index 0000000..07a90a6 --- /dev/null +++ b/src/menu/help.js @@ -0,0 +1,15 @@ +const { BrowserWindow } = require('electron'); + +exports.about = function() { + const aboutWindow = new BrowserWindow({ + width: 600, + height: 400, + webPreferences: { + nodeIntegration: true, + contextIsolation: false + } + }); + + // and load the about.html of the app. + aboutWindow.loadFile('public/about.html'); +}; diff --git a/src/menu/index.js b/src/menu/index.js new file mode 100644 index 0000000..c4d6d99 --- /dev/null +++ b/src/menu/index.js @@ -0,0 +1,30 @@ +const electron = require('electron'); + +// load event handlers +const helpHandlers = require('./help'); + +exports.createMenu = function(app) { + return electron.Menu.buildFromTemplate([ + { + label: 'File', + submenu: [ + { + label: 'Close', + click: function() { + app.quit(); + } + } + ] + }, + + { + label: 'Help', + submenu: [ + { + label: 'About', + click: helpHandlers.about + } + ] + } + ]); +};