@@ -11,6 +11,9 @@ export class ExecService extends Service {
11
11
svc_ipc . register_ipc_handler ( 'launchApp' , {
12
12
handler : this . launchApp . bind ( this ) ,
13
13
} ) ;
14
+ svc_ipc . register_ipc_handler ( 'connectToInstance' , {
15
+ handler : this . connectToInstance . bind ( this ) ,
16
+ } ) ;
14
17
}
15
18
16
19
// This method is exposed to apps via IPCService.
@@ -70,4 +73,34 @@ export class ExecService extends Service {
70
73
usesSDK : true ,
71
74
} ;
72
75
}
76
+
77
+ async connectToInstance ( { app_name, args } , { ipc_context, msg_id } = { } ) {
78
+ const caller_process = ipc_context ?. caller ?. process ;
79
+ if ( ! caller_process ) {
80
+ throw new Error ( 'Caller process not found' ) ;
81
+ }
82
+
83
+ console . log (
84
+ caller_process . name ,
85
+ app_name ,
86
+ ) ;
87
+ // TODO: permissions integration; for now it's hardcoded
88
+ if ( caller_process . name !== 'phoenix' ) {
89
+ throw new Error ( 'Connection not allowed.' ) ;
90
+ }
91
+ if ( app_name !== 'test-emu' ) {
92
+ throw new Error ( 'Connection not allowed.' ) ;
93
+ }
94
+
95
+ const svc_process = this . services . get ( 'process' ) ;
96
+ const options = svc_process . select_by_name ( app_name ) ;
97
+ const process = options [ 0 ] ;
98
+
99
+ await process . handle_connection ( caller_process , args ) ;
100
+
101
+ return {
102
+ appInstanceID : process . uuid ,
103
+ response,
104
+ } ;
105
+ }
73
106
}
0 commit comments