1- const electron = require ( 'electron' ) ;
2-
3- const BrowserWindow = electron . BrowserWindow || electron . remote . BrowserWindow ;
4- const ipcMain = electron . ipcMain || electron . remote . ipcMain ;
5- const url = require ( 'url' ) ;
61const path = require ( 'path' ) ;
2+ const electron = require ( 'electron' ) ;
73
84const DEFAULT_WIDTH = 370 ;
95const DEFAULT_HEIGHT = 160 ;
106
7+ function getElectronMainExport ( id ) {
8+ if ( electron [ id ] ) {
9+ return electron [ id ] ;
10+ }
11+
12+ let remote = electron . remote ;
13+ if ( ! remote ) {
14+ try {
15+ remote = require ( '@electron/remote' ) ;
16+ } catch ( originalError ) {
17+ const error = new Error (
18+ 'Install and set-up package `@electron/remote` to use this module from a renderer processs.\n'
19+ + 'It is preferable to set up message exchanges for this using `ipcMain.handle()` and `ipcRenderer.invoke()`,\n'
20+ + 'avoiding remote IPC overhead costs, and one morepackage dependancy.\n\n'
21+ + 'Original error message:\n\n'
22+ + originalError . message ,
23+ ) ;
24+
25+ error . originalError = originalError ;
26+ throw error ;
27+ }
28+ }
29+
30+ if ( remote && remote [ id ] ) {
31+ return remote [ id ] ;
32+ }
33+
34+ throw new Error ( 'Unknown electron export: ' + String ( id ) ) ;
35+ }
36+
37+ const BrowserWindow = getElectronMainExport ( 'BrowserWindow' ) ;
38+ const ipcMain = getElectronMainExport ( 'ipcMain' ) ;
39+
1140function electronPrompt ( options , parentWindow ) {
1241 return new Promise ( ( resolve , reject ) => {
1342 const id = `${ Date . now ( ) } -${ Math . random ( ) } ` ;
@@ -30,9 +59,9 @@ function electronPrompt(options, parentWindow) {
3059 useHtmlLabel : false ,
3160 customStylesheet : null ,
3261 menuBarVisible : false ,
33- skipTaskbar : true
62+ skipTaskbar : true ,
3463 } ,
35- options || { }
64+ options || { } ,
3665 ) ;
3766
3867 if ( options_ . type === 'select' && ( options_ . selectOptions === null || typeof options_ . selectOptions !== 'object' ) ) {
@@ -58,8 +87,8 @@ function electronPrompt(options, parentWindow) {
5887 icon : options_ . icon || undefined ,
5988 webPreferences : {
6089 nodeIntegration : true ,
61- contextIsolation : false
62- }
90+ contextIsolation : false ,
91+ } ,
6392 } ) ;
6493
6594 promptWindow . setMenu ( null ) ;
@@ -108,14 +137,10 @@ function electronPrompt(options, parentWindow) {
108137 resolve ( null ) ;
109138 } ) ;
110139
111- const promptUrl = url . format ( {
112- protocol : 'file' ,
113- slashes : true ,
114- pathname : path . join ( __dirname , 'page' , 'prompt.html' ) ,
115- hash : id
116- } ) ;
117-
118- promptWindow . loadURL ( promptUrl ) ;
140+ promptWindow . loadFile (
141+ path . join ( __dirname , 'page' , 'prompt.html' ) ,
142+ { hash : id } ,
143+ ) ;
119144 } ) ;
120145}
121146
0 commit comments