Skip to content

Commit

Permalink
Only send ipc message if webContents is available
Browse files Browse the repository at this point in the history
Close #306
  • Loading branch information
maxcnunes committed Jun 1, 2017
1 parent b1adf5b commit 0c92e71
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 24 deletions.
22 changes: 14 additions & 8 deletions src/browser/menu/darwin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { shell } from 'electron'; // eslint-disable-line import/no-unresolved

function sendMessage(win, message) {
if (win) {
win.webContents.send(message);
}
}

export function buildTemplate(app, buildNewWindow, appConfig) {
return [
{
Expand Down Expand Up @@ -54,20 +60,20 @@ export function buildTemplate(app, buildNewWindow, appConfig) {
{
label: 'New Tab',
accelerator: 'Cmd+T',
click: (item, win) => win.webContents.send('sqlectron:new-tab'),
click: (item, win) => sendMessage(win, 'sqlectron:new-tab'),
},
{
label: 'Close Tab',
accelerator: 'Cmd+W',
click: (item, win) => win.webContents.send('sqlectron:close-tab'),
click: (item, win) => sendMessage(win, 'sqlectron:close-tab'),
},
{
type: 'separator',
},
{
label: 'Save Query',
accelerator: 'Cmd+S',
click: (item, win) => win.webContents.send('sqlectron:save-query'),
click: (item, win) => sendMessage(win, 'sqlectron:save-query'),
},
],
},
Expand All @@ -77,17 +83,17 @@ export function buildTemplate(app, buildNewWindow, appConfig) {
{
label: 'Execute',
accelerator: 'Cmd+Enter',
click: (item, win) => win.webContents.send('sqlectron:query-execute'),
click: (item, win) => sendMessage(win, 'sqlectron:query-execute'),
},
{
label: 'Execute',
accelerator: 'Cmd+R',
click: (item, win) => win.webContents.send('sqlectron:query-execute'),
click: (item, win) => sendMessage(win, 'sqlectron:query-execute'),
},
{
label: 'Focus Query Editor',
accelerator: 'Shift+Cmd+0',
click: (item, win) => win.webContents.send('sqlectron:query-focus'),
click: (item, win) => sendMessage(win, 'sqlectron:query-focus'),
},
],
},
Expand Down Expand Up @@ -150,12 +156,12 @@ export function buildTemplate(app, buildNewWindow, appConfig) {
{
label: 'Search databases',
accelerator: 'Shift+Cmd+9',
click: (item, win) => win.webContents.send('sqlectron:toggle-database-search'),
click: (item, win) => sendMessage(win, 'sqlectron:toggle-database-search'),
},
{
label: 'Search database objects',
accelerator: 'Cmd+9',
click: (item, win) => win.webContents.send('sqlectron:toggle-database-objects-search'),
click: (item, win) => sendMessage(win, 'sqlectron:toggle-database-objects-search'),
},
],
},
Expand Down
22 changes: 14 additions & 8 deletions src/browser/menu/linux.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { shell } from 'electron'; // eslint-disable-line import/no-unresolved

function sendMessage(win, message) {
if (win) {
win.webContents.send(message);
}
}


export function buildTemplate(app, buildNewWindow, appConfig) {
return [
Expand All @@ -14,20 +20,20 @@ export function buildTemplate(app, buildNewWindow, appConfig) {
{
label: 'New Tab',
accelerator: 'Ctrl+T',
click: (item, win) => win.webContents.send('sqlectron:new-tab'),
click: (item, win) => sendMessage(win, 'sqlectron:new-tab'),
},
{
label: 'Close Tab',
accelerator: 'Ctrl+W',
click: (item, win) => win.webContents.send('sqlectron:close-tab'),
click: (item, win) => sendMessage(win, 'sqlectron:close-tab'),
},
{
type: 'separator',
},
{
label: 'Save Query',
accelerator: 'Ctrl+S',
click: (item, win) => win.webContents.send('sqlectron:save-query'),
click: (item, win) => sendMessage(win, 'sqlectron:save-query'),
},
{
type: 'separator',
Expand All @@ -45,17 +51,17 @@ export function buildTemplate(app, buildNewWindow, appConfig) {
{
label: 'Execute',
accelerator: 'Ctrl+Enter',
click: (item, win) => win.webContents.send('sqlectron:query-execute'),
click: (item, win) => sendMessage(win, 'sqlectron:query-execute'),
},
{
label: 'Execute',
accelerator: 'Ctrl+R',
click: (item, win) => win.webContents.send('sqlectron:query-execute'),
click: (item, win) => sendMessage(win, 'sqlectron:query-execute'),
},
{
label: 'Focus Query Editor',
accelerator: 'Shift+Ctrl+0',
click: (item, win) => win.webContents.send('sqlectron:query-focus'),
click: (item, win) => sendMessage(win, 'sqlectron:query-focus'),
},
],
},
Expand Down Expand Up @@ -118,12 +124,12 @@ export function buildTemplate(app, buildNewWindow, appConfig) {
{
label: 'Search databases',
accelerator: 'Shift+Ctrl+9',
click: (item, win) => win.webContents.send('sqlectron:toggle-database-search'),
click: (item, win) => sendMessage(win, 'sqlectron:toggle-database-search'),
},
{
label: 'Search database objects',
accelerator: 'Ctrl+9',
click: (item, win) => win.webContents.send('sqlectron:toggle-database-objects-search'),
click: (item, win) => sendMessage(win, 'sqlectron:toggle-database-objects-search'),
},
],
},
Expand Down
22 changes: 14 additions & 8 deletions src/browser/menu/win32.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { shell } from 'electron'; // eslint-disable-line import/no-unresolved

function sendMessage(win, message) {
if (win) {
win.webContents.send(message);
}
}


export function buildTemplate(app, buildNewWindow, appConfig) {
return [
Expand All @@ -14,20 +20,20 @@ export function buildTemplate(app, buildNewWindow, appConfig) {
{
label: 'New Tab',
accelerator: 'Ctrl+T',
click: (item, win) => win.webContents.send('sqlectron:new-tab'),
click: (item, win) => sendMessage(win, 'sqlectron:new-tab'),
},
{
label: 'Close Tab',
accelerator: 'Ctrl+W',
click: (item, win) => win.webContents.send('sqlectron:close-tab'),
click: (item, win) => sendMessage(win, 'sqlectron:close-tab'),
},
{
type: 'separator',
},
{
label: 'Save Query',
accelerator: 'Ctrl+S',
click: (item, win) => win.webContents.send('sqlectron:save-query'),
click: (item, win) => sendMessage(win, 'sqlectron:save-query'),
},
{
type: 'separator',
Expand All @@ -45,17 +51,17 @@ export function buildTemplate(app, buildNewWindow, appConfig) {
{
label: 'Execute',
accelerator: 'Ctrl+Enter',
click: (item, win) => win.webContents.send('sqlectron:query-execute'),
click: (item, win) => sendMessage(win, 'sqlectron:query-execute'),
},
{
label: 'Execute',
accelerator: 'Ctrl+R',
click: (item, win) => win.webContents.send('sqlectron:query-execute'),
click: (item, win) => sendMessage(win, 'sqlectron:query-execute'),
},
{
label: 'Focus Query Editor',
accelerator: 'Shift+Ctrl+0',
click: (item, win) => win.webContents.send('sqlectron:query-focus'),
click: (item, win) => sendMessage(win, 'sqlectron:query-focus'),
},
],
},
Expand Down Expand Up @@ -118,12 +124,12 @@ export function buildTemplate(app, buildNewWindow, appConfig) {
{
label: 'Search databases',
accelerator: 'Shift+Ctrl+9',
click: (item, win) => win.webContents.send('sqlectron:toggle-database-search'),
click: (item, win) => sendMessage(win, 'sqlectron:toggle-database-search'),
},
{
label: 'Search database objects',
accelerator: 'Ctrl+9',
click: (item, win) => win.webContents.send('sqlectron:toggle-database-objects-search'),
click: (item, win) => sendMessage(win, 'sqlectron:toggle-database-objects-search'),
},
],
},
Expand Down

0 comments on commit 0c92e71

Please sign in to comment.