bitwarden-estensione-browser/libs/node/src/cli/services/cliPlatformUtils.service.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

154 lines
3.0 KiB
TypeScript
Raw Normal View History

2020-09-23 17:49:16 +02:00
import * as child_process from "child_process";
2019-03-16 03:33:19 +01:00
2022-06-14 17:10:53 +02:00
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
import { ClientType } from "@bitwarden/common/enums/clientType";
import { DeviceType } from "@bitwarden/common/enums/deviceType";
2019-03-16 03:33:19 +01:00
2022-02-22 15:39:11 +01:00
// eslint-disable-next-line
2020-09-23 17:49:16 +02:00
const open = require("open");
2019-03-16 03:33:19 +01:00
export class CliPlatformUtilsService implements PlatformUtilsService {
clientType: ClientType;
2021-12-16 13:36:21 +01:00
2019-03-16 03:33:19 +01:00
private deviceCache: DeviceType = null;
2021-12-16 13:36:21 +01:00
constructor(clientType: ClientType, private packageJson: any) {
this.clientType = clientType;
2019-03-16 03:33:19 +01:00
}
2021-12-16 13:36:21 +01:00
2019-03-16 03:33:19 +01:00
getDevice(): DeviceType {
if (!this.deviceCache) {
switch (process.platform) {
case "win32":
this.deviceCache = DeviceType.WindowsDesktop;
break;
case "darwin":
this.deviceCache = DeviceType.MacOsDesktop;
break;
case "linux":
default:
this.deviceCache = DeviceType.LinuxDesktop;
break;
2021-12-16 13:36:21 +01:00
}
2019-03-16 03:33:19 +01:00
}
2021-12-16 13:36:21 +01:00
2019-03-16 03:33:19 +01:00
return this.deviceCache;
}
2021-12-16 13:36:21 +01:00
2019-03-16 03:33:19 +01:00
getDeviceString(): string {
const device = DeviceType[this.getDevice()].toLowerCase();
return device.replace("desktop", "");
}
2021-12-16 13:36:21 +01:00
getClientType() {
return this.clientType;
}
2019-03-16 03:33:19 +01:00
isFirefox() {
return false;
}
2021-12-16 13:36:21 +01:00
2019-03-16 03:33:19 +01:00
isChrome() {
return false;
}
2021-12-16 13:36:21 +01:00
2019-03-16 03:33:19 +01:00
isEdge() {
return false;
}
2021-12-16 13:36:21 +01:00
2019-03-16 03:33:19 +01:00
isOpera() {
return false;
}
2021-12-16 13:36:21 +01:00
2019-03-16 03:33:19 +01:00
isVivaldi() {
return false;
}
2021-12-16 13:36:21 +01:00
2019-03-16 03:33:19 +01:00
isSafari() {
return false;
}
2021-12-16 13:36:21 +01:00
2019-03-16 03:33:19 +01:00
isMacAppStore() {
return false;
}
2021-12-16 13:36:21 +01:00
2019-03-16 03:33:19 +01:00
isViewOpen() {
2019-08-20 19:47:15 +02:00
return Promise.resolve(false);
2019-03-16 03:33:19 +01:00
}
2021-12-16 13:36:21 +01:00
2019-03-16 03:33:19 +01:00
launchUri(uri: string, options?: any): void {
2020-09-23 17:49:16 +02:00
if (process.platform === "linux") {
child_process.spawnSync("xdg-open", [uri]);
} else {
open(uri);
2021-12-16 13:36:21 +01:00
}
2020-09-23 17:49:16 +02:00
}
2021-12-16 13:36:21 +01:00
2019-03-16 03:33:19 +01:00
saveFile(win: Window, blobData: any, blobOptions: any, fileName: string): void {
throw new Error("Not implemented.");
}
2021-12-16 13:36:21 +01:00
getApplicationVersion(): Promise<string> {
return Promise.resolve(this.packageJson.version);
2019-03-16 03:33:19 +01:00
}
2021-12-16 13:36:21 +01:00
2021-11-23 21:50:28 +01:00
getApplicationVersionSync(): string {
return this.packageJson.version;
}
2021-12-16 13:36:21 +01:00
2021-03-15 16:16:51 +01:00
supportsWebAuthn(win: Window) {
2019-03-16 03:33:19 +01:00
return false;
}
2021-12-16 13:36:21 +01:00
2019-03-16 03:33:19 +01:00
supportsDuo(): boolean {
return false;
}
2021-12-16 13:36:21 +01:00
2019-03-16 03:33:19 +01:00
showToast(
type: "error" | "success" | "warning" | "info",
title: string,
text: string | string[],
options?: any
): void {
throw new Error("Not implemented.");
}
2021-12-16 13:36:21 +01:00
2019-03-16 03:33:19 +01:00
showDialog(
text: string,
title?: string,
confirmText?: string,
cancelText?: string,
type?: string
): Promise<boolean> {
throw new Error("Not implemented.");
}
2021-12-16 13:36:21 +01:00
2019-03-16 03:33:19 +01:00
isDev(): boolean {
return process.env.BWCLI_ENV === "development";
}
2021-12-16 13:36:21 +01:00
2019-03-16 03:33:19 +01:00
isSelfHost(): boolean {
return false;
}
2021-12-16 13:36:21 +01:00
2019-03-16 03:33:19 +01:00
copyToClipboard(text: string, options?: any): void {
throw new Error("Not implemented.");
}
2021-12-16 13:36:21 +01:00
2019-03-16 03:33:19 +01:00
readFromClipboard(options?: any): Promise<string> {
throw new Error("Not implemented.");
}
2021-12-16 13:36:21 +01:00
supportsBiometric(): Promise<boolean> {
return Promise.resolve(false);
}
2021-12-16 13:36:21 +01:00
authenticateBiometric(): Promise<boolean> {
return Promise.resolve(false);
}
2021-12-16 13:36:21 +01:00
supportsSecureStorage(): boolean {
return false;
}
2019-03-16 03:33:19 +01:00
}