Skip to content

Commit dca076e

Browse files
rueckstiesskangas
authored andcommitted
INT-1434 app launched event (#389)
* INT-1434 fix window:renderer-ready and app:launched events * Only set debug namespaces on app launch This allows to change debug namespaces during app runtime via dev console.
1 parent 02e8dc0 commit dca076e

File tree

2 files changed

+29
-23
lines changed

2 files changed

+29
-23
lines changed

src/app/index.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
11
/* eslint no-console:0 */
2-
if (process.env.NODE_ENV !== 'production') {
3-
require('debug').enable('mon*,had*');
4-
require('debug/browser');
5-
require('debug').enable('mon*,had*');
6-
}
7-
8-
var debug = require('debug')('mongodb-compass:app');
92

103
console.time('app/index.js');
114

@@ -60,6 +53,16 @@ var AutoUpdate = require('../auto-update');
6053

6154
var addInspectElementMenu = require('debug-menu').install;
6255

56+
ipc.once('app:launched', function() {
57+
console.log('in app:launched');
58+
if (process.env.NODE_ENV !== 'production') {
59+
require('debug').enable('mon*,had*');
60+
require('debug/browser');
61+
}
62+
});
63+
64+
var debug = require('debug')('mongodb-compass:app');
65+
6366
function getConnection(model, done) {
6467
function _fetch(fn) {
6568
model.fetch({
@@ -409,7 +412,7 @@ app.extend({
409412
metricsSetup();
410413

411414
// signal to main process that app is ready
412-
ipc.call('app:renderer-ready');
415+
ipc.call('window:renderer-ready');
413416

414417
// as soon as dom is ready, render and set up the rest
415418
self.onDomReady();

src/main/window-manager.js

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,22 @@ function hideShareSubmenu() {
207207
AppMenu.hideShare();
208208
}
209209

210+
/**
211+
* can't use webContents `did-finish-load` event here because
212+
* metrics aren't set up at that point. renderer app sends custom event
213+
* `window:renderer-ready` when metrics are set up. If first app launch,
214+
* send back `app:launched` message at that point.
215+
*
216+
* @param {Object} sender original sender of the event
217+
*/
218+
function rendererReady(sender) {
219+
if (!appLaunched) {
220+
appLaunched = true;
221+
debug('sending `app:launched` msg back');
222+
sender.send('app:launched');
223+
}
224+
}
225+
210226
// respond to events from the renderer process
211227
ipc.respondTo({
212228
'app:show-connect-window': showConnectWindow,
@@ -215,28 +231,15 @@ ipc.respondTo({
215231
'window:show-about-dialog': showAboutDialog,
216232
'window:show-share-submenu': showShareSubmenu,
217233
'window:hide-share-submenu': hideShareSubmenu,
218-
'window:show-compass-overview-submenu': showCompassOverview
234+
'window:show-compass-overview-submenu': showCompassOverview,
235+
'window:renderer-ready': rendererReady
219236
});
220237

221238
// respond to events from the main process
222239
app.on('window:show-about-dialog', showAboutDialog);
223240
app.on('app:show-connect-window', showConnectWindow);
224241
app.on('app:show-help-window', showHelpWindow);
225242

226-
/**
227-
* can't use webContents `did-finish-load` event here because
228-
* metrics aren't set up at that point. renderer app sends custom event
229-
* `renderer ready` when metrics are set up. If first app launch, send back
230-
* `app launched` message at that point.
231-
*/
232-
app.on('window:renderer-ready', function(arg, event) {
233-
if (!appLaunched) {
234-
appLaunched = true;
235-
debug('sending `app:launched` msg back');
236-
event.sender.send('app:launched');
237-
}
238-
});
239-
240243
app.on('before-quit', function() {
241244
debug('sending `app:quit` msg');
242245
_.first(BrowserWindow.getAllWindows()).webContents.send('app:quit');

0 commit comments

Comments
 (0)