electron-findbar 0.5.0 → 0.6.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +51 -48
- package/index.js +23 -6
- package/package.json +7 -2
- package/remote.js +22 -0
- package/test/sample.html +1 -8
- package/test/sample.js +0 -1
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -8,18 +8,10 @@
|
|
|
8
8
|
Chrome-like findbar for your Electron application
|
|
9
9
|
</p>
|
|
10
10
|
<p align='center'>
|
|
11
|
-
<a href="https://github.com/ECRomaneli/electron-findbar/tags" style=
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
<a href="https://github.com/ECRomaneli/electron-findbar/
|
|
15
|
-
<img src="https://img.shields.io/github/last-commit/ecromaneli/electron-findbar?style=for-the-badge" alt="Last Commit">
|
|
16
|
-
</a>
|
|
17
|
-
<a href="https://github.com/ECRomaneli/electron-findbar/blob/master/LICENSE" style='text-decoration:none'>
|
|
18
|
-
<img src="https://img.shields.io/github/license/ecromaneli/electron-findbar?style=for-the-badge" alt="License">
|
|
19
|
-
</a>
|
|
20
|
-
<a href="https://github.com/ECRomaneli/electron-findbar/issues" style='text-decoration:none'>
|
|
21
|
-
<img src="https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=for-the-badge" alt="Contributions Welcome">
|
|
22
|
-
</a>
|
|
11
|
+
<a href="https://github.com/ECRomaneli/electron-findbar/tags"><img src="https://img.shields.io/github/v/tag/ecromaneli/electron-findbar?label=version&sort=semver&style=for-the-badge" alt="Version"></a>
|
|
12
|
+
<a href="https://github.com/ECRomaneli/electron-findbar/commits/master"><img src="https://img.shields.io/github/last-commit/ecromaneli/electron-findbar?style=for-the-badge" alt="Last Commit"></a>
|
|
13
|
+
<a href="https://github.com/ECRomaneli/electron-findbar/blob/master/LICENSE"><img src="https://img.shields.io/github/license/ecromaneli/electron-findbar?style=for-the-badge" alt="License"></a>
|
|
14
|
+
<a href="https://github.com/ECRomaneli/electron-findbar/issues"><img src="https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=for-the-badge" alt="Contributions Welcome"></a>
|
|
23
15
|
</p>
|
|
24
16
|
|
|
25
17
|
## Installation
|
|
@@ -47,21 +39,21 @@ All public methods are documented with JSDoc and can be referenced during import
|
|
|
47
39
|
To import the Findbar class:
|
|
48
40
|
|
|
49
41
|
```js
|
|
50
|
-
const { Findbar } = require('electron-findbar')
|
|
42
|
+
const { Findbar } = require('electron-findbar')
|
|
51
43
|
```
|
|
52
44
|
|
|
53
45
|
### Creating the Findbar Instance
|
|
54
46
|
|
|
55
|
-
You can pass a `BrowserWindow` instance as a single parameter to use it as the parent window. The `BrowserWindow.WebContents` will be used as the
|
|
47
|
+
You can pass a `BrowserWindow` instance as a single parameter to use it as the parent window. The `BrowserWindow.WebContents` will be used as the findable content:
|
|
56
48
|
|
|
57
49
|
```js
|
|
58
|
-
const findbar = new Findbar(browserWindow)
|
|
50
|
+
const findbar = new Findbar(browserWindow)
|
|
59
51
|
```
|
|
60
52
|
|
|
61
|
-
Alternatively, you can provide a custom `WebContents` as the second parameter. In this case, the first parameter can be any `BaseWindow`, and the second parameter will be the
|
|
53
|
+
Alternatively, you can provide a custom `WebContents` as the second parameter. In this case, the first parameter can be any `BaseWindow`, and the second parameter will be the findable content:
|
|
62
54
|
|
|
63
55
|
```js
|
|
64
|
-
const findbar = new Findbar(baseWindow, customWebContents)
|
|
56
|
+
const findbar = new Findbar(baseWindow, customWebContents)
|
|
65
57
|
```
|
|
66
58
|
|
|
67
59
|
### Configuring the Findbar
|
|
@@ -69,16 +61,24 @@ const findbar = new Findbar(baseWindow, customWebContents);
|
|
|
69
61
|
You can customize the Findbar window options using the `setWindowOptions` method:
|
|
70
62
|
|
|
71
63
|
```js
|
|
72
|
-
findbar.setWindowOptions({ movable: true, resizable: true, alwaysOnTop: true })
|
|
64
|
+
findbar.setWindowOptions({ movable: true, resizable: true, alwaysOnTop: true })
|
|
73
65
|
```
|
|
74
66
|
|
|
75
|
-
|
|
67
|
+
To handle the Findbar window directly after it is opened, use the `setWindowHandler` method:
|
|
68
|
+
|
|
69
|
+
```js
|
|
70
|
+
findbar.setWindowHandler(win => {
|
|
71
|
+
win.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true })
|
|
72
|
+
});
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
The findbar has a default position handler which moves the findbar to the top-right corner. To change the position handler, use the `setPositionHandler` method. The position handler is called when the parent window moves or resizes and provides both the parent and findbar bounds as parameters.
|
|
76
76
|
|
|
77
77
|
```js
|
|
78
78
|
findbar.setPositionHandler((parentBounds, findbarBounds) => ({
|
|
79
79
|
x: parentBounds.x + parentBounds.width - findbarBounds.width - 20,
|
|
80
80
|
y: parentBounds.y - ((findbarBounds.height / 4) | 0)
|
|
81
|
-
}))
|
|
81
|
+
}))
|
|
82
82
|
```
|
|
83
83
|
|
|
84
84
|
### Opening the Findbar
|
|
@@ -86,17 +86,9 @@ findbar.setPositionHandler((parentBounds, findbarBounds) => ({
|
|
|
86
86
|
The Findbar is a child window of the `BaseWindow` passed during construction. To open it use:
|
|
87
87
|
|
|
88
88
|
```js
|
|
89
|
-
findbar.open()
|
|
89
|
+
findbar.open()
|
|
90
90
|
```
|
|
91
91
|
|
|
92
|
-
On MacOS, the findbar will follow the relative movement of the parent window by default and there is no way to change it. On Windows and Linux, this behavior is not default and is simulated by using the `move` event of the parent and can be disabled by using:
|
|
93
|
-
|
|
94
|
-
```js
|
|
95
|
-
findbar.followParentWindow(false)
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
> Enabled by default.
|
|
99
|
-
|
|
100
92
|
### Finding Text in the Page
|
|
101
93
|
|
|
102
94
|
Once open, the Findbar appears by default in the top-right corner of the parent window and can be used without additional coding. Alternatively, you can use the following methods to trigger `findInPage` and navigate through matches in the main process:
|
|
@@ -105,28 +97,28 @@ Once open, the Findbar appears by default in the top-right corner of the parent
|
|
|
105
97
|
/**
|
|
106
98
|
* Retrieve the last queried value.
|
|
107
99
|
*/
|
|
108
|
-
getLastValue()
|
|
100
|
+
getLastValue()
|
|
109
101
|
|
|
110
102
|
/**
|
|
111
103
|
* Initiate a request to find all matches for the specified text on the page.
|
|
112
104
|
* @param {string} text - The text to search for.
|
|
113
105
|
*/
|
|
114
|
-
startFind(text)
|
|
106
|
+
startFind(text)
|
|
115
107
|
|
|
116
108
|
/**
|
|
117
109
|
* Select the previous match, if available.
|
|
118
110
|
*/
|
|
119
|
-
findPrevious()
|
|
111
|
+
findPrevious()
|
|
120
112
|
|
|
121
113
|
/**
|
|
122
114
|
* Select the next match, if available.
|
|
123
115
|
*/
|
|
124
|
-
findNext()
|
|
116
|
+
findNext()
|
|
125
117
|
|
|
126
118
|
/**
|
|
127
119
|
* Stop the find request.
|
|
128
120
|
*/
|
|
129
|
-
stopFind()
|
|
121
|
+
stopFind()
|
|
130
122
|
```
|
|
131
123
|
|
|
132
124
|
### Closing the Findbar
|
|
@@ -134,7 +126,7 @@ stopFind();
|
|
|
134
126
|
When the Findbar is closed, its window is destroyed to free memory resources. Use the following method to close the Findbar:
|
|
135
127
|
|
|
136
128
|
```js
|
|
137
|
-
findbar.close()
|
|
129
|
+
findbar.close()
|
|
138
130
|
```
|
|
139
131
|
|
|
140
132
|
A new internal window will be created the next time the `open` method is called. There is no need to instantiate another Findbar for the same parent window.
|
|
@@ -144,32 +136,36 @@ A new internal window will be created the next time the `open` method is called.
|
|
|
144
136
|
Here is a quick example demonstrating how to use the `electron-findbar`:
|
|
145
137
|
|
|
146
138
|
```js
|
|
147
|
-
const { app, BrowserWindow } = require('electron')
|
|
148
|
-
const { Findbar } = require('electron-findbar')
|
|
139
|
+
const { app, BrowserWindow } = require('electron')
|
|
140
|
+
const { Findbar } = require('electron-findbar')
|
|
149
141
|
|
|
150
142
|
app.whenReady().then(() => {
|
|
151
|
-
const window = new BrowserWindow()
|
|
152
|
-
window.loadURL('https://github.com/ECRomaneli/electron-findbar')
|
|
143
|
+
const window = new BrowserWindow()
|
|
144
|
+
window.loadURL('https://github.com/ECRomaneli/electron-findbar')
|
|
153
145
|
|
|
154
146
|
// Create and configure the Findbar object
|
|
155
|
-
const findbar = new Findbar(window)
|
|
147
|
+
const findbar = new Findbar(window)
|
|
156
148
|
|
|
157
149
|
// [OPTIONAL] Customize window options
|
|
158
|
-
findbar.setWindowOptions({ movable: true, resizable: true })
|
|
150
|
+
findbar.setWindowOptions({ movable: true, resizable: true })
|
|
159
151
|
|
|
160
152
|
// [OPTIONAL] Handle the window object when the Findbar is opened
|
|
161
153
|
findbar.setWindowHandler(win => {
|
|
162
|
-
win.webContents.openDevTools()
|
|
163
|
-
})
|
|
154
|
+
win.webContents.openDevTools()
|
|
155
|
+
})
|
|
164
156
|
|
|
165
157
|
// Open the Findbar
|
|
166
|
-
findbar.open()
|
|
167
|
-
})
|
|
158
|
+
findbar.open()
|
|
159
|
+
})
|
|
168
160
|
```
|
|
169
161
|
|
|
170
162
|
## IPC Events
|
|
171
163
|
|
|
172
|
-
As an alternative, the findbar can be controlled using IPC events in the `renderer` process of the `WebContents` provided during the findbar construction.
|
|
164
|
+
As an alternative, the findbar can be controlled using IPC events in the `renderer` process of the `WebContents` provided during the findbar construction.
|
|
165
|
+
|
|
166
|
+
### ipcRenderer
|
|
167
|
+
|
|
168
|
+
If the `contextIsolation` is enabled, the `electron-findbar/remote` will not be available, but the IPC events can be used directly through the preload script:
|
|
173
169
|
|
|
174
170
|
```js
|
|
175
171
|
const $remote = (ipc => ({
|
|
@@ -185,9 +181,16 @@ $remote.open()
|
|
|
185
181
|
$remote.inputChange('findIt')
|
|
186
182
|
```
|
|
187
183
|
|
|
188
|
-
|
|
184
|
+
### Remote module
|
|
185
|
+
|
|
186
|
+
With the `contextIsolation` disabled, the remote library is available to use:
|
|
189
187
|
|
|
190
|
-
|
|
188
|
+
```js
|
|
189
|
+
const FindbarRemote = require('electron-findbar/remote')
|
|
190
|
+
|
|
191
|
+
FindbarRemote.open()
|
|
192
|
+
FindbarRemote.inputChange('findIt')
|
|
193
|
+
```
|
|
191
194
|
|
|
192
195
|
## Author
|
|
193
196
|
|
package/index.js
CHANGED
|
@@ -40,6 +40,7 @@ class Findbar {
|
|
|
40
40
|
constructor (parent, webContents) {
|
|
41
41
|
this.#parent = parent
|
|
42
42
|
this.#findableContents = webContents ?? parent.webContents
|
|
43
|
+
this.#findableContents._findbar = this
|
|
43
44
|
|
|
44
45
|
if (!this.#findableContents) {
|
|
45
46
|
throw new Error('There are no searchable web contents.')
|
|
@@ -56,7 +57,6 @@ class Findbar {
|
|
|
56
57
|
}
|
|
57
58
|
this.#window = new BrowserWindow(Findbar.#mergeStandardOptions(this.#customOptions, this.#parent))
|
|
58
59
|
this.#window.webContents._findbar = this
|
|
59
|
-
this.#findableContents._findbar = this
|
|
60
60
|
|
|
61
61
|
this.#registerListeners()
|
|
62
62
|
|
|
@@ -90,7 +90,7 @@ class Findbar {
|
|
|
90
90
|
startFind(text, skipInputUpdate) {
|
|
91
91
|
skipInputUpdate || this.#window?.webContents.send('electron-findbar/text-change', text)
|
|
92
92
|
if (this.#lastText = text) {
|
|
93
|
-
this.#findableContents.findInPage(this.#lastText, { findNext: true })
|
|
93
|
+
this.isOpen() && this.#findableContents.findInPage(this.#lastText, { findNext: true })
|
|
94
94
|
} else {
|
|
95
95
|
this.stopFind()
|
|
96
96
|
}
|
|
@@ -101,7 +101,7 @@ class Findbar {
|
|
|
101
101
|
*/
|
|
102
102
|
findPrevious() {
|
|
103
103
|
this.#matches.active === 1 && (this.#fixMove = false)
|
|
104
|
-
this.#findableContents.findInPage(this.#lastText, { forward: false })
|
|
104
|
+
this.isOpen() && this.#findableContents.findInPage(this.#lastText, { forward: false })
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
/**
|
|
@@ -109,7 +109,7 @@ class Findbar {
|
|
|
109
109
|
*/
|
|
110
110
|
findNext() {
|
|
111
111
|
this.#matches.active === this.#matches.total && (this.#fixMove = true)
|
|
112
|
-
this.#findableContents.findInPage(this.#lastText, { forward: true })
|
|
112
|
+
this.isOpen() && this.#findableContents.findInPage(this.#lastText, { forward: true })
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
/**
|
|
@@ -121,13 +121,29 @@ class Findbar {
|
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
/**
|
|
124
|
-
*
|
|
124
|
+
* Whether the findbar is opened.
|
|
125
125
|
* @returns {boolean} True, if the findbar is open. Otherwise, false.
|
|
126
126
|
*/
|
|
127
127
|
isOpen() {
|
|
128
128
|
return !!this.#window
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
+
/**
|
|
132
|
+
* Whether the findbar is focused. If the findbar is closed, false will be returned.
|
|
133
|
+
* @returns {boolean} True, if the findbar is focused. Otherwise, false.
|
|
134
|
+
*/
|
|
135
|
+
isFocused() {
|
|
136
|
+
return !!this.#window?.isFocused()
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Whether the findbar is visible to the user in the foreground of the app. If the findbar is closed, false will be returned.
|
|
141
|
+
* @returns {boolean} True, if the findbar is visible. Otherwise, false.
|
|
142
|
+
*/
|
|
143
|
+
isVisible() {
|
|
144
|
+
return !!this.#window?.isVisible()
|
|
145
|
+
}
|
|
146
|
+
|
|
131
147
|
/**
|
|
132
148
|
* Provides a customized set of options to findbar window before open. Note
|
|
133
149
|
* that the options below are necessary for the correct functioning and cannot
|
|
@@ -244,7 +260,8 @@ class Findbar {
|
|
|
244
260
|
options.acceptFirstMouse = options.acceptFirstMouse ?? true
|
|
245
261
|
options.parent = parent
|
|
246
262
|
options.frame = false
|
|
247
|
-
options.
|
|
263
|
+
options.roundedCorners = true
|
|
264
|
+
options.transparent = process.platform === 'linux'
|
|
248
265
|
options.maximizable = false
|
|
249
266
|
options.minimizable = false
|
|
250
267
|
options.skipTaskbar = true
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "electron-findbar",
|
|
3
|
-
"version": "0.5
|
|
3
|
+
"version": "0.6.5",
|
|
4
4
|
"description": "Chrome-like findbar for your Electron app.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -13,10 +13,15 @@
|
|
|
13
13
|
},
|
|
14
14
|
"keywords": [
|
|
15
15
|
"findbar",
|
|
16
|
+
"find-bar",
|
|
17
|
+
"find bar",
|
|
16
18
|
"electron-findbar",
|
|
19
|
+
"electron-find-bar",
|
|
17
20
|
"electron",
|
|
18
21
|
"chrome-findbar",
|
|
19
|
-
"
|
|
22
|
+
"chrome-find-bar",
|
|
23
|
+
"search",
|
|
24
|
+
"search-bar"
|
|
20
25
|
],
|
|
21
26
|
"author": "ECRomaneli",
|
|
22
27
|
"license": "MIT",
|
package/remote.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Remote IPC events to control the findbar through the renderer.
|
|
3
|
+
*/
|
|
4
|
+
const Remote = (ipc => ({
|
|
5
|
+
/**
|
|
6
|
+
* Get last queried text.
|
|
7
|
+
* @returns {string}
|
|
8
|
+
*/
|
|
9
|
+
getLastText: async () => ipc.invoke('electron-findbar/last-text'),
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Change the input value and find it.
|
|
13
|
+
* @param {string} text
|
|
14
|
+
*/
|
|
15
|
+
inputChange: (text) => { ipc.send('electron-findbar/input-change', text) },
|
|
16
|
+
previous: () => { ipc.send('electron-findbar/previous') },
|
|
17
|
+
next: () => { ipc.send('electron-findbar/next') },
|
|
18
|
+
open: () => { ipc.send('electron-findbar/open') },
|
|
19
|
+
close: () => { ipc.send('electron-findbar/close') },
|
|
20
|
+
})) (require('electron').ipcRenderer)
|
|
21
|
+
|
|
22
|
+
module.exports = Remote
|
package/test/sample.html
CHANGED
|
@@ -22,14 +22,7 @@ Suspendisse vel euismod ante. Nunc sagittis quam ut gravida pulvinar. Sed at sem
|
|
|
22
22
|
Aliquam ut pellentesque tellus, quis vulputate nisl. Phasellus vitae blandit nunc, eu sodales velit. Duis enim tellus, faucibus id arcu vitae, consectetur tempus mauris. Praesent commodo commodo dolor non malesuada. Donec sed dolor eget arcu tincidunt efficitur sit amet vel nisi. Sed consectetur tincidunt molestie. Nam at magna a odio rhoncus convallis id eu nunc. Nam luctus ut leo et viverra. Proin tempor libero vitae arcu laoreet, sed pharetra sapien rutrum. Nam nunc orci, aliquet sit amet dignissim nec, aliquet quis quam. Nulla facilisi.
|
|
23
23
|
</span>
|
|
24
24
|
<script>
|
|
25
|
-
const $remote = (
|
|
26
|
-
getLastText: async () => ipc.invoke('electron-findbar/last-text'),
|
|
27
|
-
inputChange: (value) => { ipc.send('electron-findbar/input-change', value) },
|
|
28
|
-
previous: () => { ipc.send('electron-findbar/previous') },
|
|
29
|
-
next: () => { ipc.send('electron-findbar/next') },
|
|
30
|
-
open: () => { ipc.send('electron-findbar/open') },
|
|
31
|
-
close: () => { ipc.send('electron-findbar/close') },
|
|
32
|
-
})) (require('electron').ipcRenderer)
|
|
25
|
+
const $remote = require('../remote')
|
|
33
26
|
</script>
|
|
34
27
|
</body>
|
|
35
28
|
</html>
|
package/test/sample.js
CHANGED