Skip to content

Feature/47/async cleanup #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Mar 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 34 additions & 34 deletions lib/adapter/native.adapter.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ export class NativeAdapter {
* @param {Point} p The new cursor position
* @memberof NativeAdapter
*/
public async setMousePosition(p: Point): Promise<void> {
await this.mouse.setMousePosition(p);
public setMousePosition(p: Point): Promise<void> {
return this.mouse.setMousePosition(p);
}

/**
Expand All @@ -58,33 +58,33 @@ export class NativeAdapter {
* @returns {Promise<Point>} Current cursor position
* @memberof NativeAdapter
*/
public async currentMousePosition(): Promise<Point> {
return await this.mouse.currentMousePosition();
public currentMousePosition(): Promise<Point> {
return this.mouse.currentMousePosition();
}

/**
* leftClick triggers a native left-click event via OS API
*
* @memberof NativeAdapter
*/
public async leftClick(): Promise<void> {
await this.mouse.leftClick();
public leftClick(): Promise<void> {
return this.mouse.leftClick();
}

/**
* rightClick triggers a native right-click event via OS API
*
* @memberof NativeAdapter
*/
public async rightClick(): Promise<void> {
await this.mouse.rightClick();
public rightClick(): Promise<void> {
return this.mouse.rightClick();
}

/**
* middleClick triggers a native middle-click event via OS API
*/
public async middleClick(): Promise<void> {
await this.mouse.middleClick();
public middleClick(): Promise<void> {
return this.mouse.middleClick();
}

/**
Expand All @@ -93,8 +93,8 @@ export class NativeAdapter {
* @param {Button} btn The mouse button to press
* @memberof NativeAdapter
*/
public async pressButton(btn: Button): Promise<void> {
await this.mouse.pressButton(btn);
public pressButton(btn: Button): Promise<void> {
return this.mouse.pressButton(btn);
}

/**
Expand All @@ -103,8 +103,8 @@ export class NativeAdapter {
* @param {Button} btn The mouse button to release
* @memberof NativeAdapter
*/
public async releaseButton(btn: Button): Promise<void> {
await this.mouse.releaseButton(btn);
public releaseButton(btn: Button): Promise<void> {
return this.mouse.releaseButton(btn);
}

/**
Expand All @@ -113,8 +113,8 @@ export class NativeAdapter {
* @param {string} input The text to type
* @memberof NativeAdapter
*/
public async type(input: string): Promise<void> {
await this.keyboard.type(input);
public type(input: string): Promise<void> {
return this.keyboard.type(input);
}

/**
Expand All @@ -123,8 +123,8 @@ export class NativeAdapter {
* @param {Key[]} keys The keys to click
* @memberof NativeAdapter
*/
public async click(...keys: Key[]): Promise<void> {
await this.keyboard.click(...keys);
public click(...keys: Key[]): Promise<void> {
return this.keyboard.click(...keys);
}

/**
Expand All @@ -133,8 +133,8 @@ export class NativeAdapter {
* @param {Key[]} keys The Keys to press and hold
* @memberof NativeAdapter
*/
public async pressKey(...keys: Key[]): Promise<void> {
await this.keyboard.pressKey(...keys);
public pressKey(...keys: Key[]): Promise<void> {
return this.keyboard.pressKey(...keys);
}

/**
Expand All @@ -143,8 +143,8 @@ export class NativeAdapter {
* @param {Key[]} keys The Keys to release
* @memberof NativeAdapter
*/
public async releaseKey(...keys: Key[]): Promise<void> {
await this.keyboard.releaseKey(...keys);
public releaseKey(...keys: Key[]): Promise<void> {
return this.keyboard.releaseKey(...keys);
}

/**
Expand All @@ -153,8 +153,8 @@ export class NativeAdapter {
* @param {number} amount The amount of 'ticks' to scroll
* @memberof NativeAdapter
*/
public async scrollUp(amount: number): Promise<void> {
await this.mouse.scrollUp(amount);
public scrollUp(amount: number): Promise<void> {
return this.mouse.scrollUp(amount);
}

/**
Expand All @@ -163,8 +163,8 @@ export class NativeAdapter {
* @param {number} amount The amount of 'ticks' to scroll
* @memberof NativeAdapter
*/
public async scrollDown(amount: number): Promise<void> {
await this.mouse.scrollDown(amount);
public scrollDown(amount: number): Promise<void> {
return this.mouse.scrollDown(amount);
}

/**
Expand All @@ -173,8 +173,8 @@ export class NativeAdapter {
* @param {number} amount The amount of 'ticks' to scroll
* @memberof NativeAdapter
*/
public async scrollLeft(amount: number): Promise<void> {
await this.mouse.scrollLeft(amount);
public scrollLeft(amount: number): Promise<void> {
return this.mouse.scrollLeft(amount);
}

/**
Expand All @@ -183,8 +183,8 @@ export class NativeAdapter {
* @param {number} amount The amount of 'ticks' to scroll
* @memberof NativeAdapter
*/
public async scrollRight(amount: number): Promise<void> {
await this.mouse.scrollRight(amount);
public scrollRight(amount: number): Promise<void> {
return this.mouse.scrollRight(amount);
}

/**
Expand All @@ -193,8 +193,8 @@ export class NativeAdapter {
* @param {string} text The text to copy
* @memberof NativeAdapter
*/
public async copy(text: string): Promise<void> {
await this.clipboard.copy(text);
public copy(text: string): Promise<void> {
return this.clipboard.copy(text);
}

/**
Expand All @@ -203,7 +203,7 @@ export class NativeAdapter {
* @returns {Promise<string>} The clipboard text
* @memberof NativeAdapter
*/
public async paste(): Promise<string> {
return await this.clipboard.paste();
public paste(): Promise<string> {
return this.clipboard.paste();
}
}
24 changes: 12 additions & 12 deletions lib/adapter/vision.adapter.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export class VisionAdapter {
* @returns {Promise<Image>} Image will contain screenshot data as well as dimensions
* @memberof VisionAdapter
*/
public async grabScreen(): Promise<Image> {
return await this.screen.grabScreen();
public grabScreen(): Promise<Image> {
return this.screen.grabScreen();
}

/**
Expand All @@ -41,8 +41,8 @@ export class VisionAdapter {
* @returns {Promise<Image>} Image will contain screenshot data of the specified region as well as dimensions
* @memberof VisionAdapter
*/
public async grabScreenRegion(region: Region): Promise<Image> {
return await this.screen.grabScreenRegion(region);
public grabScreenRegion(region: Region): Promise<Image> {
return this.screen.grabScreenRegion(region);
}

/**
Expand Down Expand Up @@ -75,8 +75,8 @@ export class VisionAdapter {
* @returns {Promise<number>} The main screen's width as reported by the OS
* @memberof VisionAdapter
*/
public async screenWidth(): Promise<number> {
return await this.screen.screenWidth();
public screenWidth(): Promise<number> {
return this.screen.screenWidth();
}

/**
Expand All @@ -87,8 +87,8 @@ export class VisionAdapter {
* @returns {Promise<number>} The main screen's height as reported by the OS
* @memberof VisionAdapter
*/
public async screenHeight(): Promise<number> {
return await this.screen.screenHeight();
public screenHeight(): Promise<number> {
return this.screen.screenHeight();
}

/**
Expand All @@ -99,8 +99,8 @@ export class VisionAdapter {
* @returns {Promise<Region>} The Region object the size of your main screen
* @memberof VisionAdapter
*/
public async screenSize(): Promise<Region> {
return await this.screen.screenSize();
public screenSize(): Promise<Region> {
return this.screen.screenSize();
}

/**
Expand All @@ -110,7 +110,7 @@ export class VisionAdapter {
* @param path The storage path
* @memberof VisionAdapter
*/
public async saveImage(image: Image, path: string): Promise<void> {
await (this.dataSink as ImageWriter).store(image, path);
public saveImage(image: Image, path: string): Promise<void> {
return (this.dataSink as ImageWriter).store(image, path);
}
}
8 changes: 3 additions & 5 deletions lib/clipboard.class.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { NativeAdapter } from "./adapter/native.adapter.class";

export class Clipboard {
constructor(private nativeAdapter: NativeAdapter) {}
constructor(private nativeAdapter: NativeAdapter) {
}

public copy(text: string): Promise<void> {
return new Promise<void>(resolve => {
this.nativeAdapter.copy(text);
resolve();
});
return this.nativeAdapter.copy(text);
}

public paste(): Promise<string> {
Expand Down
42 changes: 27 additions & 15 deletions lib/keyboard.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,43 @@ export class Keyboard {
}

public type(...input: StringOrKey): Promise<Keyboard> {
return new Promise<Keyboard>(async resolve => {
if (inputIsString(input)) {
for (const char of input.join(" ").split("")) {
await this.nextTick();
await this.nativeAdapter.type(char);
this.updateTick();
return new Promise<Keyboard>(async (resolve, reject) => {
try {
if (inputIsString(input)) {
for (const char of input.join(" ").split("")) {
await this.nextTick();
await this.nativeAdapter.type(char);
this.updateTick();
}
} else {
await this.nativeAdapter.click(...input as Key[]);
}
} else {
await this.nativeAdapter.click(...input as Key[]);
resolve(this);
} catch (e) {
reject(e);
}
resolve(this);
});
}

public pressKey(...keys: Key[]): Promise<Keyboard> {
return new Promise<Keyboard>(async resolve => {
await this.nativeAdapter.pressKey(...keys);
resolve(this);
return new Promise<Keyboard>(async (resolve, reject) => {
try {
await this.nativeAdapter.pressKey(...keys);
resolve(this);
} catch (e) {
reject(e);
}
});
}

public releaseKey(...keys: Key[]): Promise<Keyboard> {
return new Promise<Keyboard>(async resolve => {
await this.nativeAdapter.releaseKey(...keys);
resolve(this);
return new Promise<Keyboard>(async (resolve, reject) => {
try {
await this.nativeAdapter.releaseKey(...keys);
resolve(this);
} catch (e) {
reject(e);
}
});
}

Expand Down
Loading