Skip to content
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

Bind all class methods using the keyword "this" #582

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions core/nut.js/lib/assert.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ export class AssertClass {
constructor(private screen: ScreenClass) {
}

public async isVisible(
public isVisible = async (
searchInput: FindInput | Promise<FindInput>,
searchRegion?: Region | Promise<Region>,
confidence?: number
): Promise<void> {
): Promise<void> => {
const needle = await searchInput;
const identifier = needle.id;

Expand All @@ -29,11 +29,11 @@ export class AssertClass {
}
}

public async notVisible(
public notVisible = async (
searchInput: FindInput | Promise<FindInput>,
searchRegion?: Region | Promise<Region>,
confidence?: number
) {
) => {
const needle = await searchInput;
const identifier = needle.id;

Expand Down
4 changes: 2 additions & 2 deletions core/nut.js/lib/clipboard.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ export class ClipboardClass {
* {@link setContent} copies a given text to the system clipboard
* @param text The text to copy
*/
public async setContent(text: string): Promise<void> {
public setContent = async (text: string): Promise<void> => {
await this.providerRegistry.getClipboard().copy(text);
this.providerRegistry.getLogProvider().debug(`Saved to clipboard`);
}

/**
* {@link getContent} returns the current content of the system clipboard (limited to text)
*/
public async getContent(): Promise<string> {
public getContent = async (): Promise<string> => {
const content = await this.providerRegistry.getClipboard().paste();
this.providerRegistry.getLogProvider().debug(`Fetched clipboard content`);
return content;
Expand Down
6 changes: 3 additions & 3 deletions core/nut.js/lib/keyboard.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class KeyboardClass {
*
* @param input Sequence of {@link String} or {@link Key} to type
*/
public async type(...input: StringOrKey): Promise<KeyboardClass> {
public type = async (...input: StringOrKey): Promise<KeyboardClass> => {
try {
if (inputIsString(input)) {
for (const char of input.join(" ")) {
Expand Down Expand Up @@ -88,7 +88,7 @@ export class KeyboardClass {
*
* @param keys Array of {@link Key}s to press and hold
*/
public async pressKey(...keys: Key[]): Promise<KeyboardClass> {
public pressKey = async (...keys: Key[]): Promise<KeyboardClass> => {
try {
await sleep(this.config.autoDelayMs);
await this.providerRegistry.getKeyboard().pressKey(...keys);
Expand All @@ -112,7 +112,7 @@ export class KeyboardClass {
*
* @param keys Array of {@link Key}s to release
*/
public async releaseKey(...keys: Key[]): Promise<KeyboardClass> {
public releaseKey = async (...keys: Key[]): Promise<KeyboardClass> => {
try {
await sleep(this.config.autoDelayMs);
await this.providerRegistry.getKeyboard().releaseKey(...keys);
Expand Down
30 changes: 15 additions & 15 deletions core/nut.js/lib/mouse.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class MouseClass {
* {@link setPosition} instantly moves the mouse cursor to a given {@link Point}
* @param target {@link Point} to move the cursor to
*/
public async setPosition(target: Point): Promise<MouseClass> {
public setPosition = async (target: Point): Promise<MouseClass> => {
if (!isPoint(target)) {
const e = new Error(
`setPosition requires a Point, but received ${JSON.stringify(target)}`
Expand All @@ -64,7 +64,7 @@ export class MouseClass {
/**
* {@link getPosition} returns a {@link Point} representing the current mouse position
*/
public async getPosition(): Promise<Point> {
public getPosition = async (): Promise<Point> => {
const currentPosition = await this.providerRegistry
.getMouse()
.currentMousePosition();
Expand All @@ -79,10 +79,10 @@ export class MouseClass {
* @param path Array of {@link Point}s to follow
* @param movementType Defines the type of mouse movement. Would allow to configured acceleration etc. (Default: {@link linear}, no acceleration)
*/
public async move(
public move = async (
path: Point[] | Promise<Point[]>,
movementType: EasingFunction = linear
): Promise<MouseClass> {
): Promise<MouseClass> => {
try {
let pathSteps = await path;
if (!Array.isArray(pathSteps)) {
Expand Down Expand Up @@ -114,14 +114,14 @@ export class MouseClass {
/**
* {@link leftClick} performs a click with the left mouse button
*/
public async leftClick(): Promise<MouseClass> {
public leftClick = async (): Promise<MouseClass> => {
return this.click(Button.LEFT);
}

/**
* {@link rightClick} performs a click with the right mouse button
*/
public async rightClick(): Promise<MouseClass> {
public rightClick = async (): Promise<MouseClass> => {
return this.click(Button.RIGHT);
}

Expand All @@ -130,7 +130,7 @@ export class MouseClass {
* Please note that the actual scroll distance of a single "step" is OS dependent
* @param amount The amount of "steps" to scroll
*/
public async scrollDown(amount: number): Promise<MouseClass> {
public scrollDown = async (amount: number): Promise<MouseClass> => {
try {
await sleep(this.config.autoDelayMs);
await this.providerRegistry.getMouse().scrollDown(amount);
Expand All @@ -149,7 +149,7 @@ export class MouseClass {
* Please note that the actual scroll distance of a single "step" is OS dependent
* @param amount The amount of "steps" to scroll
*/
public async scrollUp(amount: number): Promise<MouseClass> {
public scrollUp = async (amount: number): Promise<MouseClass> => {
try {
await sleep(this.config.autoDelayMs);
await this.providerRegistry.getMouse().scrollUp(amount);
Expand All @@ -168,7 +168,7 @@ export class MouseClass {
* Please note that the actual scroll distance of a single "step" is OS dependent
* @param amount The amount of "steps" to scroll
*/
public async scrollLeft(amount: number): Promise<MouseClass> {
public scrollLeft = async (amount: number): Promise<MouseClass> => {
try {
await sleep(this.config.autoDelayMs);
await this.providerRegistry.getMouse().scrollLeft(amount);
Expand All @@ -187,7 +187,7 @@ export class MouseClass {
* Please note that the actual scroll distance of a single "step" is OS dependent
* @param amount The amount of "steps" to scroll
*/
public async scrollRight(amount: number): Promise<MouseClass> {
public scrollRight = async (amount: number): Promise<MouseClass> => {
try {
await sleep(this.config.autoDelayMs);
await this.providerRegistry.getMouse().scrollRight(amount);
Expand All @@ -206,7 +206,7 @@ export class MouseClass {
* In summary, {@link drag} presses and holds the left mouse button, moves the mouse and releases the left button
* @param path The path of {@link Point}s to drag along
*/
public async drag(path: Point[] | Promise<Point[]>): Promise<MouseClass> {
public drag = async (path: Point[] | Promise<Point[]>): Promise<MouseClass> => {
try {
await sleep(this.config.autoDelayMs);
await this.providerRegistry.getMouse().pressButton(Button.LEFT);
Expand All @@ -225,7 +225,7 @@ export class MouseClass {
* {@link pressButton} presses and holds a mouse button
* @param btn The {@link Button} to press and hold
*/
public async pressButton(btn: Button): Promise<MouseClass> {
public pressButton = async (btn: Button): Promise<MouseClass> => {
try {
await sleep(this.config.autoDelayMs);
await this.providerRegistry.getMouse().pressButton(btn);
Expand All @@ -244,7 +244,7 @@ export class MouseClass {
* {@link releaseButton} releases a mouse button previously pressed via {@link pressButton}
* @param btn The {@link Button} to release
*/
public async releaseButton(btn: Button): Promise<MouseClass> {
public releaseButton = async (btn: Button): Promise<MouseClass> => {
try {
await sleep(this.config.autoDelayMs);
await this.providerRegistry.getMouse().releaseButton(btn);
Expand All @@ -263,7 +263,7 @@ export class MouseClass {
* {@link click} clicks a mouse button
* @param btn The {@link Button} to click
*/
public async click(btn: Button): Promise<MouseClass> {
public click = async (btn: Button): Promise<MouseClass> => {
try {
await sleep(this.config.autoDelayMs);
await this.providerRegistry.getMouse().click(btn);
Expand All @@ -282,7 +282,7 @@ export class MouseClass {
* {@link doubleClick} performs a double click on a mouse button
* @param btn The {@link Button} to click
*/
public async doubleClick(btn: Button): Promise<MouseClass> {
public doubleClick = async (btn: Button): Promise<MouseClass> => {
try {
await sleep(this.config.autoDelayMs);
await this.providerRegistry.getMouse().doubleClick(btn);
Expand Down
2 changes: 1 addition & 1 deletion core/nut.js/lib/provider/io/jimp-image-reader.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ImageReader } from "@nut-tree/provider-interfaces";
import { ColorMode, Image } from "@nut-tree/shared";

export default class implements ImageReader {
load(parameters: string): Promise<Image> {
load = (parameters: string): Promise<Image> => {
return new Promise<Image>((resolve, reject) => {
Jimp.read(parameters)
.then((jimpImage) => {
Expand Down
12 changes: 6 additions & 6 deletions core/nut.js/lib/provider/log/console-log-provider.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class ConsoleLogProvider implements LogProviderInterface {
this.withTimeStamp = config.withTimeStamp ?? true;
}

private log(logLevel: ConsoleLogLevel, message: string | Error, data?: {}) {
private log = (logLevel: ConsoleLogLevel, message: string | Error, data?: {}) => {
if (logLevel >= this.logLevel) {
const timeStampPrefix = `${new Date().toISOString()} - `;
const extendedMessage = `${
Expand Down Expand Up @@ -81,23 +81,23 @@ export class ConsoleLogProvider implements LogProviderInterface {
}
}

public trace(message: string, data?: {}) {
public trace = (message: string, data?: {}) => {
this.log(ConsoleLogLevel.TRACE, message, data);
}

public debug(message: string, data?: {}) {
public debug = (message: string, data?: {}) => {
this.log(ConsoleLogLevel.DEBUG, message, data);
}

public info(message: string, data?: {}) {
public info = (message: string, data?: {}) => {
this.log(ConsoleLogLevel.INFO, message, data);
}

public warn(message: string, data?: {}) {
public warn = (message: string, data?: {}) => {
this.log(ConsoleLogLevel.WARN, message, data);
}

public error(message: Error, data?: {}) {
public error = (message: Error, data?: {}) => {
this.log(ConsoleLogLevel.ERROR, message, data);
}
}
26 changes: 13 additions & 13 deletions core/nut.js/lib/provider/provider-registry.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class DefaultProviderRegistry implements ProviderRegistry {
private _colorFinder?: ColorFinderInterface;
private _windowElementInspector?: ElementInspectionProviderInterface;

hasClipboard(): boolean {
hasClipboard = (): boolean => {
return this._clipboard != null;
}

Expand All @@ -66,7 +66,7 @@ class DefaultProviderRegistry implements ProviderRegistry {
this.getLogProvider().trace("Registered new clipboard provider", value);
};

hasImageFinder(): boolean {
hasImageFinder = (): boolean => {
return this._imageFinder != null;
}

Expand All @@ -84,7 +84,7 @@ class DefaultProviderRegistry implements ProviderRegistry {
this.getLogProvider().trace("Registered new image finder", value);
};

hasKeyboard(): boolean {
hasKeyboard = (): boolean => {
return this._keyboard != null;
}

Expand All @@ -102,7 +102,7 @@ class DefaultProviderRegistry implements ProviderRegistry {
this.getLogProvider().trace("Registered new keyboard provider", value);
};

hasMouse(): boolean {
hasMouse = (): boolean => {
return this._mouse != null;
}

Expand All @@ -120,7 +120,7 @@ class DefaultProviderRegistry implements ProviderRegistry {
this.getLogProvider().trace("Registered new mouse provider", value);
};

hasScreen(): boolean {
hasScreen = (): boolean => {
return this._screen != null;
}

Expand All @@ -138,7 +138,7 @@ class DefaultProviderRegistry implements ProviderRegistry {
this.getLogProvider().trace("Registered new screen provider", value);
};

hasWindow(): boolean {
hasWindow = (): boolean => {
return this._window != null;
}

Expand All @@ -156,7 +156,7 @@ class DefaultProviderRegistry implements ProviderRegistry {
this.getLogProvider().trace("Registered new window provider", value);
};

hasTextFinder(): boolean {
hasTextFinder = (): boolean => {
return this._textFinder != null;
}

Expand All @@ -174,7 +174,7 @@ class DefaultProviderRegistry implements ProviderRegistry {
this.getLogProvider().trace("Registered new TextFinder provider", value);
};

hasWindowFinder(): boolean {
hasWindowFinder = (): boolean => {
return this._windowFinder != null;
}

Expand Down Expand Up @@ -206,7 +206,7 @@ class DefaultProviderRegistry implements ProviderRegistry {
this.getLogProvider().trace("Registered new WindowElementInspector provider", value);
};

hasImageReader(): boolean {
hasImageReader = (): boolean => {
return this._imageReader != null;
}

Expand All @@ -224,7 +224,7 @@ class DefaultProviderRegistry implements ProviderRegistry {
this.getLogProvider().trace("Registered new image reader", value);
};

hasImageWriter(): boolean {
hasImageWriter = (): boolean => {
return this._imageWriter != null;
}

Expand All @@ -242,7 +242,7 @@ class DefaultProviderRegistry implements ProviderRegistry {
this.getLogProvider().trace("Registered new image writer", value);
};

hasImageProcessor(): boolean {
hasImageProcessor = (): boolean => {
return this._imageProcessor != null;
}

Expand All @@ -260,7 +260,7 @@ class DefaultProviderRegistry implements ProviderRegistry {
this.getLogProvider().trace("Registered new image processor", value);
};

hasLogProvider(): boolean {
hasLogProvider = (): boolean => {
return this._logProvider != null;
}

Expand All @@ -278,7 +278,7 @@ class DefaultProviderRegistry implements ProviderRegistry {
this.getLogProvider().trace("Registered new log provider", value);
};

hasColorFinder(): boolean {
hasColorFinder = (): boolean => {
return this._colorFinder != null;
}

Expand Down
Loading