Skip to content

Commit 8e2f9d3

Browse files
committed
v1.7.0
2 parents 8ccd4d4 + 2bd19da commit 8e2f9d3

File tree

6 files changed

+65
-27
lines changed

6 files changed

+65
-27
lines changed

.editorconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ insert_final_newline = true
1111
indent_style = space
1212
indent_size = 2
1313

14+
[*.yml]
15+
indent_style = space
16+
indent_size = 2
17+
1418
[*.md]
1519
indent_style = space
1620
indent_size = 4

.github/workflows/ci.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: CI
2+
3+
on: [push, pull_request, workflow_dispatch]
4+
5+
jobs:
6+
test:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- uses: actions/checkout@v2
11+
- uses: actions/setup-node@v2
12+
with: {node-version: 16.x}
13+
- run: npm install
14+
- run: npm test

.travis.yml

Lines changed: 0 additions & 2 deletions
This file was deleted.

lib/index.js

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,42 @@
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');
61
const path = require('path');
2+
const electron = require('electron');
73

84
const DEFAULT_WIDTH = 370;
95
const 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+
1140
function 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

lib/page/prompt.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const fs = require('fs');
22
const {ipcRenderer} = require('electron');
3-
const docReady = require('doc-ready');
43

54
let promptId = null;
65
let promptOptions = null;
@@ -158,4 +157,4 @@ window.addEventListener('error', error => {
158157
}
159158
});
160159

161-
docReady(promptRegister);
160+
document.addEventListener('DOMContentLoaded', promptRegister);

package.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "electron-prompt",
3-
"version": "1.6.2",
3+
"version": "1.7.0",
44
"description": "Electron helper to prompt for a value via input or select",
55
"keywords": [
66
"electron",
@@ -30,13 +30,11 @@
3030
"browser"
3131
],
3232
"rules": {
33-
"unicorn/prefer-ternary": 0
33+
"unicorn/prefer-ternary": 0,
34+
"unicorn/prefer-module": 0
3435
}
3536
},
36-
"dependencies": {
37-
"doc-ready": "^1.0.4"
38-
},
3937
"devDependencies": {
40-
"xo": "^0.38.2"
38+
"xo": "^0.44.0"
4139
}
4240
}

0 commit comments

Comments
 (0)