@@ -18,10 +18,10 @@ remote.getGlobal('appShared').QuitWatcher = () => {
18
18
19
19
20
20
21
- const emit = ( origin , path , data ) => LowLevelSocketService . emit ( origin , path , data ) ;
22
- const getNewKey = origin => LowLevelSocketService . getNewKey ( origin ) ;
21
+ const emit = ( origin , id , path , data ) => LowLevelSocketService . emit ( origin , id , path , data ) ;
22
+ const getNewKey = ( origin , id ) => LowLevelSocketService . getNewKey ( origin , id ) ;
23
23
24
- const handleApiResponse = async request => {
24
+ const handleApiResponse = async ( request , id ) => {
25
25
26
26
// 2 way authentication
27
27
const existingApp = StoreService . get ( ) . state . scatter . keychain . findApp ( request . data . payload . origin ) ;
@@ -45,11 +45,11 @@ const handleApiResponse = async request => {
45
45
else await updateNonce ( ) ;
46
46
47
47
ApiService . handler ( Object . assign ( request . data , { plugin :request . plugin } ) ) . then ( result => {
48
- emit ( existingApp . origin , 'api' , result ) ;
48
+ emit ( existingApp . origin , id , 'api' , result ) ;
49
49
} )
50
50
} ;
51
51
52
- const handlePairedResponse = async request => {
52
+ const handlePairedResponse = async ( request , id ) => {
53
53
const scatter = StoreService . get ( ) . state . scatter ;
54
54
const existingApp = scatter . keychain . findApp ( request . data . origin ) ;
55
55
const linkApp = {
@@ -58,27 +58,27 @@ const handlePairedResponse = async request => {
58
58
} ;
59
59
60
60
if ( request . data . passthrough )
61
- return emit ( request . data . origin , 'paired' , existingApp && existingApp . checkKey ( request . data . appkey ) ) ;
61
+ return emit ( request . data . origin , id , 'paired' , existingApp && existingApp . checkKey ( request . data . appkey ) ) ;
62
62
63
63
const addAuthorizedApp = async ( newKey = null ) => {
64
64
const authedApp = new AuthorizedApp ( request . data . origin , newKey ? newKey : request . data . appkey ) ;
65
65
const clone = scatter . clone ( ) ;
66
66
clone . keychain . updateOrPushApp ( authedApp ) ;
67
67
await StoreService . get ( ) . dispatch ( Actions . SET_SCATTER , clone ) ;
68
- emit ( request . data . origin , 'paired' , true ) ;
68
+ emit ( request . data . origin , id , 'paired' , true ) ;
69
69
} ;
70
70
71
71
const repair = async ( ) => {
72
- const newKey = await getNewKey ( request . data . origin ) ;
73
- if ( newKey . data . origin !== request . data . origin || newKey . data . appkey . indexOf ( 'appkey:' ) === - 1 ) return emit ( request . data . origin , 'paired' , false ) ;
72
+ const newKey = await getNewKey ( request . data . origin , id ) ;
73
+ if ( newKey . data . origin !== request . data . origin || newKey . data . appkey . indexOf ( 'appkey:' ) === - 1 ) return emit ( request . data . origin , id , 'paired' , false ) ;
74
74
return addAuthorizedApp ( newKey . data . appkey )
75
75
}
76
76
77
77
if ( existingApp ) {
78
- if ( existingApp . checkKey ( request . data . appkey ) ) return emit ( request . data . origin , 'paired' , true ) ;
78
+ if ( existingApp . checkKey ( request . data . appkey ) ) return emit ( request . data . origin , id , 'paired' , true ) ;
79
79
else PopupService . push ( Popup . popout ( linkApp , async ( { result} ) => {
80
80
if ( result ) return repair ( ) ;
81
- else emit ( request . data . origin , 'paired' , false ) ;
81
+ else emit ( request . data . origin , id , 'paired' , false ) ;
82
82
} ) ) ;
83
83
}
84
84
else return repair ( ) ;
@@ -111,8 +111,8 @@ export default class SocketService {
111
111
112
112
static async initialize ( ) {
113
113
const certs = await getCerts ( ) ;
114
- ipcRenderer . on ( 'api' , ( event , request ) => handleApiResponse ( request ) ) ;
115
- ipcRenderer . on ( 'pair' , ( event , request ) => handlePairedResponse ( request ) ) ;
114
+ ipcRenderer . on ( 'api' , ( event , { request, id } ) => handleApiResponse ( request , id ) ) ;
115
+ ipcRenderer . on ( 'pair' , ( event , { request, id } ) => handlePairedResponse ( request , id ) ) ;
116
116
ipcRenderer . on ( 'ports' , ( event , ports ) => StoreService . get ( ) . dispatch ( Actions . SET_PORTS , ports ) ) ;
117
117
return LowLevelSocketService . initialize ( certs ) ;
118
118
}
0 commit comments