Skip to content

Commit d01410f

Browse files
authored
Release/v3.1.2 (#514)
* Updated changelog * Update dependencies * npm audit fix * Version bump to v3.1.2 * Address sonar issues * Increase test coverage * Properly adapt color query test to findAll
1 parent db54f92 commit d01410f

10 files changed

+334
-296
lines changed

Diff for: CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

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

5+
## 3.1.2
6+
7+
- Bugfix: Screen capture broken on macOS 13 [(#469)](https://github.com/nut-tree/nut.js/issues/469)
8+
- Enhancement: Enable newly introduced keys to be used as modifiers [(#490)](https://github.com/nut-tree/nut.js/issues/490)
9+
- Enhancement: Extend move API to handle single point case [(#499)](https://github.com/nut-tree/nut.js/issues/499)
10+
- Feature: Add color queries to search for pixels of a certain color [(#500)](https://github.com/nut-tree/nut.js/issues/500)
11+
- Bugfix: screen.highlight closes Electron window [(#505)](https://github.com/nut-tree/nut.js/issues/505)
12+
513
## 3.1.1
614

715
- Bugfix: Fix mouse drift on Windows [(nut-tree/libnut-core#126)](https://github.com/nut-tree/libnut-core/issues/126)

Diff for: lib/keyboard.class.ts

+44-52
Original file line numberDiff line numberDiff line change
@@ -49,32 +49,30 @@ export class KeyboardClass {
4949
*
5050
* @param input Sequence of {@link String} or {@link Key} to type
5151
*/
52-
public type(...input: StringOrKey): Promise<KeyboardClass> {
53-
return new Promise<KeyboardClass>(async (resolve, reject) => {
54-
try {
55-
if (inputIsString(input)) {
56-
for (const char of input.join(" ")) {
57-
await sleep(this.config.autoDelayMs);
58-
await this.providerRegistry.getKeyboard().type(char);
59-
this.providerRegistry.getLogProvider().debug(`Tapped ${char}`);
60-
}
61-
this.providerRegistry.getLogProvider().info(`Typed string ${input}`);
62-
} else {
63-
await this.providerRegistry.getKeyboard().click(...(input as Key[]));
64-
const key = input[input.length - 1];
65-
const modifiers = input.slice(0, -1);
66-
const keyName = Key[key];
67-
const modifierNames = modifiers.map((modifier) => Key[modifier]);
68-
this.providerRegistry
69-
.getLogProvider()
70-
.info(`Tapped key ${keyName} with modifiers ${modifierNames}`);
52+
public async type(...input: StringOrKey): Promise<KeyboardClass> {
53+
try {
54+
if (inputIsString(input)) {
55+
for (const char of input.join(" ")) {
56+
await sleep(this.config.autoDelayMs);
57+
await this.providerRegistry.getKeyboard().type(char);
58+
this.providerRegistry.getLogProvider().debug(`Tapped ${char}`);
7159
}
72-
resolve(this);
73-
} catch (e) {
74-
this.providerRegistry.getLogProvider().error(e as Error);
75-
reject(e);
60+
this.providerRegistry.getLogProvider().info(`Typed string ${input}`);
61+
} else {
62+
await this.providerRegistry.getKeyboard().click(...(input as Key[]));
63+
const key = input[input.length - 1];
64+
const modifiers = input.slice(0, -1);
65+
const keyName = Key[key];
66+
const modifierNames = modifiers.map((modifier) => Key[modifier]);
67+
this.providerRegistry
68+
.getLogProvider()
69+
.info(`Tapped key ${keyName} with modifiers ${modifierNames}`);
7670
}
77-
});
71+
return this;
72+
} catch (e) {
73+
this.providerRegistry.getLogProvider().error(e as Error);
74+
throw e;
75+
}
7876
}
7977

8078
/**
@@ -88,19 +86,17 @@ export class KeyboardClass {
8886
*
8987
* @param keys Array of {@link Key}s to press and hold
9088
*/
91-
public pressKey(...keys: Key[]): Promise<KeyboardClass> {
92-
return new Promise<KeyboardClass>(async (resolve, reject) => {
93-
try {
94-
await sleep(this.config.autoDelayMs);
95-
await this.providerRegistry.getKeyboard().pressKey(...keys);
96-
const keyNames = keys.map((key) => Key[key]);
97-
this.providerRegistry.getLogProvider().info(`Pressed keys ${keyNames}`);
98-
resolve(this);
99-
} catch (e) {
100-
this.providerRegistry.getLogProvider().error(e as Error);
101-
reject(e);
102-
}
103-
});
89+
public async pressKey(...keys: Key[]): Promise<KeyboardClass> {
90+
try {
91+
await sleep(this.config.autoDelayMs);
92+
await this.providerRegistry.getKeyboard().pressKey(...keys);
93+
const keyNames = keys.map((key) => Key[key]);
94+
this.providerRegistry.getLogProvider().info(`Pressed keys ${keyNames}`);
95+
return this;
96+
} catch (e) {
97+
this.providerRegistry.getLogProvider().error(e as Error);
98+
throw e;
99+
}
104100
}
105101

106102
/**
@@ -114,20 +110,16 @@ export class KeyboardClass {
114110
*
115111
* @param keys Array of {@link Key}s to release
116112
*/
117-
public releaseKey(...keys: Key[]): Promise<KeyboardClass> {
118-
return new Promise<KeyboardClass>(async (resolve, reject) => {
119-
try {
120-
await sleep(this.config.autoDelayMs);
121-
await this.providerRegistry.getKeyboard().releaseKey(...keys);
122-
const keyNames = keys.map((key) => Key[key]);
123-
this.providerRegistry
124-
.getLogProvider()
125-
.info(`Released keys ${keyNames}`);
126-
resolve(this);
127-
} catch (e) {
128-
this.providerRegistry.getLogProvider().error(e as Error);
129-
reject(e);
130-
}
131-
});
113+
public async releaseKey(...keys: Key[]): Promise<KeyboardClass> {
114+
try {
115+
await sleep(this.config.autoDelayMs);
116+
await this.providerRegistry.getKeyboard().releaseKey(...keys);
117+
const keyNames = keys.map((key) => Key[key]);
118+
this.providerRegistry.getLogProvider().info(`Released keys ${keyNames}`);
119+
return this;
120+
} catch (e) {
121+
this.providerRegistry.getLogProvider().error(e as Error);
122+
throw e;
123+
}
132124
}
133125
}

0 commit comments

Comments
 (0)