Skip to content

Commit

Permalink
Basic menu.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaston Figueroa authored and gastonfig committed May 15, 2018
1 parent c359729 commit 4840ecf
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
52 changes: 51 additions & 1 deletion public/electron.js
@@ -1,4 +1,4 @@
const { app, BrowserWindow, Tray } = require('electron');
const { app, BrowserWindow, Menu, Tray } = require('electron');
const path = require('path');
const url = require('url');

Expand All @@ -15,6 +15,53 @@ function createWindow() {
width: 800
});

const menuTemplate = [
{
label: 'Electron',
submenu: [
{
role: 'about'
},
{
type: 'separator'
},
{
role: 'quit'
}
]
},
{
label: 'File',
submenu: [
{
label: 'Open',
click: () => {
mainWindow.webContents.send('openFile');
}
}
]
},
{
label: 'Actions',
submenu: [
{
label: 'Always on top',
type: 'checkbox',
checked: mainWindow.isAlwaysOnTop(),
click: () => {
mainWindow.setAlwaysOnTop(!mainWindow.isAlwaysOnTop());
}
},
{
type: 'separator'
},
{ role: 'reload' },
{ role: 'forcereload' },
{ role: 'toggledevtools' }
]
}
];

// and load the index.html of the app.
const startUrl =
process.env.ELECTRON_START_URL ||
Expand All @@ -40,6 +87,9 @@ function createWindow() {
mainWindow.on('resize', function() {
mainWindow.setHasShadow(false);
});

const menu = Menu.buildFromTemplate(menuTemplate);
Menu.setApplicationMenu(menu);
}

// This method will be called when Electron has finished
Expand Down
6 changes: 6 additions & 0 deletions src/App.js
Expand Up @@ -7,6 +7,8 @@ import Titlebar from './components/Titlebar';
import { loadImage, readFile } from './utils/loadImage';
import { defaultImg } from './data/defaultImg';

const ipcRenderer = window.require('electron').ipcRenderer;

class App extends Component {
constructor(props) {
super(props);
Expand Down Expand Up @@ -40,6 +42,10 @@ class App extends Component {
readFile(this.updateImage, filePath);
e.preventDefault();
};

ipcRenderer.on('openFile', (event, message) => {
this.handleImageLoad();
});
}

render() {
Expand Down

0 comments on commit 4840ecf

Please sign in to comment.