Skip to content

Commit

Permalink
v1.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
p-sam committed Sep 12, 2021
2 parents 8ccd4d4 + 2bd19da commit 8e2f9d3
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 27 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ insert_final_newline = true
indent_style = space
indent_size = 2

[*.yml]
indent_style = space
indent_size = 2

[*.md]
indent_style = space
indent_size = 4
14 changes: 14 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: CI

on: [push, pull_request, workflow_dispatch]

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with: {node-version: 16.x}
- run: npm install
- run: npm test
2 changes: 0 additions & 2 deletions .travis.yml

This file was deleted.

59 changes: 42 additions & 17 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,42 @@
const electron = require('electron');

const BrowserWindow = electron.BrowserWindow || electron.remote.BrowserWindow;
const ipcMain = electron.ipcMain || electron.remote.ipcMain;
const url = require('url');
const path = require('path');
const electron = require('electron');

const DEFAULT_WIDTH = 370;
const DEFAULT_HEIGHT = 160;

function getElectronMainExport(id) {
if (electron[id]) {
return electron[id];
}

let remote = electron.remote;
if (!remote) {
try {
remote = require('@electron/remote');
} catch (originalError) {
const error = new Error(
'Install and set-up package `@electron/remote` to use this module from a renderer processs.\n'
+ 'It is preferable to set up message exchanges for this using `ipcMain.handle()` and `ipcRenderer.invoke()`,\n'
+ 'avoiding remote IPC overhead costs, and one morepackage dependancy.\n\n'
+ 'Original error message:\n\n'
+ originalError.message,
);

error.originalError = originalError;
throw error;
}
}

if (remote && remote[id]) {
return remote[id];
}

throw new Error('Unknown electron export: ' + String(id));
}

const BrowserWindow = getElectronMainExport('BrowserWindow');
const ipcMain = getElectronMainExport('ipcMain');

function electronPrompt(options, parentWindow) {
return new Promise((resolve, reject) => {
const id = `${Date.now()}-${Math.random()}`;
Expand All @@ -30,9 +59,9 @@ function electronPrompt(options, parentWindow) {
useHtmlLabel: false,
customStylesheet: null,
menuBarVisible: false,
skipTaskbar: true
skipTaskbar: true,
},
options || {}
options || {},
);

if (options_.type === 'select' && (options_.selectOptions === null || typeof options_.selectOptions !== 'object')) {
Expand All @@ -58,8 +87,8 @@ function electronPrompt(options, parentWindow) {
icon: options_.icon || undefined,
webPreferences: {
nodeIntegration: true,
contextIsolation: false
}
contextIsolation: false,
},
});

promptWindow.setMenu(null);
Expand Down Expand Up @@ -108,14 +137,10 @@ function electronPrompt(options, parentWindow) {
resolve(null);
});

const promptUrl = url.format({
protocol: 'file',
slashes: true,
pathname: path.join(__dirname, 'page', 'prompt.html'),
hash: id
});

promptWindow.loadURL(promptUrl);
promptWindow.loadFile(
path.join(__dirname, 'page', 'prompt.html'),
{hash: id},
);
});
}

Expand Down
3 changes: 1 addition & 2 deletions lib/page/prompt.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const fs = require('fs');
const {ipcRenderer} = require('electron');
const docReady = require('doc-ready');

let promptId = null;
let promptOptions = null;
Expand Down Expand Up @@ -158,4 +157,4 @@ window.addEventListener('error', error => {
}
});

docReady(promptRegister);
document.addEventListener('DOMContentLoaded', promptRegister);
10 changes: 4 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "electron-prompt",
"version": "1.6.2",
"version": "1.7.0",
"description": "Electron helper to prompt for a value via input or select",
"keywords": [
"electron",
Expand Down Expand Up @@ -30,13 +30,11 @@
"browser"
],
"rules": {
"unicorn/prefer-ternary": 0
"unicorn/prefer-ternary": 0,
"unicorn/prefer-module": 0
}
},
"dependencies": {
"doc-ready": "^1.0.4"
},
"devDependencies": {
"xo": "^0.38.2"
"xo": "^0.44.0"
}
}

0 comments on commit 8e2f9d3

Please sign in to comment.