1
0
mirror of https://github.com/bitwarden/browser synced 2026-01-04 01:23:57 +00:00

[PM-3683] Remove ipcRenderer from electron-platform-utils (#6679)

* [PM-3683] Remove ipcRenderer from electron-platform-utils

* FIx review comments

* Formatting

* Use isNullOrWhitespace
This commit is contained in:
Daniel García
2023-11-01 18:34:36 +01:00
committed by GitHub
parent a1729c97df
commit c592bcba80
9 changed files with 112 additions and 46 deletions

View File

@@ -4,7 +4,7 @@ import { BiometricKey } from "@bitwarden/common/auth/types/biometric-key";
import { ConsoleLogService } from "@bitwarden/common/platform/services/console-log.service";
import { passwords } from "@bitwarden/desktop-native";
import { BiometricMessage, BiometricStorageAction } from "../../types/biometric-message";
import { BiometricMessage, BiometricAction } from "../../types/biometric-message";
import { BiometricsServiceAbstraction } from "./biometric/index";
@@ -66,7 +66,7 @@ export class DesktopCredentialStorageListener {
}
switch (message.action) {
case BiometricStorageAction.EnabledForUser:
case BiometricAction.EnabledForUser:
if (!message.key || !message.userId) {
break;
}
@@ -76,7 +76,7 @@ export class DesktopCredentialStorageListener {
userId: message.userId,
});
break;
case BiometricStorageAction.OsSupported:
case BiometricAction.OsSupported:
val = await this.biometricService.osSupportsBiometric();
break;
default:

View File

@@ -2,8 +2,11 @@ import { ipcRenderer } from "electron";
import { DeviceType, ThemeType } from "@bitwarden/common/enums";
import { BiometricMessage, BiometricAction } from "../types/biometric-message";
import { isDev, isWindowsStore } from "../utils";
import { ClipboardWriteMessage } from "./types/clipboard";
const storage = {
get: <T>(key: string): Promise<T> => ipcRenderer.invoke("storageService", { action: "get", key }),
has: (key: string): Promise<boolean> =>
@@ -25,6 +28,22 @@ const passwords = {
ipcRenderer.invoke("keytar", { action: "deletePassword", key, keySuffix }),
};
const biometric = {
osSupported: (): Promise<boolean> =>
ipcRenderer.invoke("biometric", {
action: BiometricAction.OsSupported,
} satisfies BiometricMessage),
authenticate: (): Promise<boolean> =>
ipcRenderer.invoke("biometric", {
action: BiometricAction.Authenticate,
} satisfies BiometricMessage),
};
const clipboard = {
read: (): Promise<string> => ipcRenderer.invoke("clipboard.read"),
write: (message: ClipboardWriteMessage) => ipcRenderer.invoke("clipboard.write", message),
};
export default {
versions: {
app: (): Promise<string> => ipcRenderer.invoke("appVersion"),
@@ -52,8 +71,12 @@ export default {
});
},
launchUri: (uri: string) => ipcRenderer.invoke("launchUri", uri),
storage,
passwords,
biometric,
clipboard,
};
function deviceType(): DeviceType {

View File

@@ -1,5 +1,3 @@
import { ipcRenderer, shell } from "electron";
import { ClientType, DeviceType } from "@bitwarden/common/enums";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
@@ -8,7 +6,6 @@ import {
PlatformUtilsService,
} from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { BiometricMessage, BiometricStorageAction } from "../../types/biometric-message";
import { isMacAppStore } from "../../utils";
import { ClipboardWriteMessage } from "../types/clipboard";
@@ -61,7 +58,7 @@ export class ElectronPlatformUtilsService implements PlatformUtilsService {
}
launchUri(uri: string, options?: any): void {
shell.openExternal(uri);
ipc.platform.launchUri(uri);
}
getApplicationVersion(): Promise<string> {
@@ -108,7 +105,7 @@ export class ElectronPlatformUtilsService implements PlatformUtilsService {
const clearing = options?.clearing === true;
const clearMs = options?.clearMs ?? null;
ipcRenderer.invoke("clipboard.write", {
ipc.platform.clipboard.write({
text: text,
password: (options?.allowHistory ?? false) === false, // default to false
} satisfies ClipboardWriteMessage);
@@ -123,13 +120,11 @@ export class ElectronPlatformUtilsService implements PlatformUtilsService {
}
readFromClipboard(): Promise<string> {
return ipcRenderer.invoke("clipboard.read");
return ipc.platform.clipboard.read();
}
async supportsBiometric(): Promise<boolean> {
return await ipcRenderer.invoke("biometric", {
action: BiometricStorageAction.OsSupported,
} as BiometricMessage);
return await ipc.platform.biometric.osSupported();
}
/** This method is used to authenticate the user presence _only_.
@@ -137,11 +132,7 @@ export class ElectronPlatformUtilsService implements PlatformUtilsService {
* biometric keys, which has a separate authentication mechanism.
* For biometric keys, invoke "keytar" with a biometric key suffix */
async authenticateBiometric(): Promise<boolean> {
const val = await ipcRenderer.invoke("biometric", {
action: "authenticate",
});
return val;
return await ipc.platform.biometric.authenticate();
}
supportsSecureStorage(): boolean {