Skip to content
This repository was archived by the owner on Sep 6, 2023. It is now read-only.

Commit

Permalink
Only register app-command listeners on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
jwheare committed May 17, 2019
1 parent 694923a commit 7286621
Showing 1 changed file with 35 additions and 31 deletions.
66 changes: 35 additions & 31 deletions app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,21 +262,6 @@ function openMainWindow(opts) {
log.debug('closed');
mainWindow = null;
});

mainWindow.on('swipe', function (e, direction) {
switch (direction) {
case 'right':
if (mainWindow.webContents.canGoForward()) {
mainWindow.webContents.goForward();
}
break;
case 'left':
if (mainWindow.webContents.canGoBack()) {
mainWindow.webContents.goBack();
}
break;
}
});

mainWindow.on('page-title-updated', function(event) {
var title = mainWindow.getTitle();
Expand All @@ -289,30 +274,49 @@ function openMainWindow(opts) {
app.dock.setBadge(unread);
}
});

mainWindow.on('app-command', function (e, cmd) {
switch (cmd) {
case 'browser-backward':
if (mainWindow.webContents.canGoBack()) {
e.preventDefault();
mainWindow.webContents.goBack();
}
break;
case 'browser-forward':

mainWindow.on('swipe', function (e, direction) {
switch (direction) {
case 'right':
if (mainWindow.webContents.canGoForward()) {
e.preventDefault();
mainWindow.webContents.goForward();
}
break;
case 'browser-refresh':
e.preventDefault();
mainWindow.webContents.reloadIgnoringCache();
break;
default:
case 'left':
if (mainWindow.webContents.canGoBack()) {
mainWindow.webContents.goBack();
}
break;
}
});

// This is apparently not needed on linux, and results in double actions
// despite the documentation
// https://github.com/electron/electron/issues/18322
// https://github.com/irccloud/irccloud-desktop/issues/86
// macOS doesn't use app-command
if (is.windows()) {
mainWindow.on('app-command', function (e, cmd) {
switch (cmd) {
case 'browser-backward':
if (mainWindow.webContents.canGoBack()) {
mainWindow.webContents.goBack();
}
break;
case 'browser-forward':
if (mainWindow.webContents.canGoForward()) {
mainWindow.webContents.goForward();
}
break;
case 'browser-refresh':
mainWindow.webContents.reloadIgnoringCache();
break;
default:
break;
}
});
}

ContextMenu(mainWindow);

mainWindow.webContents.on('preload-error', function (event, preloadPath, error) {
Expand Down

0 comments on commit 7286621

Please sign in to comment.