Skip to content

Commit

Permalink
Create NoopBiometricsService instead of method guards
Browse files Browse the repository at this point in the history
  • Loading branch information
djsmith85 committed Jan 24, 2024
1 parent cb85919 commit 9997306
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
34 changes: 34 additions & 0 deletions apps/desktop/src/platform/main/biometric/biometric.noop.main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { OsBiometricService } from "./biometrics.service.abstraction";

export default class NoopBiometricsService implements OsBiometricService {
constructor() {}

async init() {}

Check warning on line 6 in apps/desktop/src/platform/main/biometric/biometric.noop.main.ts

View check run for this annotation

Codecov / codecov/patch

apps/desktop/src/platform/main/biometric/biometric.noop.main.ts#L6

Added line #L6 was not covered by tests

async osSupportsBiometric(): Promise<boolean> {
return false;

Check warning on line 9 in apps/desktop/src/platform/main/biometric/biometric.noop.main.ts

View check run for this annotation

Codecov / codecov/patch

apps/desktop/src/platform/main/biometric/biometric.noop.main.ts#L9

Added line #L9 was not covered by tests
}

async getBiometricKey(
service: string,
storageKey: string,
clientKeyHalfB64: string,
): Promise<string | null> {
return null;

Check warning on line 17 in apps/desktop/src/platform/main/biometric/biometric.noop.main.ts

View check run for this annotation

Codecov / codecov/patch

apps/desktop/src/platform/main/biometric/biometric.noop.main.ts#L17

Added line #L17 was not covered by tests
}

async setBiometricKey(
service: string,
storageKey: string,
value: string,
clientKeyPartB64: string | undefined,
): Promise<void> {
return;

Check warning on line 26 in apps/desktop/src/platform/main/biometric/biometric.noop.main.ts

View check run for this annotation

Codecov / codecov/patch

apps/desktop/src/platform/main/biometric/biometric.noop.main.ts#L26

Added line #L26 was not covered by tests
}

async deleteBiometricKey(service: string, key: string): Promise<void> {}

Check warning on line 29 in apps/desktop/src/platform/main/biometric/biometric.noop.main.ts

View check run for this annotation

Codecov / codecov/patch

apps/desktop/src/platform/main/biometric/biometric.noop.main.ts#L29

Added line #L29 was not covered by tests

async authenticateBiometric(): Promise<boolean> {
throw new Error("Not supported on this platform");

Check warning on line 32 in apps/desktop/src/platform/main/biometric/biometric.noop.main.ts

View check run for this annotation

Codecov / codecov/patch

apps/desktop/src/platform/main/biometric/biometric.noop.main.ts#L32

Added line #L32 was not covered by tests
}
}
15 changes: 9 additions & 6 deletions apps/desktop/src/platform/main/biometric/biometrics.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export class BiometricsService implements BiometricsServiceAbstraction {
this.loadWindowsHelloService();
} else if (platform === "darwin") {
this.loadMacOSService();
} else {
this.loadNoopBiometricsService();
}
}

Expand All @@ -47,16 +49,17 @@ export class BiometricsService implements BiometricsServiceAbstraction {
this.platformSpecificService = new BiometricDarwinMain(this.i18nService, this.stateService);
}

private loadNoopBiometricsService() {
// eslint-disable-next-line
const NoopBiometricsService = require("./biometric.noop.main").default;
this.platformSpecificService = new NoopBiometricsService();
}

async init() {
if (this.platformSpecificService) {
return await this.platformSpecificService.init();
}
return await this.platformSpecificService.init();
}

async osSupportsBiometric() {
if (!this.platformSpecificService) {
return false;
}
return await this.platformSpecificService.osSupportsBiometric();
}

Expand Down

0 comments on commit 9997306

Please sign in to comment.