Skip to content

Commit 6a76103

Browse files
authored
Feature/533/optional default providers (#534)
* (#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
1 parent 722150e commit 6a76103

12 files changed

Lines changed: 188 additions & 83 deletions

‎.github/workflows/ci.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
npm run coverage:merge
4747
npm run coverage:merge-report
4848
- name: Send results to SonarCloud
49-
uses: SonarSource/sonarcloud-github-action@v1.6
49+
uses: SonarSource/sonarcloud-github-action@v2.0.2
5050
env:
5151
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5252
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

‎lib/constants.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export const DISABLE_DEFAULT_PROVIDERS_ENV_VAR =
2+
"NUT_JS_DISABLE_DEFAULT_PROVIDERS";
3+
export const DISABLE_DEFAULT_CLIPBOARD_PROVIDER_ENV_VAR =
4+
"NUT_JS_DISABLE_DEFAULT_CLIPBOARD_PROVIDER";
5+
export const DISABLE_DEFAULT_KEYBOARD_PROVIDER_ENV_VAR =
6+
"NUT_JS_DISABLE_DEFAULT_KEYBOARD_PROVIDER";
7+
export const DISABLE_DEFAULT_MOUSE_PROVIDER_ENV_VAR =
8+
"NUT_JS_DISABLE_DEFAULT_MOUSE_PROVIDER";
9+
export const DISABLE_DEFAULT_SCREEN_PROVIDER_ENV_VAR =
10+
"NUT_JS_DISABLE_DEFAULT_SCREEN_PROVIDER";
11+
export const DISABLE_DEFAULT_WINDOW_PROVIDER_ENV_VAR =
12+
"NUT_JS_DISABLE_DEFAULT_WINDOW_PROVIDER";

‎lib/expect/jest.matcher.function.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ declare global {
1010
interface Matchers<R> {
1111
toBeAt: (position: Point) => ReturnType<typeof toBeAt>;
1212
toBeIn: (region: Region) => ReturnType<typeof toBeIn>;
13+
// @ts-ignore
1314
toShow: (
1415
needle: FindInput,
1516
confidence?: number

‎lib/keyboard.class.spec.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ const providerRegistryMock = mockPartial<ProviderRegistry>({
2020
setKeyboardDelay: jest.fn(),
2121
});
2222
},
23+
hasKeyboard(): boolean {
24+
return true;
25+
},
2326
});
2427

2528
describe("Keyboard", () => {

‎lib/keyboard.class.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ export class KeyboardClass {
3434
* @param providerRegistry
3535
*/
3636
constructor(private providerRegistry: ProviderRegistry) {
37-
this.providerRegistry
38-
.getKeyboard()
39-
.setKeyboardDelay(this.config.autoDelayMs);
37+
if (this.providerRegistry.hasKeyboard()) {
38+
this.providerRegistry
39+
.getKeyboard()
40+
.setKeyboardDelay(this.config.autoDelayMs);
41+
}
4042
}
4143

4244
/**

‎lib/mouse.class.spec.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ const providerRegistryMock = mockPartial<ProviderRegistry>({
1919
setMouseDelay: jest.fn(),
2020
});
2121
},
22+
hasMouse(): boolean {
23+
return true;
24+
},
2225
});
2326

2427
describe("Mouse class", () => {

‎lib/mouse.class.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ export class MouseClass {
3737
* @param providerRegistry
3838
*/
3939
constructor(private providerRegistry: ProviderRegistry) {
40-
this.providerRegistry.getMouse().setMouseDelay(0);
40+
if (this.providerRegistry.hasMouse()) {
41+
this.providerRegistry.getMouse().setMouseDelay(0);
42+
}
4143
}
4244

4345
/**

‎lib/provider/native/clipboardy-clipboard.class.spec.ts‎

Lines changed: 0 additions & 35 deletions
This file was deleted.

‎lib/provider/native/clipboardy-clipboard.class.ts‎

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)