@@ -6,7 +6,8 @@ function Api (app, requireName) {
6
6
}
7
7
8
8
Api . prototype . initialize = function ( ) {
9
- return this . load ( ) . then ( this . addApiCommands . bind ( this ) )
9
+ var self = this
10
+ return self . load ( ) . then ( self . addApiCommands . bind ( self ) )
10
11
}
11
12
12
13
Api . prototype . addApiCommands = function ( api ) {
@@ -30,6 +31,7 @@ Api.prototype.addApiCommands = function (api) {
30
31
31
32
Api . prototype . load = function ( ) {
32
33
var self = this
34
+
33
35
return this . isNodeIntegrationEnabled ( ) . then ( function ( nodeIntegration ) {
34
36
self . nodeIntegration = nodeIntegration
35
37
if ( ! nodeIntegration ) {
@@ -54,9 +56,10 @@ Api.prototype.load = function () {
54
56
}
55
57
56
58
Api . prototype . isNodeIntegrationEnabled = function ( ) {
57
- return this . app . client . execute ( function ( requireName ) {
59
+ var self = this
60
+ return self . app . client . execute ( function ( requireName ) {
58
61
return typeof window [ requireName ] === 'function'
59
- } , this . requireName ) . then ( getResponseValue )
62
+ } , self . requireName )
60
63
}
61
64
62
65
Api . prototype . getVersion = function ( ) {
@@ -65,7 +68,7 @@ Api.prototype.getVersion = function () {
65
68
if ( process != null && process . versions != null ) {
66
69
return process . versions . electron
67
70
}
68
- } , this . requireName ) . then ( getResponseValue )
71
+ } , this . requireName )
69
72
}
70
73
71
74
Api . prototype . loadApi = function ( ) {
@@ -183,7 +186,7 @@ Api.prototype.loadApi = function () {
183
186
addProcess ( )
184
187
185
188
return api
186
- } , this . requireName ) . then ( getResponseValue )
189
+ } , this . requireName )
187
190
}
188
191
189
192
Api . prototype . addClientProperty = function ( name ) {
@@ -229,7 +232,7 @@ Api.prototype.addRenderProcessApis = function (api) {
229
232
230
233
app . client . addCommand ( commandName , function ( ) {
231
234
var args = Array . prototype . slice . call ( arguments )
232
- return this . execute ( callRenderApi , moduleName , key , args , self . requireName ) . then ( getResponseValue )
235
+ return this . execute ( callRenderApi , moduleName , key , args , self . requireName )
233
236
} )
234
237
235
238
electron [ moduleName ] [ key ] = function ( ) {
@@ -252,7 +255,7 @@ Api.prototype.addMainProcessApis = function (api) {
252
255
253
256
app . client . addCommand ( commandName , function ( ) {
254
257
var args = Array . prototype . slice . call ( arguments )
255
- return this . execute ( callMainApi , null , name , args , self . requireName ) . then ( getResponseValue )
258
+ return this . execute ( callMainApi , '' , name , args , self . requireName )
256
259
} )
257
260
258
261
remote [ name ] = function ( ) {
@@ -271,7 +274,7 @@ Api.prototype.addMainProcessApis = function (api) {
271
274
272
275
app . client . addCommand ( commandName , function ( ) {
273
276
var args = Array . prototype . slice . call ( arguments )
274
- return this . execute ( callMainApi , moduleName , key , args , self . requireName ) . then ( getResponseValue )
277
+ return this . execute ( callMainApi , moduleName , key , args , self . requireName )
275
278
} )
276
279
277
280
remote [ moduleName ] [ key ] = function ( ) {
@@ -297,7 +300,7 @@ Api.prototype.addBrowserWindowApis = function (api) {
297
300
298
301
app . client . addCommand ( commandName , function ( ) {
299
302
var args = Array . prototype . slice . call ( arguments )
300
- return this . execute ( callBrowserWindowApi , name , args , self . requireName ) . then ( getResponseValue )
303
+ return this . execute ( callBrowserWindowApi , name , args , self . requireName )
301
304
} )
302
305
303
306
app . browserWindow [ name ] = function ( ) {
@@ -323,7 +326,7 @@ Api.prototype.addCapturePageSupport = function () {
323
326
} else {
324
327
done ( image )
325
328
}
326
- } , rect , self . requireName ) . then ( getResponseValue ) . then ( function ( image ) {
329
+ } , rect , self . requireName ) . then ( function ( image ) {
327
330
return Buffer . from ( image , 'base64' )
328
331
} )
329
332
} )
@@ -350,7 +353,7 @@ Api.prototype.addWebContentsApis = function (api) {
350
353
351
354
app . client . addCommand ( commandName , function ( ) {
352
355
var args = Array . prototype . slice . call ( arguments )
353
- return this . execute ( callWebContentsApi , name , args , self . requireName ) . then ( getResponseValue )
356
+ return this . execute ( callWebContentsApi , name , args , self . requireName )
354
357
} )
355
358
356
359
app . webContents [ name ] = function ( ) {
@@ -371,7 +374,7 @@ Api.prototype.addSavePageSupport = function () {
371
374
var webContents = window [ requireName ] ( 'electron' ) . remote . getCurrentWebContents ( )
372
375
await webContents . savePage ( fullPath , saveType )
373
376
done ( )
374
- } , fullPath , saveType , self . requireName ) . then ( getResponseValue ) . then ( function ( rawError ) {
377
+ } , fullPath , saveType , self . requireName ) . then ( function ( rawError ) {
375
378
if ( rawError ) {
376
379
var error = new Error ( rawError . message )
377
380
if ( rawError . name ) error . name = rawError . name
@@ -394,7 +397,7 @@ Api.prototype.addExecuteJavaScriptSupport = function () {
394
397
const webContents = window [ requireName ] ( 'electron' ) . remote . getCurrentWebContents ( )
395
398
const result = await webContents . executeJavaScript ( code , useGesture )
396
399
done ( result )
397
- } , code , useGesture , self . requireName ) . then ( getResponseValue )
400
+ } , code , useGesture , self . requireName )
398
401
} )
399
402
400
403
app . webContents . executeJavaScript = function ( ) {
@@ -411,7 +414,7 @@ Api.prototype.addProcessApis = function (api) {
411
414
412
415
app . client . addCommand ( commandName , function ( ) {
413
416
var args = Array . prototype . slice . call ( arguments )
414
- return this . execute ( callProcessApi , name , args ) . then ( getResponseValue )
417
+ return this . execute ( callProcessApi , name , args )
415
418
} )
416
419
417
420
app . rendererProcess [ name ] = function ( ) {
@@ -423,8 +426,6 @@ Api.prototype.addProcessApis = function (api) {
423
426
}
424
427
425
428
Api . prototype . transferPromiseness = function ( target , promise ) {
426
- this . app . client . transferPromiseness ( target , promise )
427
-
428
429
if ( ! this . nodeIntegration ) return
429
430
430
431
var addProperties = function ( source , target , moduleName ) {
@@ -501,8 +502,4 @@ function callProcessApi (name, args) {
501
502
}
502
503
}
503
504
504
- function getResponseValue ( response ) {
505
- return response . value
506
- }
507
-
508
505
module . exports = Api
0 commit comments