ELECTRON-607 (Optimization and bug fix) (#455)

- Fix setLocale args
- Optimize Alt key press
- Optimize title bar style menu selection
This commit is contained in:
Kiran Niranjan 2018-08-07 18:02:02 +05:30 committed by Vishwas Shashidhar
parent 6746fb294c
commit 3ce535ae21
3 changed files with 31 additions and 6 deletions

View File

@ -402,8 +402,15 @@ function getTemplate(app) {
label: i18n.getMessageFor('Native'),
type: 'checkbox',
checked: titleBarStyle === titleBarStyles.NATIVE,
enabled: titleBarStyle !== titleBarStyles.NATIVE,
click: function (item) {
item.menu.items[1].checked = false;
const isNativeStyle = titleBarStyle === titleBarStyles.NATIVE;
item.menu.items[1].checked = isNativeStyle;
// Disable menu item accordingly
item.menu.items[0].enabled = isNativeStyle;
item.menu.items[1].enabled = !isNativeStyle;
titleBarStyle = titleBarStyles.NATIVE;
updateConfigField('isCustomTitleBar', false);
titleBarActions(app);
@ -413,8 +420,15 @@ function getTemplate(app) {
label: i18n.getMessageFor('Custom'),
type: 'checkbox',
checked: titleBarStyle === titleBarStyles.CUSTOM,
enabled: titleBarStyle !== titleBarStyles.CUSTOM,
click: function (item) {
item.menu.items[0].checked = false;
const isCustomStyle = titleBarStyle === titleBarStyles.CUSTOM;
item.menu.items[0].checked = isCustomStyle;
// Disable menu item accordingly
item.menu.items[1].enabled = isCustomStyle;
item.menu.items[0].enabled = !isCustomStyle;
titleBarStyle = titleBarStyles.CUSTOM;
updateConfigField('isCustomTitleBar', true);
titleBarActions(app);

View File

@ -32,6 +32,7 @@ const KeyCodes = {
let Search;
let SearchUtils;
let isAltKey = false;
let isMenuOpen = false;
try {
Search = remote.require('swift-search').Search;
@ -503,7 +504,7 @@ function createAPI() {
}
// Handle key down events
const throttledKeyDown = throttle(1000, (event) => {
const throttledKeyDown = throttle(500, (event) => {
isAltKey = event.keyCode === KeyCodes.Alt;
if (event.keyCode === KeyCodes.Esc) {
local.ipcRenderer.send(apiName, {
@ -514,8 +515,11 @@ function createAPI() {
});
// Handle key up events
const throttledKeyUp = throttle(1000, (event) => {
if (isAltKey && event.keyCode === KeyCodes.Alt) {
const throttledKeyUp = throttle(500, (event) => {
if (isAltKey && (event.keyCode === KeyCodes.Alt || KeyCodes.Esc)) {
isMenuOpen = !isMenuOpen;
}
if (isAltKey && isMenuOpen && event.keyCode === KeyCodes.Alt) {
local.ipcRenderer.send(apiName, {
cmd: apiCmds.keyPress,
keyCode: event.keyCode
@ -523,11 +527,18 @@ function createAPI() {
}
});
const throttleMouseDown = throttle(500, () => {
if (isAltKey && isMenuOpen) {
isMenuOpen = !isMenuOpen;
}
});
window.addEventListener('offline', updateOnlineStatus, false);
window.addEventListener('online', updateOnlineStatus, false);
window.addEventListener('beforeunload', sanitize, false);
window.addEventListener('keyup', throttledKeyUp, true);
window.addEventListener('keydown', throttledKeyDown, true);
window.addEventListener('mousedown', throttleMouseDown, { capture: true });
updateOnlineStatus();
}

View File

@ -322,7 +322,7 @@ function doCreateMainWindow(initialUrl, initialBounds, isCustomTitleBar) {
addWindowKey(key, mainWindow);
mainWindow.loadURL(url);
setLocale(mainWindow, lang);
setLocale(mainWindow, { language: lang });
mainWindow.on('close', function (e) {
if (willQuitApp) {