Skip to content

Commit

Permalink
Feature/533/optional default providers (#534)
Browse files Browse the repository at this point in the history
* (#533) Move clipboard provider into dedicated package

* (#533) Extend provider registry with checks for providers, disable loading of default clipboard provider via env var

* (#533) Add safety checks when accessing providers to avoid errors before being able to load alternatives

* (#533) Extend constants and provider registry to disable loading of other native providers as well.
Preparing for further refactorings

* (#533) Update sonar action
  • Loading branch information
s1hofmann authored Sep 23, 2023
1 parent 722150e commit 6a76103
Show file tree
Hide file tree
Showing 12 changed files with 188 additions and 83 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
npm run coverage:merge
npm run coverage:merge-report
- name: Send results to SonarCloud
uses: SonarSource/sonarcloud-github-action@v1.6
uses: SonarSource/sonarcloud-github-action@v2.0.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
Expand Down
12 changes: 12 additions & 0 deletions lib/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const DISABLE_DEFAULT_PROVIDERS_ENV_VAR =
"NUT_JS_DISABLE_DEFAULT_PROVIDERS";
export const DISABLE_DEFAULT_CLIPBOARD_PROVIDER_ENV_VAR =
"NUT_JS_DISABLE_DEFAULT_CLIPBOARD_PROVIDER";
export const DISABLE_DEFAULT_KEYBOARD_PROVIDER_ENV_VAR =
"NUT_JS_DISABLE_DEFAULT_KEYBOARD_PROVIDER";
export const DISABLE_DEFAULT_MOUSE_PROVIDER_ENV_VAR =
"NUT_JS_DISABLE_DEFAULT_MOUSE_PROVIDER";
export const DISABLE_DEFAULT_SCREEN_PROVIDER_ENV_VAR =
"NUT_JS_DISABLE_DEFAULT_SCREEN_PROVIDER";
export const DISABLE_DEFAULT_WINDOW_PROVIDER_ENV_VAR =
"NUT_JS_DISABLE_DEFAULT_WINDOW_PROVIDER";
1 change: 1 addition & 0 deletions lib/expect/jest.matcher.function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ declare global {
interface Matchers<R> {
toBeAt: (position: Point) => ReturnType<typeof toBeAt>;
toBeIn: (region: Region) => ReturnType<typeof toBeIn>;
// @ts-ignore
toShow: (
needle: FindInput,
confidence?: number
Expand Down
3 changes: 3 additions & 0 deletions lib/keyboard.class.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ const providerRegistryMock = mockPartial<ProviderRegistry>({
setKeyboardDelay: jest.fn(),
});
},
hasKeyboard(): boolean {
return true;
},
});

describe("Keyboard", () => {
Expand Down
8 changes: 5 additions & 3 deletions lib/keyboard.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ export class KeyboardClass {
* @param providerRegistry
*/
constructor(private providerRegistry: ProviderRegistry) {
this.providerRegistry
.getKeyboard()
.setKeyboardDelay(this.config.autoDelayMs);
if (this.providerRegistry.hasKeyboard()) {
this.providerRegistry
.getKeyboard()
.setKeyboardDelay(this.config.autoDelayMs);
}
}

/**
Expand Down
3 changes: 3 additions & 0 deletions lib/mouse.class.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ const providerRegistryMock = mockPartial<ProviderRegistry>({
setMouseDelay: jest.fn(),
});
},
hasMouse(): boolean {
return true;
},
});

describe("Mouse class", () => {
Expand Down
4 changes: 3 additions & 1 deletion lib/mouse.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ export class MouseClass {
* @param providerRegistry
*/
constructor(private providerRegistry: ProviderRegistry) {
this.providerRegistry.getMouse().setMouseDelay(0);
if (this.providerRegistry.hasMouse()) {
this.providerRegistry.getMouse().setMouseDelay(0);
}
}

/**
Expand Down
35 changes: 0 additions & 35 deletions lib/provider/native/clipboardy-clipboard.class.spec.ts

This file was deleted.

36 changes: 0 additions & 36 deletions lib/provider/native/clipboardy-clipboard.class.ts

This file was deleted.

Loading

0 comments on commit 6a76103

Please sign in to comment.