├── .gitignore
├── LICENSE
├── README.md
├── example
├── index.js
└── modal.html
├── modal.js
└── package.json
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | sandbox.js
3 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2019 Mathias Buus
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # electron-modal-window
2 |
3 | Easily create and use electron modal windows
4 |
5 | ```
6 | npm install electron-modal-window
7 | ```
8 |
9 | ## Usage
10 |
11 | In your "main" renderer process where you want to spawn a modal from do
12 |
13 | ``` js
14 | const modal = require('electron-modal-window')
15 |
16 | const m = modal.createModal(`file://${__dirname}/modal.html`, {
17 | width: 300,
18 | height: 300 // and pass any other electron BrowserWindow opts you want
19 | })
20 |
21 | m.window // this is the modal BrowserWindow
22 |
23 | m.on('hello', function (cb) {
24 | // emitted when the modal sends 'hello'
25 | cb(null, 'world')
26 | })
27 | ```
28 |
29 | In the js for modal.html
30 |
31 | ``` js
32 | const modal = require('electron-modal-window')
33 |
34 | m.send('hello', function (err, val) {
35 | console.log('they said', val)
36 | })
37 |
38 | // m.window is the current window
39 | ```
40 |
41 | ## API
42 |
43 | #### `m = modal.createModal([url, browserWindowOptions])`
44 |
45 | Make a new module. Set `url` to the url the modal should load.
46 | All `browserWindowOptions` are forwarded to the BrowserWindow constructor.
47 |
48 | #### `m.window`
49 |
50 | The attached BrowserWindow instance.
51 |
52 | #### `m.on(name, args..., callback)`
53 |
54 | Emitted when the modal sends a message. You can reply back by calling the calling cb.
55 |
56 | #### `m.send(name, args..., [callback])`
57 |
58 | Send a message to the modal. The optional callback is called with the reply.
59 | If an error occured (i.e. the modal sent an error or the modal closed) it will
60 | be passed to the callback.
61 |
62 | #### `modal.on(name, args..., callback)`
63 |
64 | Same as `m.on` but use this in the modal window to listen for messages from the modal creator.
65 |
66 | #### `modal.send(name, args..., [callback])`
67 |
68 | Same as `m.send` but use this in the modal window to message the modal creator.
69 |
70 | #### `modal.window`
71 |
72 | The modals own window instance.
73 |
74 | ## License
75 |
76 | MIT
77 |
--------------------------------------------------------------------------------
/example/index.js:
--------------------------------------------------------------------------------
1 | const modal = require('../modal')
2 |
3 | let n = 0
4 |
5 | const m = modal.createModal(`file://${__dirname}/modal.html`, {
6 | height: 600,
7 | width: 300,
8 | webPreferences: {
9 | nodeIntegration: true
10 | },
11 | frame: true
12 | })
13 |
14 | // modal never answers
15 | m.send('void', function (err) {
16 | console.log('reply', err)
17 | })
18 |
19 | m.on('increment', function (cb) {
20 | console.log('incrementing')
21 | cb(null, ++n)
22 | })
23 |
24 | m.on('decrement', function (cb) {
25 | console.log('decrementing')
26 | cb(null, --n)
27 | })
28 |
29 | m.window.on('closed', function () {
30 | console.log('modal closed')
31 | })
32 |
--------------------------------------------------------------------------------
/example/modal.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |