From a4f119bcae16df6aed7c772ead779cfc366b97c0 Mon Sep 17 00:00:00 2001 From: Yuya Ochiai Date: Sat, 21 May 2016 16:13:22 +0900 Subject: [PATCH] Update menu when the config is updated --- src/browser/settings.jsx | 3 ++- src/main.js | 10 +++++++--- src/main/menus/app.js | 18 +++++++----------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/browser/settings.jsx b/src/browser/settings.jsx index 74442c1d..99ec2e10 100644 --- a/src/browser/settings.jsx +++ b/src/browser/settings.jsx @@ -1,6 +1,6 @@ 'use strict'; -const remote = require('electron').remote; +const {remote, ipcRenderer} = require('electron'); const settings = require('../common/settings'); const React = require('react'); @@ -50,6 +50,7 @@ var SettingsPage = React.createClass({ currentWindow.setAutoHideMenuBar(config.hideMenuBar); currentWindow.setMenuBarVisibility(!config.hideMenuBar); } + ipcRenderer.send('update-menu', config); backToIndex(); }, handleCancel: function() { diff --git a/src/main.js b/src/main.js index 1042d91c..91920116 100644 --- a/src/main.js +++ b/src/main.js @@ -231,6 +231,13 @@ app.on('ready', function() { // and load the index.html of the app. mainWindow.loadURL('file://' + __dirname + '/browser/index.html'); + // Set application menu + ipc.on('update-menu', (event, config) => { + var app_menu = appMenu.createMenu(mainWindow, config); + Menu.setApplicationMenu(app_menu); + }); + ipc.emit('update-menu', true, config); + // Open the DevTools. // mainWindow.openDevTools(); @@ -274,9 +281,6 @@ app.on('ready', function() { saveWindowState(bounds_info_path, mainWindow); }); - var app_menu = appMenu.createMenu(mainWindow, config); - Menu.setApplicationMenu(app_menu); - // Emitted when the window is closed. mainWindow.on('closed', function() { // Dereference the window object, usually you would store windows diff --git a/src/main/menus/app.js b/src/main/menus/app.js index a0132984..471de492 100644 --- a/src/main/menus/app.js +++ b/src/main/menus/app.js @@ -138,7 +138,7 @@ var createTemplate = function(mainWindow, config) { } } }, separatorItem, { - label: 'Actual size', + label: 'Actual Size', accelerator: 'CmdOrCtrl+0', click: () => { mainWindow.webContents.send('zoom-reset'); @@ -187,25 +187,21 @@ var createTemplate = function(mainWindow, config) { mainWindow.webContents.send('switch-tab', i); } }; - })] - } - - if (config.teams.length > 1) { - window_menu.submenu = window_menu.submenu.concat([{ - type: 'separator' - }, { + }), separatorItem, { label: 'Select Next Team', accelerator: (process.platform === 'darwin') ? 'Alt+Cmd+Right' : 'CmdOrCtrl+Tab', click: () => { mainWindow.webContents.send('select-next-tab'); - } + }, + enabled: (config.teams.length > 1) }, { label: 'Select Previous Team', accelerator: (process.platform === 'darwin') ? 'Alt+Cmd+Left' : 'CmdOrCtrl+Shift+Tab', click: () => { mainWindow.webContents.send('select-previous-tab'); - } - }]); + }, + enabled: (config.teams.length > 1) + }] } template.push(window_menu);