@@ -14,6 +14,10 @@ var getOrCreateClient = require('scout-client');
14
14
var ViewSwitcher = require ( 'ampersand-view-switcher' ) ;
15
15
var View = require ( 'ampersand-view' ) ;
16
16
var localLinks = require ( 'local-links' ) ;
17
+ var debug = require ( 'debug' ) ( 'scout:app' ) ;
18
+
19
+ // Inter-process communication with main process (Electron window)
20
+ var ipc = window . require ( 'ipc' ) ;
17
21
18
22
/**
19
23
* The top-level application singleton that brings everything together!
@@ -130,6 +134,13 @@ var Application = View.extend({
130
134
event . preventDefault ( ) ;
131
135
this . router . history . navigate ( pathname ) ;
132
136
}
137
+ } ,
138
+ sendMessage : function ( msg ) {
139
+ ipc . send ( 'message' , msg ) ;
140
+ } ,
141
+ onMessageReceived : function ( msg ) {
142
+ debug ( 'message received from main process:' , msg ) ;
143
+ this . trigger ( msg ) ;
133
144
}
134
145
} ) ;
135
146
@@ -161,6 +172,9 @@ app.extend({
161
172
} ;
162
173
163
174
state . router = new Router ( ) ;
175
+
176
+ // set up ipc
177
+ ipc . on ( 'message' , state . onMessageReceived . bind ( this ) ) ;
164
178
} ,
165
179
navigate : state . navigate . bind ( state )
166
180
} ) ;
@@ -180,13 +194,11 @@ Object.defineProperty(app, 'client', {
180
194
} ) ;
181
195
app . init ( ) ;
182
196
183
- // expose app globally for debugging purposes
184
- window . app = app ;
185
-
186
197
function render_app ( ) {
187
198
state . _onDOMReady ( ) ;
188
199
}
189
200
190
201
domReady ( render_app ) ;
191
202
203
+ // expose app globally for debugging purposes
192
204
window . app = app ;
0 commit comments