@@ -26,12 +26,13 @@ import {
2626 addInstancesToCanvas ,
2727 openConfirmationDialog ,
2828 registerModelPath ,
29+ loadModel ,
2930 LOAD_MODEL
3031} from '../actions/general' ;
3132import { OPEN_BACKEND_ERROR_DIALOG , CLOSE_BACKEND_ERROR_DIALOG , openBackendErrorDialog } from '../actions/errors' ;
3233import { closeDrawerDialogBox } from '../actions/drawer' ;
3334import Utils from '../../Utils' ;
34- import { downloadJsonResponse , downloadPythonResponse } from './utils' ;
35+ import { downloadJsonResponse , downloadPythonResponse , initParentFrameMessaging } from './utils' ;
3536import * as Constants from '../../constants' ;
3637import { ADD_EXPERIMENT , REMOVE_EXPERIMENT } from '../actions/experiments' ;
3738
@@ -249,6 +250,36 @@ export default (store) => (next) => (action) => {
249250
250251 }
251252
253+
254+ /**
255+ * Notify parent frame that the app is ready
256+ * Used in Open Source Brain integration
257+ */
258+ function initParentFrameMessaging ( ) {
259+ if ( window !== window . parent ) {
260+ window . parent . postMessage ( {
261+ type : 'APP_READY' ,
262+ } , '*' ) ;
263+
264+
265+ // Listen messages from the parent frame (Open Source Brain integration)
266+ const loadFromEvent = ( event ) => {
267+ // Here we would expect some cross-origin check, but we don't do anything more than load a model here
268+ switch ( event . data . type ) {
269+ case 'LOAD_RESOURCE' :
270+ // eslint-disable-next-line no-case-declarations
271+ const resource = event . data . payload ;
272+ store . dispatch ( loadModel ( resource ) ) ;
273+ break ;
274+ default :
275+ break ;
276+ }
277+ } ;
278+ // A message from the parent frame can specify the file to load
279+ window . addEventListener ( 'message' , loadFromEvent ) ;
280+ }
281+ }
282+
252283 switch ( action . type ) {
253284 case GeppettoActions . layoutActions . SET_WIDGETS : {
254285 if ( Object . values ( action . data ) . length == 1 ) {
@@ -291,6 +322,9 @@ export default (store) => (next) => (action) => {
291322 getExperiments ( )
292323 } ) ;
293324 Utils . execPythonMessage ( `netpyne_geppetto.saveToIndexFile(None, "${ Constants . KERNEL_HANDLING . tmpModelPath } ", True, True)` , ( ) => { } , false ) ;
325+
326+
327+ initParentFrameMessaging ( ) ;
294328
295329 setTimeout ( ( ) => {
296330 if ( ! responded ) {
@@ -299,6 +333,8 @@ export default (store) => (next) => (action) => {
299333 . then ( ( ) => window . location . reload ( ) ) ;
300334 }
301335 } , TIMEOUT ) ;
336+
337+
302338 break ;
303339 }
304340 case OPEN_BACKEND_ERROR_DIALOG :
@@ -529,3 +565,4 @@ export default (store) => (next) => (action) => {
529565 }
530566 }
531567} ;
568+
0 commit comments