diff --git a/core/nut.js/lib/assert.class.ts b/core/nut.js/lib/assert.class.ts index 4db61fe1..dda1b95f 100644 --- a/core/nut.js/lib/assert.class.ts +++ b/core/nut.js/lib/assert.class.ts @@ -5,11 +5,11 @@ export class AssertClass { constructor(private screen: ScreenClass) { } - public async isVisible( + public isVisible = async ( searchInput: FindInput | Promise, searchRegion?: Region | Promise, confidence?: number - ): Promise { + ): Promise => { const needle = await searchInput; const identifier = needle.id; @@ -29,11 +29,11 @@ export class AssertClass { } } - public async notVisible( + public notVisible = async ( searchInput: FindInput | Promise, searchRegion?: Region | Promise, confidence?: number - ) { + ) => { const needle = await searchInput; const identifier = needle.id; diff --git a/core/nut.js/lib/clipboard.class.ts b/core/nut.js/lib/clipboard.class.ts index 63ec8fc2..55646b4f 100644 --- a/core/nut.js/lib/clipboard.class.ts +++ b/core/nut.js/lib/clipboard.class.ts @@ -15,7 +15,7 @@ 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 { + public setContent = async (text: string): Promise => { await this.providerRegistry.getClipboard().copy(text); this.providerRegistry.getLogProvider().debug(`Saved to clipboard`); } @@ -23,7 +23,7 @@ export class ClipboardClass { /** * {@link getContent} returns the current content of the system clipboard (limited to text) */ - public async getContent(): Promise { + public getContent = async (): Promise => { const content = await this.providerRegistry.getClipboard().paste(); this.providerRegistry.getLogProvider().debug(`Fetched clipboard content`); return content; diff --git a/core/nut.js/lib/keyboard.class.ts b/core/nut.js/lib/keyboard.class.ts index c1aaab4c..98c84298 100644 --- a/core/nut.js/lib/keyboard.class.ts +++ b/core/nut.js/lib/keyboard.class.ts @@ -51,7 +51,7 @@ export class KeyboardClass { * * @param input Sequence of {@link String} or {@link Key} to type */ - public async type(...input: StringOrKey): Promise { + public type = async (...input: StringOrKey): Promise => { try { if (inputIsString(input)) { for (const char of input.join(" ")) { @@ -88,7 +88,7 @@ export class KeyboardClass { * * @param keys Array of {@link Key}s to press and hold */ - public async pressKey(...keys: Key[]): Promise { + public pressKey = async (...keys: Key[]): Promise => { try { await sleep(this.config.autoDelayMs); await this.providerRegistry.getKeyboard().pressKey(...keys); @@ -112,7 +112,7 @@ export class KeyboardClass { * * @param keys Array of {@link Key}s to release */ - public async releaseKey(...keys: Key[]): Promise { + public releaseKey = async (...keys: Key[]): Promise => { try { await sleep(this.config.autoDelayMs); await this.providerRegistry.getKeyboard().releaseKey(...keys); diff --git a/core/nut.js/lib/mouse.class.ts b/core/nut.js/lib/mouse.class.ts index 8c818656..e686737a 100644 --- a/core/nut.js/lib/mouse.class.ts +++ b/core/nut.js/lib/mouse.class.ts @@ -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 { + public setPosition = async (target: Point): Promise => { if (!isPoint(target)) { const e = new Error( `setPosition requires a Point, but received ${JSON.stringify(target)}` @@ -64,7 +64,7 @@ export class MouseClass { /** * {@link getPosition} returns a {@link Point} representing the current mouse position */ - public async getPosition(): Promise { + public getPosition = async (): Promise => { const currentPosition = await this.providerRegistry .getMouse() .currentMousePosition(); @@ -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, movementType: EasingFunction = linear - ): Promise { + ): Promise => { try { let pathSteps = await path; if (!Array.isArray(pathSteps)) { @@ -114,14 +114,14 @@ export class MouseClass { /** * {@link leftClick} performs a click with the left mouse button */ - public async leftClick(): Promise { + public leftClick = async (): Promise => { return this.click(Button.LEFT); } /** * {@link rightClick} performs a click with the right mouse button */ - public async rightClick(): Promise { + public rightClick = async (): Promise => { return this.click(Button.RIGHT); } @@ -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 { + public scrollDown = async (amount: number): Promise => { try { await sleep(this.config.autoDelayMs); await this.providerRegistry.getMouse().scrollDown(amount); @@ -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 { + public scrollUp = async (amount: number): Promise => { try { await sleep(this.config.autoDelayMs); await this.providerRegistry.getMouse().scrollUp(amount); @@ -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 { + public scrollLeft = async (amount: number): Promise => { try { await sleep(this.config.autoDelayMs); await this.providerRegistry.getMouse().scrollLeft(amount); @@ -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 { + public scrollRight = async (amount: number): Promise => { try { await sleep(this.config.autoDelayMs); await this.providerRegistry.getMouse().scrollRight(amount); @@ -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): Promise { + public drag = async (path: Point[] | Promise): Promise => { try { await sleep(this.config.autoDelayMs); await this.providerRegistry.getMouse().pressButton(Button.LEFT); @@ -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 { + public pressButton = async (btn: Button): Promise => { try { await sleep(this.config.autoDelayMs); await this.providerRegistry.getMouse().pressButton(btn); @@ -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 { + public releaseButton = async (btn: Button): Promise => { try { await sleep(this.config.autoDelayMs); await this.providerRegistry.getMouse().releaseButton(btn); @@ -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 { + public click = async (btn: Button): Promise => { try { await sleep(this.config.autoDelayMs); await this.providerRegistry.getMouse().click(btn); @@ -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 { + public doubleClick = async (btn: Button): Promise => { try { await sleep(this.config.autoDelayMs); await this.providerRegistry.getMouse().doubleClick(btn); diff --git a/core/nut.js/lib/provider/io/jimp-image-reader.class.ts b/core/nut.js/lib/provider/io/jimp-image-reader.class.ts index c360106f..3f27102c 100644 --- a/core/nut.js/lib/provider/io/jimp-image-reader.class.ts +++ b/core/nut.js/lib/provider/io/jimp-image-reader.class.ts @@ -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 { + load = (parameters: string): Promise => { return new Promise((resolve, reject) => { Jimp.read(parameters) .then((jimpImage) => { diff --git a/core/nut.js/lib/provider/log/console-log-provider.class.ts b/core/nut.js/lib/provider/log/console-log-provider.class.ts index 157c1014..cf9cf5ee 100644 --- a/core/nut.js/lib/provider/log/console-log-provider.class.ts +++ b/core/nut.js/lib/provider/log/console-log-provider.class.ts @@ -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 = `${ @@ -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); } } diff --git a/core/nut.js/lib/provider/provider-registry.class.ts b/core/nut.js/lib/provider/provider-registry.class.ts index 4e44b34b..0313807d 100644 --- a/core/nut.js/lib/provider/provider-registry.class.ts +++ b/core/nut.js/lib/provider/provider-registry.class.ts @@ -48,7 +48,7 @@ class DefaultProviderRegistry implements ProviderRegistry { private _colorFinder?: ColorFinderInterface; private _windowElementInspector?: ElementInspectionProviderInterface; - hasClipboard(): boolean { + hasClipboard = (): boolean => { return this._clipboard != null; } @@ -66,7 +66,7 @@ class DefaultProviderRegistry implements ProviderRegistry { this.getLogProvider().trace("Registered new clipboard provider", value); }; - hasImageFinder(): boolean { + hasImageFinder = (): boolean => { return this._imageFinder != null; } @@ -84,7 +84,7 @@ class DefaultProviderRegistry implements ProviderRegistry { this.getLogProvider().trace("Registered new image finder", value); }; - hasKeyboard(): boolean { + hasKeyboard = (): boolean => { return this._keyboard != null; } @@ -102,7 +102,7 @@ class DefaultProviderRegistry implements ProviderRegistry { this.getLogProvider().trace("Registered new keyboard provider", value); }; - hasMouse(): boolean { + hasMouse = (): boolean => { return this._mouse != null; } @@ -120,7 +120,7 @@ class DefaultProviderRegistry implements ProviderRegistry { this.getLogProvider().trace("Registered new mouse provider", value); }; - hasScreen(): boolean { + hasScreen = (): boolean => { return this._screen != null; } @@ -138,7 +138,7 @@ class DefaultProviderRegistry implements ProviderRegistry { this.getLogProvider().trace("Registered new screen provider", value); }; - hasWindow(): boolean { + hasWindow = (): boolean => { return this._window != null; } @@ -156,7 +156,7 @@ class DefaultProviderRegistry implements ProviderRegistry { this.getLogProvider().trace("Registered new window provider", value); }; - hasTextFinder(): boolean { + hasTextFinder = (): boolean => { return this._textFinder != null; } @@ -174,7 +174,7 @@ class DefaultProviderRegistry implements ProviderRegistry { this.getLogProvider().trace("Registered new TextFinder provider", value); }; - hasWindowFinder(): boolean { + hasWindowFinder = (): boolean => { return this._windowFinder != null; } @@ -206,7 +206,7 @@ class DefaultProviderRegistry implements ProviderRegistry { this.getLogProvider().trace("Registered new WindowElementInspector provider", value); }; - hasImageReader(): boolean { + hasImageReader = (): boolean => { return this._imageReader != null; } @@ -224,7 +224,7 @@ class DefaultProviderRegistry implements ProviderRegistry { this.getLogProvider().trace("Registered new image reader", value); }; - hasImageWriter(): boolean { + hasImageWriter = (): boolean => { return this._imageWriter != null; } @@ -242,7 +242,7 @@ class DefaultProviderRegistry implements ProviderRegistry { this.getLogProvider().trace("Registered new image writer", value); }; - hasImageProcessor(): boolean { + hasImageProcessor = (): boolean => { return this._imageProcessor != null; } @@ -260,7 +260,7 @@ class DefaultProviderRegistry implements ProviderRegistry { this.getLogProvider().trace("Registered new image processor", value); }; - hasLogProvider(): boolean { + hasLogProvider = (): boolean => { return this._logProvider != null; } @@ -278,7 +278,7 @@ class DefaultProviderRegistry implements ProviderRegistry { this.getLogProvider().trace("Registered new log provider", value); }; - hasColorFinder(): boolean { + hasColorFinder = (): boolean => { return this._colorFinder != null; } diff --git a/core/nut.js/lib/screen.class.ts b/core/nut.js/lib/screen.class.ts index 6b3c71d0..5a138c06 100644 --- a/core/nut.js/lib/screen.class.ts +++ b/core/nut.js/lib/screen.class.ts @@ -143,7 +143,7 @@ export class ScreenClass { * This refers to the hardware resolution. * Screens with higher pixel density (e.g. retina displays in MacBooks) might have a higher width in in actual pixels */ - public width() { + public width = () => { this.providerRegistry.getLogProvider().debug(`Fetching screen width`); return this.providerRegistry.getScreen().screenWidth(); } @@ -153,7 +153,7 @@ export class ScreenClass { * This refers to the hardware resolution. * Screens with higher pixel density (e.g. retina displays in MacBooks) might have a higher height in in actual pixels */ - public height() { + public height = () => { this.providerRegistry.getLogProvider().debug(`Fetching screen height`); return this.providerRegistry.getScreen().screenHeight(); } @@ -163,23 +163,25 @@ export class ScreenClass { * @param searchInput A {@link FindInput} instance * @param params {@link OptionalSearchParameters} which are used to fine tune search region and / or match confidence */ - public async find( + public find = this._find.bind(this); + + private _find( searchInput: RegionResultFindInput | Promise, params?: OptionalSearchParameters ): Promise; - public async find( + private async _find( searchInput: PointResultFindInput | Promise, params?: OptionalSearchParameters ): Promise; - public async find( + private async _find( searchInput: WindowResultFindInput | Promise, params?: OptionalSearchParameters ): Promise; - public async find( + private async _find( searchInput: FindInput | Promise, params?: OptionalSearchParameters ): Promise; - public async find( + private async _find ( searchInput: FindInput | Promise, params?: OptionalSearchParameters ): Promise { @@ -314,23 +316,25 @@ export class ScreenClass { * @param searchInput A {@link FindInput} instance to search for * @param params {@link OptionalSearchParameters} which are used to fine tune search region and / or match confidence */ - public async findAll( + public findAll = this._findAll.bind(this); + + private async _findAll( searchInput: RegionResultFindInput | Promise, params?: OptionalSearchParameters ): Promise; - public async findAll( + private async _findAll( searchInput: PointResultFindInput | Promise, params?: OptionalSearchParameters ): Promise; - public async findAll( + private async _findAll( searchInput: WindowResultFindInput | Promise, params?: OptionalSearchParameters ): Promise; - public async findAll( + private async _findAll( searchInput: FindInput | Promise, params?: OptionalSearchParameters ): Promise; - public async findAll( + private async _findAll ( searchInput: FindInput | Promise, params?: OptionalSearchParameters ): Promise { @@ -481,9 +485,9 @@ export class ScreenClass { * {@link highlight} highlights a screen {@link Region} for a certain duration by overlaying it with an opaque highlight window * @param regionToHighlight The {@link Region} to highlight */ - public async highlight( + public highlight = async ( regionToHighlight: Region | Promise - ): Promise { + ): Promise => { const highlightRegion = await regionToHighlight; if (!isRegion(highlightRegion)) { const e = Error( @@ -518,25 +522,27 @@ export class ScreenClass { * @param updateInterval Update interval in milliseconds to retry search * @param params {@link OptionalSearchParameters} which are used to fine tune search region and / or match confidence */ - public async waitFor( + public waitFor = this._waitFor.bind(this); + + private async _waitFor( searchInput: RegionResultFindInput | Promise, timeoutMs?: number, updateInterval?: number, params?: OptionalSearchParameters ): Promise; - public async waitFor( + private async _waitFor( searchInput: PointResultFindInput | Promise, timeoutMs?: number, updateInterval?: number, params?: OptionalSearchParameters ): Promise; - public async waitFor( + private async _waitFor( searchInput: WindowResultFindInput | Promise, timeoutMs?: number, updateInterval?: number, params?: OptionalSearchParameters ): Promise; - public async waitFor( + private async _waitFor ( searchInput: FindInput | Promise, timeoutMs?: number, updateInterval?: number, @@ -573,16 +579,18 @@ export class ScreenClass { * @param searchInput to trigger the callback on * @param callback The {@link FindHookCallback} function to trigger */ - public on(searchInput: WindowResultFindInput, callback: WindowCallback): void; - public on( + public on = this._on.bind(this); + + private _on(searchInput: WindowResultFindInput, callback: WindowCallback): void; + private _on( searchInput: PointResultFindInput, callback: MatchResultCallback ): void; - public on( + private _on( searchInput: RegionResultFindInput, callback: MatchResultCallback ): void; - public on(searchInput: FindInput, callback: FindHookCallback): void { + private _on(searchInput: FindInput, callback: FindHookCallback): void { this.validateSearchInput("on", searchInput); const existingHooks = this.findHooks.get(searchInput) ?? []; @@ -604,13 +612,13 @@ export class ScreenClass { * @param fileNamePrefix Filename prefix for the generated screenshot (Default: empty) * @param fileNamePostfix Filename postfix for the generated screenshot (Default: empty) */ - public async capture( + public capture = async ( fileName: string, fileFormat: FileType = FileType.PNG, filePath: string = cwd(), fileNamePrefix: string = "", fileNamePostfix: string = "" - ): Promise { + ): Promise => { const currentScreen = await this.providerRegistry.getScreen().grabScreen(); if (!isImage(currentScreen)) { const e = new Error( @@ -639,7 +647,7 @@ export class ScreenClass { /** * {@link grab} grabs screen content of a systems main display */ - public async grab(): Promise { + public grab = async (): Promise => { const currentScreen = await this.providerRegistry.getScreen().grabScreen(); this.providerRegistry .getLogProvider() @@ -658,14 +666,14 @@ export class ScreenClass { * @param fileNamePrefix Filename prefix for the generated screenshot (Default: empty) * @param fileNamePostfix Filename postfix for the generated screenshot (Default: empty) */ - public async captureRegion( + public captureRegion = async ( fileName: string, regionToCapture: Region | Promise, fileFormat: FileType = FileType.PNG, filePath: string = cwd(), fileNamePrefix: string = "", fileNamePostfix: string = "" - ): Promise { + ): Promise => { const targetRegion = await regionToCapture; if (!isRegion(targetRegion)) { const e = new Error( @@ -705,9 +713,9 @@ export class ScreenClass { * {@link grabRegion} grabs screen content of a region on the systems main display * @param regionToGrab The screen region to grab */ - public async grabRegion( + public grabRegion = async ( regionToGrab: Region | Promise - ): Promise { + ): Promise => { const targetRegion = await regionToGrab; if (!isRegion(targetRegion)) { const e = new Error( @@ -731,7 +739,7 @@ export class ScreenClass { * {@link colorAt} returns RGBA color values for a certain pixel at {@link Point} p * @param point Location to query color information from */ - public async colorAt(point: Point | Promise) { + public colorAt = async (point: Point | Promise) => { const screenContent = await this.providerRegistry.getScreen().grabScreen(); const inputPoint = await point; if (!isPoint(inputPoint)) { @@ -763,14 +771,14 @@ export class ScreenClass { return color; } - private async saveImage( + private saveImage = async ( image: Image, fileName: string, fileFormat: FileType, filePath: string, fileNamePrefix: string, fileNamePostfix: string - ) { + ) => { const outputPath = generateOutputPath(fileName, { path: filePath, postfix: fileNamePostfix, @@ -787,9 +795,9 @@ export class ScreenClass { return outputPath; } - private async getFindParameters( + private getFindParameters = async ( params?: OptionalSearchParameters - ) { + ) => { const minMatch = params?.confidence; const screenSize = await this.providerRegistry.getScreen().screenSize(); const searchRegion = (await params?.searchRegion) ?? screenSize; @@ -813,14 +821,16 @@ export class ScreenClass { return findParameters; } - private getHooksForInput(input: WindowResultFindInput): WindowCallback[]; - private getHooksForInput( + private getHooksForInput = this._getHooksForInput.bind(this); + + private _getHooksForInput(input: WindowResultFindInput): WindowCallback[]; + private _getHooksForInput( input: RegionResultFindInput ): MatchResultCallback[]; - private getHooksForInput( + private _getHooksForInput( input: PointResultFindInput ): MatchResultCallback[]; - private getHooksForInput( + private _getHooksForInput( input: FindInput ): | MatchResultCallback[] @@ -836,7 +846,7 @@ export class ScreenClass { return []; } - private logNeedleType(needle: Image | WordQuery | LineQuery | ColorQuery) { + private logNeedleType = (needle: Image | WordQuery | LineQuery | ColorQuery) => { if (isImage(needle)) { this.providerRegistry.getLogProvider().debug(`Running an image search`); } else if (isTextQuery(needle)) { @@ -844,7 +854,7 @@ export class ScreenClass { } } - private validateSearchInput( + private validateSearchInput = ( functionName: string, needle: | Image @@ -853,7 +863,7 @@ export class ScreenClass { | WindowResultFindInput | PointResultFindInput | Promise - ) { + ) => { if ( !isImage(needle) && !isTextQuery(needle) && diff --git a/core/nut.js/lib/window.class.ts b/core/nut.js/lib/window.class.ts index 2385cb1d..55b1f384 100644 --- a/core/nut.js/lib/window.class.ts +++ b/core/nut.js/lib/window.class.ts @@ -32,7 +32,7 @@ export class Window implements WindowInterface { return this.getTitle(); } - async getTitle(): Promise { + getTitle = async (): Promise => { return this.providerRegistry.getWindow().getWindowTitle(this.windowHandle); } @@ -40,7 +40,7 @@ export class Window implements WindowInterface { return this.getRegion(); } - async getRegion(): Promise { + getRegion = async (): Promise => { const region = await this.providerRegistry.getWindow().getWindowRegion(this.windowHandle); const mainWindowRegion = await this.providerRegistry.getScreen().screenSize(); if (region.left < 0) { @@ -70,31 +70,31 @@ export class Window implements WindowInterface { return region; } - async move(newOrigin: Point) { + move = async (newOrigin: Point) => { return this.providerRegistry .getWindow() .moveWindow(this.windowHandle, newOrigin); } - async resize(newSize: Size) { + resize = async (newSize: Size) => { return this.providerRegistry .getWindow() .resizeWindow(this.windowHandle, newSize); } - async focus() { + focus = async () => { return this.providerRegistry.getWindow().focusWindow(this.windowHandle); } - async minimize() { + minimize = async () => { return this.providerRegistry.getWindow().minimizeWindow(this.windowHandle); } - async restore() { + restore = async () => { return this.providerRegistry.getWindow().restoreWindow(this.windowHandle); } - async getElements(maxElements?: number): Promise { + getElements = async (maxElements?: number): Promise => { return this.providerRegistry.getWindowElementInspector().getElements(this.windowHandle, maxElements); } @@ -102,9 +102,9 @@ export class Window implements WindowInterface { * {@link find} will search for a single occurrence of a given search input in the current window. * @param searchInput A {@link WindowedFindInput} instance */ - public async find( + public find = async ( searchInput: WindowElementResultFindInput | Promise - ): Promise { + ): Promise => { const needle = await searchInput; this.providerRegistry.getLogProvider().info(`Searching for ${needle} in window ${this.windowHandle}`); @@ -140,9 +140,9 @@ export class Window implements WindowInterface { * {@link findAll} will search for multiple occurrence of a given search input in the current window. * @param searchInput A {@link WindowedFindInput} instance */ - public async findAll( + public findAll = async ( searchInput: WindowElementResultFindInput | Promise - ): Promise { + ): Promise => { const needle = await searchInput; this.providerRegistry.getLogProvider().info(`Searching for ${needle} in window ${this.windowHandle}`); @@ -183,12 +183,12 @@ export class Window implements WindowInterface { * @param updateInterval Update interval in milliseconds to retry search * @param params {@link OptionalSearchParameters} which are used to fine tune search */ - public async waitFor( + public waitFor = async ( searchInput: WindowElementQuery | Promise, timeoutMs?: number, updateInterval?: number, params?: OptionalSearchParameters - ): Promise { + ): Promise => { const needle = await searchInput; const timeoutValue = timeoutMs ?? 5000; @@ -218,7 +218,7 @@ export class Window implements WindowInterface { * @param searchInput to trigger the callback on * @param callback The {@link FindHookCallback} function to trigger */ - public on(searchInput: WindowElementQuery, callback: WindowElementCallback): void { + public on = (searchInput: WindowElementQuery, callback: WindowElementCallback): void => { const existingHooks = this.getHooksForInput(searchInput); this.findHooks.set(searchInput, [...existingHooks, callback]); this.providerRegistry @@ -230,9 +230,9 @@ export class Window implements WindowInterface { ); } - private getHooksForInput( + private getHooksForInput = ( input: WindowElementQuery - ): WindowElementCallback[] { + ): WindowElementCallback[] => { return this.findHooks.get(input) ?? []; } } diff --git a/core/shared/lib/objects/image.class.ts b/core/shared/lib/objects/image.class.ts index 467b5643..62e4f24d 100644 --- a/core/shared/lib/objects/image.class.ts +++ b/core/shared/lib/objects/image.class.ts @@ -46,7 +46,7 @@ export class Image { /** * {@link toRGB} converts an {@link Image} from BGR color mode (default within nut.js) to RGB */ - public async toRGB(): Promise { + public toRGB = async (): Promise => { if (this.colorMode === ColorMode.RGB) { return this; } @@ -67,7 +67,7 @@ export class Image { /** * {@link toBGR} converts an {@link Image} from RGB color mode to RGB */ - public async toBGR(): Promise { + public toBGR = async (): Promise => { if (this.colorMode === ColorMode.BGR) { return this; } diff --git a/core/shared/lib/objects/point.class.ts b/core/shared/lib/objects/point.class.ts index 6b45b6b8..c6dd70f2 100644 --- a/core/shared/lib/objects/point.class.ts +++ b/core/shared/lib/objects/point.class.ts @@ -1,7 +1,7 @@ export class Point { constructor(public x: number, public y: number) {} - public toString() { + public toString = () => { return `(${this.x}, ${this.y})`; } } diff --git a/core/shared/lib/objects/region.class.ts b/core/shared/lib/objects/region.class.ts index edf154c9..209dec89 100644 --- a/core/shared/lib/objects/region.class.ts +++ b/core/shared/lib/objects/region.class.ts @@ -6,11 +6,11 @@ export class Region { public height: number ) {} - public area() { + public area = () => { return this.width * this.height; } - public toString() { + public toString = () => { return `(${this.left}, ${this.top}, ${this.width}, ${this.height})`; } } diff --git a/core/shared/lib/objects/rgba.class.ts b/core/shared/lib/objects/rgba.class.ts index 8b46c173..d46a8bd5 100644 --- a/core/shared/lib/objects/rgba.class.ts +++ b/core/shared/lib/objects/rgba.class.ts @@ -7,11 +7,11 @@ export class RGBA { ) { } - public toString(): string { + public toString = (): string => { return `rgba(${this.R},${this.G},${this.B},${this.A})`; } - public toHex(): string { + public toHex = (): string => { return `#${this.R.toString(16).padStart(2, "0")}${this.G.toString( 16 ).padStart(2, "0")}${this.B.toString(16).padStart(2, "0")}${this.A.toString( diff --git a/core/shared/lib/objects/size.class.ts b/core/shared/lib/objects/size.class.ts index 3e75f0a8..18626b86 100644 --- a/core/shared/lib/objects/size.class.ts +++ b/core/shared/lib/objects/size.class.ts @@ -4,11 +4,11 @@ export class Size { public height: number, ) {} - public area() { + public area = () => { return this.width * this.height; } - public toString() { + public toString = () => { return `(${this.width}x${this.height})`; } } diff --git a/providers/libnut/lib/libnut-keyboard.class.ts b/providers/libnut/lib/libnut-keyboard.class.ts index b396f6c5..5ac96753 100644 --- a/providers/libnut/lib/libnut-keyboard.class.ts +++ b/providers/libnut/lib/libnut-keyboard.class.ts @@ -150,21 +150,21 @@ export default class KeyboardAction implements KeyboardProviderInterface { [Key.AudioRandom, "audio_random"] ]); - public static keyLookup(key: Key): any { + public static keyLookup = (key: Key): any => { return this.KeyLookupMap.get(key); } - private static mapModifierKeys(...keys: Key[]): string[] { + private static mapModifierKeys = (...keys: Key[]): string[] => { return keys .map((modifier) => KeyboardAction.keyLookup(modifier)) .filter((modifierKey) => modifierKey != null && modifierKey.length > 1); } - private static key( + private static key = ( key: Key, event: "up" | "down", ...modifiers: Key[] - ): Promise { + ): Promise => { return new Promise((resolve, reject) => { try { const nativeKey = KeyboardAction.keyLookup(key); @@ -182,7 +182,7 @@ export default class KeyboardAction implements KeyboardProviderInterface { constructor() { } - public type(input: string): Promise { + public type = (input: string): Promise => { return new Promise((resolve, reject) => { try { libnut.typeString(input); @@ -193,7 +193,7 @@ export default class KeyboardAction implements KeyboardProviderInterface { }); } - public click(...keys: Key[]): Promise { + public click = (...keys: Key[]): Promise => { return new Promise((resolve, reject) => { try { keys.reverse(); @@ -210,7 +210,7 @@ export default class KeyboardAction implements KeyboardProviderInterface { }); } - public pressKey(...keys: Key[]): Promise { + public pressKey = (...keys: Key[]): Promise => { return new Promise(async (resolve, reject) => { try { keys.reverse(); @@ -223,7 +223,7 @@ export default class KeyboardAction implements KeyboardProviderInterface { }); } - public releaseKey(...keys: Key[]): Promise { + public releaseKey = (...keys: Key[]): Promise => { return new Promise(async (resolve, reject) => { try { keys.reverse(); @@ -236,7 +236,7 @@ export default class KeyboardAction implements KeyboardProviderInterface { }); } - public setKeyboardDelay(delay: number): void { + public setKeyboardDelay = (delay: number): void => { libnut.setKeyboardDelay(delay); } } diff --git a/providers/libnut/lib/libnut-mouse.class.ts b/providers/libnut/lib/libnut-mouse.class.ts index 374485a9..c726d161 100644 --- a/providers/libnut/lib/libnut-mouse.class.ts +++ b/providers/libnut/lib/libnut-mouse.class.ts @@ -3,7 +3,7 @@ import { Button, Point } from "@nut-tree/shared"; import { MouseProviderInterface } from "@nut-tree/provider-interfaces"; export default class MouseAction implements MouseProviderInterface { - public static buttonLookup(btn: Button): any { + public static buttonLookup = (btn: Button): any => { return this.ButtonLookupMap.get(btn); } @@ -18,11 +18,11 @@ export default class MouseAction implements MouseProviderInterface { constructor() { } - public setMouseDelay(delay: number): void { + public setMouseDelay = (delay: number): void => { libnut.setMouseDelay(delay); } - public setMousePosition(p: Point): Promise { + public setMousePosition = (p: Point): Promise => { return new Promise((resolve, reject) => { try { libnut.moveMouse(p.x, p.y); @@ -33,7 +33,7 @@ export default class MouseAction implements MouseProviderInterface { }); } - public currentMousePosition(): Promise { + public currentMousePosition = (): Promise => { return new Promise((resolve, reject) => { try { const position = libnut.getMousePos(); @@ -44,7 +44,7 @@ export default class MouseAction implements MouseProviderInterface { }); } - public click(btn: Button): Promise { + public click = (btn: Button): Promise => { return new Promise((resolve, reject) => { try { libnut.mouseClick(MouseAction.buttonLookup(btn)); @@ -55,7 +55,7 @@ export default class MouseAction implements MouseProviderInterface { }); } - public doubleClick(btn: Button): Promise { + public doubleClick = (btn: Button): Promise => { return new Promise((resolve, reject) => { try { libnut.mouseClick(MouseAction.buttonLookup(btn), true); @@ -66,19 +66,19 @@ export default class MouseAction implements MouseProviderInterface { }); } - public leftClick(): Promise { + public leftClick = (): Promise => { return this.click(Button.LEFT); } - public rightClick(): Promise { + public rightClick = (): Promise => { return this.click(Button.RIGHT); } - public middleClick(): Promise { + public middleClick = (): Promise => { return this.click(Button.MIDDLE); } - public pressButton(btn: Button): Promise { + public pressButton = (btn: Button): Promise => { return new Promise((resolve, reject) => { try { libnut.mouseToggle("down", MouseAction.buttonLookup(btn)); @@ -89,7 +89,7 @@ export default class MouseAction implements MouseProviderInterface { }); } - public releaseButton(btn: Button): Promise { + public releaseButton = (btn: Button): Promise => { return new Promise((resolve, reject) => { try { libnut.mouseToggle("up", MouseAction.buttonLookup(btn)); @@ -100,7 +100,7 @@ export default class MouseAction implements MouseProviderInterface { }); } - public scrollUp(amount: number): Promise { + public scrollUp = (amount: number): Promise => { return new Promise((resolve, reject) => { try { libnut.scrollMouse(0, amount); @@ -111,7 +111,7 @@ export default class MouseAction implements MouseProviderInterface { }); } - public scrollDown(amount: number): Promise { + public scrollDown = (amount: number): Promise => { return new Promise((resolve, reject) => { try { libnut.scrollMouse(0, -amount); @@ -122,7 +122,7 @@ export default class MouseAction implements MouseProviderInterface { }); } - public scrollLeft(amount: number): Promise { + public scrollLeft = (amount: number): Promise => { return new Promise((resolve, reject) => { try { libnut.scrollMouse(-amount, 0); @@ -133,7 +133,7 @@ export default class MouseAction implements MouseProviderInterface { }); } - public scrollRight(amount: number): Promise { + public scrollRight = (amount: number): Promise => { return new Promise((resolve, reject) => { try { libnut.scrollMouse(amount, 0);