Skip to content

Commit 4a9256c

Browse files
WaleyChenkangas
authored andcommitted
INT-833 Make help window a singleton, change window size
Squashed: INT-833 help window not clicking element bug fix INT-833 code cleanup INT-833 fix nom run check INT-833 redundant code INT-833 use loadURL instead of executeJS send message instead of loadURL, much faster
1 parent b698671 commit 4a9256c

File tree

5 files changed

+79
-68
lines changed

5 files changed

+79
-68
lines changed

src/app.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ var MongoDBInstance = require('./models/mongodb-instance');
2828
var User = require('./models/user');
2929
var Router = require('./router');
3030
var Statusbar = require('./statusbar');
31-
var Help = require('./help');
3231
var $ = require('jquery');
3332

3433
var debug = require('debug')('scout:app');
@@ -126,7 +125,7 @@ var Application = View.extend({
126125
},
127126
onHelpClicked: function(evt) {
128127
var id = $(evt.target).attr('data-hook');
129-
Help.open(id);
128+
app.sendMessage('show help window', id);
130129
},
131130
onClientReady: function() {
132131
debug('Client ready! Took %dms to become readable',
@@ -291,12 +290,12 @@ app.extend({
291290
setFeature: function(id, bool) {
292291
FEATURES[id] = bool;
293292
},
294-
sendMessage: function(msg, arg1) {
295-
ipc.send('message', msg, arg1);
293+
sendMessage: function(msg, arg) {
294+
ipc.send('message', msg, arg);
296295
},
297-
onMessageReceived: function(msg) {
298-
debug('message received from main process:', msg);
299-
this.trigger(msg);
296+
onMessageReceived: function(msg, arg) {
297+
debug('message received from main process:', msg, arg);
298+
this.trigger(msg, arg);
300299
},
301300
metrics: metrics,
302301
init: function() {

src/electron/menu.js

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
// based off of https://github.com/atom/atom/blob/master/src/browser/application-menu.coffee
22
// use js2.coffee to convert it to JS
33

4-
var _ = require('lodash');
5-
var app = require('app');
64
var BrowserWindow = require('browser-window');
7-
var debug = require('debug')('electron:menu');
85
var Menu = require('menu');
96
var State = require('ampersand-state');
107

8+
var _ = require('lodash');
9+
var app = require('app');
10+
var debug = require('debug')('electron:menu');
11+
1112
// submenu related
1213
function separator() {
1314
return {
1415
type: 'separator'
1516
};
1617
}
1718

18-
function quitSubMenu(label) {
19+
function quitSubMenuItem(label) {
1920
return {
2021
label: label,
2122
accelerator: 'CmdOrCtrl+Q',
@@ -25,7 +26,7 @@ function quitSubMenu(label) {
2526
};
2627
}
2728

28-
function compassOverviewSubMenu() {
29+
function compassOverviewSubMenuItem() {
2930
return {
3031
label: 'Compass Overview',
3132
click: function() {
@@ -58,7 +59,7 @@ function darwinCompassSubMenu() {
5859
selector: 'unhideAllApplications:'
5960
},
6061
separator(),
61-
quitSubMenu('Quit')
62+
quitSubMenuItem('Quit')
6263
]
6364
};
6465
}
@@ -126,7 +127,7 @@ function editSubMenu() {
126127
};
127128
}
128129

129-
function nonDarwinAboutSubMenu() {
130+
function nonDarwinAboutSubMenuItem() {
130131
return {
131132
label: 'About Compass',
132133
click: function() {
@@ -135,18 +136,27 @@ function nonDarwinAboutSubMenu() {
135136
};
136137
}
137138

139+
function helpWindowSubMenuItem() {
140+
return {
141+
label: 'Help',
142+
accelerator: 'CmdOrCtrl+H',
143+
click: function() {
144+
app.emit('show help window');
145+
}
146+
};
147+
}
148+
138149
function helpSubMenu(showCompassOverview) {
139150
var subMenu = [];
140-
if (showCompassOverview) {
141-
subMenu.push(compassOverviewSubMenu());
151+
subMenu.push(helpWindowSubMenuItem());
142152

143-
if (process.platform !== 'darwin') {
144-
subMenu.push(separator());
145-
}
153+
if (showCompassOverview) {
154+
subMenu.push(compassOverviewSubMenuItem());
146155
}
147156

148157
if (process.platform !== 'darwin') {
149-
subMenu.push(nonDarwinAboutSubMenu());
158+
subMenu.push(separator());
159+
subMenu.push(nonDarwinAboutSubMenuItem());
150160
}
151161

152162
return {
@@ -155,6 +165,15 @@ function helpSubMenu(showCompassOverview) {
155165
};
156166
}
157167

168+
function nonDarwinCompassSubMenuItem() {
169+
return {
170+
label: 'MongoDB Compass',
171+
submenu: [
172+
quitSubMenuItem('Exit')
173+
]
174+
};
175+
}
176+
158177
function shareSubMenu() {
159178
return {
160179
label: 'Share',
@@ -230,20 +249,19 @@ function darwinMenu(menuState) {
230249
}
231250

232251
menu.push(windowSubMenu());
233-
234-
if (menuState.showCompassOverview) {
235-
menu.push(helpSubMenu(menuState.showCompassOverview));
236-
}
252+
menu.push(helpSubMenu(menuState.showCompassOverview));
237253

238254
return menu;
239255
}
240256

241257
function nonDarwinMenu(menuState) {
242258
var menu = [
243-
connectSubMenu(true),
244-
viewSubMenu()
259+
nonDarwinCompassSubMenuItem()
245260
];
246261

262+
menu.push(connectSubMenu());
263+
menu.push(viewSubMenu());
264+
247265
if (menuState.showShare) {
248266
menu.push(shareSubMenu());
249267
}
@@ -297,10 +315,6 @@ var AppMenu = (function() {
297315
getTemplate: function(winID) {
298316
var menuState = this.windowTemplates.get(winID);
299317

300-
debug('WINDOW\'s ' + winID + ' Menu State');
301-
debug('showCompassOverview: ' + menuState.showCompassOverview);
302-
debug('showShare: ' + menuState.showShare);
303-
304318
if (process.platform === 'darwin') {
305319
return darwinMenu(menuState);
306320
}
@@ -339,7 +353,6 @@ var AppMenu = (function() {
339353
Menu.setApplicationMenu(menu);
340354
},
341355

342-
// share/hide submenu fns
343356
hideShare: function() {
344357
this.updateMenu('showShare', false);
345358
},

src/electron/window-manager.js

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,36 @@
33
* [BrowserWindow](https://github.com/atom/electron/blob/master/docs/api/browser-window.md)
44
* class
55
*/
6-
76
var AppMenu = require('./menu');
87
var BrowserWindow = require('browser-window');
98
var Notifier = require('node-notifier');
10-
var Path = require('path');
119

1210
var _ = require('lodash');
1311
var app = require('app');
1412
var config = require('./config');
1513
var debug = require('debug')('scout-electron:window-manager');
1614
var dialog = require('dialog');
15+
var path = require('path');
1716

1817
/**
1918
* When running in electron, we're in `RESOURCES/src/electron`.
2019
*/
21-
var RESOURCES = Path.resolve(__dirname, '../../');
22-
var SCOUT_ICON_PATH = RESOURCES + '/images/scout.png';
20+
var RESOURCES = path.resolve(__dirname, '../../');
2321

2422
/**
2523
* The app's HTML shell which is the output of `./src/index.jade`
2624
* created by the `build:pages` gulp task.
2725
*/
28-
var DEFAULT_URL = 'file://' + Path.join(RESOURCES, 'index.html#connect');
26+
var DEFAULT_URL = 'file://' + path.join(RESOURCES, 'index.html#connect');
27+
var HELP_URL = 'file://' + path.join(RESOURCES, 'index.html#help');
2928

3029
/**
31-
* We want the Connect dialog window to be special
32-
* and for there to ever only be one instance of it
33-
* so we'll use scope to essentially make it a Singleton.
30+
* We want the Connect and Help window to be special
31+
* and for there to ever only be one instance of each of them
32+
* so we'll use scope to essentially make each of them a Singleton.
3433
*/
3534
var connectWindow;
35+
var helpWindow;
3636

3737
// @todo (imlucas): Removed in setup branch as we dont need to do this anymore
3838
// as a `all-windows-closed` event has been added to the `app` event api
@@ -136,11 +136,6 @@ function createWindow(opts, url) {
136136
return module.exports.create(opts);
137137
}
138138

139-
app.on('close connect', function() {
140-
connectWindow.close();
141-
connectWindow = null;
142-
});
143-
144139
app.on('show about dialog', function() {
145140
dialog.showMessageBox({
146141
type: 'info',
@@ -156,9 +151,29 @@ app.on('show connect dialog', function() {
156151
}
157152

158153
connectWindow = createWindow({}, DEFAULT_URL);
159-
connectWindow.on('focus', function() {
160-
debug('connect window focused.');
161-
connectWindow.webContents.send('message', 'connect-window-focused');
154+
connectWindow.on('closed', function() {
155+
debug('connect window closed.');
156+
connectWindow = null;
157+
});
158+
});
159+
160+
app.on('show help window', function(id) {
161+
if (helpWindow) {
162+
helpWindow.focus();
163+
if (_.isString(id)) {
164+
helpWindow.webContents.send('message', 'show-help-entry', id);
165+
}
166+
return;
167+
}
168+
169+
var url = HELP_URL;
170+
if (_.isString(id)) {
171+
url += '/' + id;
172+
}
173+
174+
helpWindow = createWindow({}, url);
175+
helpWindow.on('closed', function() {
176+
helpWindow = null;
162177
});
163178
});
164179

@@ -203,7 +218,7 @@ app.on('ready', function() {
203218
});
204219

205220
var ipc = require('ipc');
206-
ipc.on('message', function(event, msg, arg1) {
207-
debug('message received in main process', msg);
208-
app.emit(msg, arg1);
221+
ipc.on('message', function(event, msg, arg) {
222+
debug('message received in main process', msg, arg);
223+
app.emit(msg, arg, event);
209224
});

src/help/index.js

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ var HelpPage = View.extend({
6969
this.show(this.entryId);
7070
}
7171
});
72+
73+
this.listenTo(app, 'show-help-entry', this.show.bind(this));
7274
},
7375
show: function(entryId) {
7476
debug('show `%s`', entryId);
@@ -145,21 +147,4 @@ var HelpPage = View.extend({
145147
}
146148
});
147149

148-
/**
149-
* Convenience to open the help window if needed and show an item.
150-
*
151-
* @param {String} [entryId] - Optional filename to show from `./items/#{entryId}.jade`.
152-
*
153-
* @todo (imlucas) Add helper to `./src/electron/window-manager.js` so this works
154-
* like connect window (singleton w/ custom dimensions).
155-
*/
156-
HelpPage.open = function(entryId) {
157-
var url = format('%s?#help', window.location.origin);
158-
if (entryId) {
159-
url += '/' + entryId;
160-
}
161-
debug('Opening item `%s`', entryId);
162-
window.open(url);
163-
};
164-
165150
module.exports = HelpPage;

src/home/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ var HomeView = View.extend({
4949
this.once('change:rendered', this.onRendered);
5050
debug('fetching instance model...');
5151
app.instance.fetch();
52-
5352
app.sendMessage('show compass overview submenu');
5453
},
5554
render: function() {

0 commit comments

Comments
 (0)