Skip to content

Commit 32e5b9d

Browse files
authored
Release/v3.0.0 (#465)
* Updated CHANGELOG.md for v3.0.0 * Version bump to v3.0.0 * Updated readme * Updated changelog * Updated docstrings
1 parent bdaf314 commit 32e5b9d

File tree

6 files changed

+95
-33
lines changed

6 files changed

+95
-33
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## 3.0.0
6+
7+
- Enhancement: Improve types of Jest matchers [(#466)](https://github.com/nut-tree/nut.js/issues/466)
8+
- BREAKING: Rename clipboard methods [(#463)](https://github.com/nut-tree/nut.js/issues/463)
9+
- Enhancement: Option to disable automatic request of permissions in macOS [(#462)](https://github.com/nut-tree/nut.js/issues/462)
10+
- BREAKING: Allow `screen.find` and other to work with non-image needles [(#455)](https://github.com/nut-tree/nut.js/issues/455)
11+
- BREAKING: Add bits per pixel and byteWidth info to image class [(#451)](https://github.com/nut-tree/nut.js/issues/451)
12+
- Bugfix: Installed Electron App crashes after upgrading to 2.3.0 [(#449)](https://github.com/nut-tree/nut.js/issues/449)
13+
- Maintenance: Add .nvmrc config [(#447)](https://github.com/nut-tree/nut.js/issues/447)
14+
- Enhancement: Define and export interfaces for keyboard/mouse/screen configs [(#443)](https://github.com/nut-tree/nut.js/issues/445)
15+
- Bugfix: 'RightShift' key is mapped to space [(#442)](https://github.com/nut-tree/nut.js/issues/442)
16+
- Maintenance: Introduce prettier [(#437)](https://github.com/nut-tree/nut.js/issues/437)
17+
- Bugfix: Win2012-R2: Error: The specified procedure could not be found [(#434)](https://github.com/nut-tree/nut.js/issues/434)
18+
- Feature: Logging provider [(#371)](https://github.com/nut-tree/nut.js/issues/371)
19+
520
## 2.3.0
621

722
- Bugfix: Segmentation Fault when retrieving window title [(#377)](https://github.com/nut-tree/nut.js/issues/377)

README.md

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,6 @@ but additionally gives you the possibility to navigate the screen based on image
4040

4141
A huge **"Thank you!"** goes out to all sponsors who make open source a bit more sustainable!
4242

43-
[<img src="https://avatars.githubusercontent.com/u/17616211?v=4" width="75" alt="Reiss Cashmore" />](https://github.com/Reiss-Cashmore)
44-
[<img src="https://avatars.githubusercontent.com/u/1794527?v=4" width="75" alt="Chet Corcos" />](https://github.com/ccorcos)
45-
[<img src="https://avatars.githubusercontent.com/u/4453806?v=4" width="75" alt="Patrick Flor" />](https://github.com/senorflor)
46-
[<img src="https://avatars.githubusercontent.com/u/7562803?v=4" width="75" alt="Ian" />](https://github.com/iwiedenm)
47-
48-
<hr/>
49-
50-
[<img src="https://github.com/nut-tree/nut.js/raw/develop/.gfx/sponsors/mighty.svg" height="75" alt="Mighty browser logo"/>](https://www.mightyapp.com)
51-
5243
# Demo
5344

5445
Check out this demo video to get a first impression of what nut.js is capable of.
@@ -102,46 +93,72 @@ It's work in progress and will undergo constant modification.
10293

10394
## Screen
10495

105-
- [x] Find an image on screen (requires an additional provider package like e.g. [nut-tree/template-matcher](https://www.npmjs.com/package/@nut-tree/template-matcher))
106-
- [x] Find all image occurrences on screen
107-
- [x] Wait for an image to appear on screen (requires an additional provider package like e.g. [nut-tree/template-matcher](https://www.npmjs.com/package/@nut-tree/template-matcher))
10896
- [x] Retrieve RGBA color information on screen
109-
- [x] Hooks to trigger actions based on images (requires an additional provider package like e.g. [nut-tree/template-matcher](https://www.npmjs.com/package/@nut-tree/template-matcher))
11097
- [x] Highlighting screen regions
98+
- [x] Find a single or multiple occurrences of an image on screen (requires an additional provider package like e.g. [nut-tree/template-matcher](https://www.npmjs.com/package/@nut-tree/template-matcher))
99+
- [x] Wait for an image to appear on screen (requires an additional provider package like e.g. [nut-tree/template-matcher](https://www.npmjs.com/package/@nut-tree/template-matcher))
100+
- [x] Find a single or multiple occurrences of text on screen (\*)
101+
- [x] Wait for a piece of text to appear on screen (\*)
102+
- [x] Find a single or multiple windows on screen (\*)
103+
- [x] Wait for a window to appear on screen (\*)
104+
- [x] Hooks to trigger actions based on detected text, images or windows (\*)
105+
106+
(\*) Requires an additional provider package, visit [nutjs.dev](https://nutjs.dev) for more info
111107

112108
## Integration
113109

114110
- [x] Jest
115111
- [x] Electron
112+
- [x] Custom log integration
116113

117114
# Sample
118115

119-
The following snippet shows a valid `nut.js` example:
116+
The following snippet shows a valid `nut.js` example (using multiple addons):
120117

121118
```js
122119
"use strict";
123120

124121
const {
125122
mouse,
126-
left,
127-
right,
128-
up,
129-
down,
123+
screen,
124+
singleWord,
125+
sleep,
126+
useConsoleLogger,
127+
ConsoleLogLevel,
130128
straightTo,
131129
centerOf,
132-
Region,
130+
Button,
131+
getActiveWindow,
133132
} = require("@nut-tree/nut-js");
133+
const {
134+
preloadLanguages,
135+
Language,
136+
LanguageModelType,
137+
configure,
138+
} = require("@nut-tree/plugin-ocr");
139+
140+
configure({ languageModelType: LanguageModelType.BEST });
141+
142+
useConsoleLogger({ logLevel: ConsoleLogLevel.DEBUG });
143+
144+
screen.config.autoHighlight = true;
145+
screen.config.ocrConfidence = 0.8;
134146

135-
const square = async () => {
136-
await mouse.move(right(500));
137-
await mouse.move(down(500));
138-
await mouse.move(left(500));
139-
await mouse.move(up(500));
140-
};
147+
function activeWindowRegion() {
148+
return getActiveWindow().then((activeWindow) => activeWindow.region);
149+
}
141150

142151
(async () => {
143-
await square();
144-
await mouse.move(straightTo(centerOf(new Region(100, 100, 200, 300))));
152+
await preloadLanguages([Language.English], [LanguageModelType.BEST]);
153+
await sleep(5000);
154+
const result = await screen.find(singleWord("@nut-tree/nut-js"));
155+
await mouse.move(straightTo(centerOf(result)));
156+
await mouse.click(Button.LEFT);
157+
await screen.waitFor(singleWord("Native"), 15000, 1000, {
158+
providerData: { partialMatch: true },
159+
});
160+
const content = await screen.read({ searchRegion: activeWindowRegion() });
161+
console.log(content);
145162
})();
146163
```
147164

lib/query.class.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,52 @@ type Query =
2323

2424
export type TextQuery = Extract<Query, { type: "text" }>;
2525

26-
export type WordQuery = Extract<TextQuery, { by: { word: string | RegExp } }>;
27-
export type LineQuery = Extract<TextQuery, { by: { line: string | RegExp } }>;
26+
/**
27+
* A word query is a text query that searches for a single word on screen.
28+
* It will be processed by an {@link TextFinderInterface} instance.
29+
*/
30+
export type WordQuery = Extract<TextQuery, { by: { word: string } }>;
2831

32+
/**
33+
* A word query is a text query that searches for a single text line on screen.
34+
* It will be processed by an {@link TextFinderInterface} instance.
35+
*/
36+
export type LineQuery = Extract<TextQuery, { by: { line: string } }>;
37+
38+
/**
39+
* A window query is a query that searches for a window on screen.
40+
* It will be processed by an {@link WindowFinderInterface} instance.
41+
*/
2942
export type WindowQuery = Extract<Query, { type: "window" }>;
3043

44+
/**
45+
* Type guard for {@link WordQuery}
46+
* @param possibleQuery A possible word query
47+
*/
3148
export const isWordQuery = (possibleQuery: any): possibleQuery is WordQuery => {
3249
return possibleQuery?.type === "text" && possibleQuery?.by?.word != null;
3350
};
51+
52+
/**
53+
* Type guard for {@link LineQuery}
54+
* @param possibleQuery A possible line query
55+
*/
3456
export const isLineQuery = (possibleQuery: any): possibleQuery is LineQuery => {
3557
return possibleQuery?.type === "text" && possibleQuery?.by?.line != null;
3658
};
3759

60+
/**
61+
* Type guard for {@link TextQuery}
62+
* @param possibleQuery A possible line or word query
63+
*/
3864
export const isTextQuery = (possibleQuery: any): possibleQuery is TextQuery => {
3965
return possibleQuery?.type === "text";
4066
};
4167

68+
/**
69+
* Type guard for {@link WindowQuery}
70+
* @param possibleQuery A possible window query
71+
*/
4272
export const isWindowQuery = (
4373
possibleQuery: any
4474
): possibleQuery is WindowQuery => {

lib/screen.class.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ export class ScreenClass {
415415
* @param searchInput Filename of the template image, relative to {@link ScreenClass.config.resourceDirectory}, or an {@link Image}
416416
* @param timeoutMs Timeout in milliseconds after which {@link waitFor} fails
417417
* @param updateInterval Update interval in milliseconds to retry search
418-
* @param params {@link LocationParameters} which are used to fine tune search region and / or match confidence
418+
* @param params {@link OptionalSearchParameters} which are used to fine tune search region and / or match confidence
419419
*/
420420
public async waitFor<PROVIDER_DATA_TYPE>(
421421
searchInput: RegionResultFindInput | Promise<RegionResultFindInput>,

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nut-tree/nut-js",
3-
"version": "2.3.0",
3+
"version": "3.0.0",
44
"license": "Apache-2.0",
55
"main": "dist/index",
66
"typings": "dist/index",

0 commit comments

Comments
 (0)