mirror of
https://github.com/bitwarden/browser
synced 2025-12-29 22:53:44 +00:00
181 lines
4.8 KiB
TypeScript
181 lines
4.8 KiB
TypeScript
import { ipcRenderer } from "electron";
|
|
|
|
import type { autofill } from "@bitwarden/desktop-napi";
|
|
|
|
import { Command } from "../platform/main/autofill/command";
|
|
import { RunCommandParams, RunCommandResult } from "../platform/main/autofill/native-autofill.main";
|
|
|
|
import { AutotypeConfig } from "./models/autotype-configure";
|
|
|
|
export default {
|
|
runCommand: <C extends Command>(params: RunCommandParams<C>): Promise<RunCommandResult<C>> =>
|
|
ipcRenderer.invoke("autofill.runCommand", params),
|
|
|
|
listenPasskeyRegistration: (
|
|
fn: (
|
|
clientId: number,
|
|
sequenceNumber: number,
|
|
request: autofill.PasskeyRegistrationRequest,
|
|
completeCallback: (
|
|
error: Error | null,
|
|
response: autofill.PasskeyRegistrationResponse,
|
|
) => void,
|
|
) => void,
|
|
) => {
|
|
ipcRenderer.on(
|
|
"autofill.passkeyRegistration",
|
|
(
|
|
event,
|
|
data: {
|
|
clientId: number;
|
|
sequenceNumber: number;
|
|
request: autofill.PasskeyRegistrationRequest;
|
|
},
|
|
) => {
|
|
const { clientId, sequenceNumber, request } = data;
|
|
fn(clientId, sequenceNumber, request, (error, response) => {
|
|
if (error) {
|
|
ipcRenderer.send("autofill.completeError", {
|
|
clientId,
|
|
sequenceNumber,
|
|
error: error.message,
|
|
});
|
|
return;
|
|
}
|
|
|
|
ipcRenderer.send("autofill.completePasskeyRegistration", {
|
|
clientId,
|
|
sequenceNumber,
|
|
response,
|
|
});
|
|
});
|
|
},
|
|
);
|
|
},
|
|
|
|
listenPasskeyAssertion: (
|
|
fn: (
|
|
clientId: number,
|
|
sequenceNumber: number,
|
|
request: autofill.PasskeyAssertionRequest,
|
|
completeCallback: (error: Error | null, response: autofill.PasskeyAssertionResponse) => void,
|
|
) => void,
|
|
) => {
|
|
ipcRenderer.on(
|
|
"autofill.passkeyAssertion",
|
|
(
|
|
event,
|
|
data: {
|
|
clientId: number;
|
|
sequenceNumber: number;
|
|
request: autofill.PasskeyAssertionRequest;
|
|
},
|
|
) => {
|
|
const { clientId, sequenceNumber, request } = data;
|
|
fn(clientId, sequenceNumber, request, (error, response) => {
|
|
if (error) {
|
|
ipcRenderer.send("autofill.completeError", {
|
|
clientId,
|
|
sequenceNumber,
|
|
error: error.message,
|
|
});
|
|
return;
|
|
}
|
|
|
|
ipcRenderer.send("autofill.completePasskeyAssertion", {
|
|
clientId,
|
|
sequenceNumber,
|
|
response,
|
|
});
|
|
});
|
|
},
|
|
);
|
|
},
|
|
listenPasskeyAssertionWithoutUserInterface: (
|
|
fn: (
|
|
clientId: number,
|
|
sequenceNumber: number,
|
|
request: autofill.PasskeyAssertionWithoutUserInterfaceRequest,
|
|
completeCallback: (error: Error | null, response: autofill.PasskeyAssertionResponse) => void,
|
|
) => void,
|
|
) => {
|
|
ipcRenderer.on(
|
|
"autofill.passkeyAssertionWithoutUserInterface",
|
|
(
|
|
event,
|
|
data: {
|
|
clientId: number;
|
|
sequenceNumber: number;
|
|
request: autofill.PasskeyAssertionWithoutUserInterfaceRequest;
|
|
},
|
|
) => {
|
|
const { clientId, sequenceNumber, request } = data;
|
|
fn(clientId, sequenceNumber, request, (error, response) => {
|
|
if (error) {
|
|
ipcRenderer.send("autofill.completeError", {
|
|
clientId,
|
|
sequenceNumber,
|
|
error: error.message,
|
|
});
|
|
return;
|
|
}
|
|
|
|
ipcRenderer.send("autofill.completePasskeyAssertion", {
|
|
clientId,
|
|
sequenceNumber,
|
|
response,
|
|
});
|
|
});
|
|
},
|
|
);
|
|
},
|
|
initAutotype: () => {
|
|
return ipcRenderer.invoke("autofill.initAutotype");
|
|
},
|
|
autotypeIsInitialized: () => {
|
|
return ipcRenderer.invoke("autofill.autotypeIsInitialized");
|
|
},
|
|
configureAutotype: (config: AutotypeConfig) => {
|
|
ipcRenderer.send("autofill.configureAutotype", config);
|
|
},
|
|
toggleAutotype: (enable: boolean) => {
|
|
ipcRenderer.send("autofill.toggleAutotype", enable);
|
|
},
|
|
listenAutotypeRequest: (
|
|
fn: (
|
|
windowTitle: string,
|
|
completeCallback: (
|
|
error: Error | null,
|
|
response: { username?: string; password?: string },
|
|
) => void,
|
|
) => void,
|
|
) => {
|
|
ipcRenderer.on(
|
|
"autofill.listenAutotypeRequest",
|
|
(
|
|
event,
|
|
data: {
|
|
windowTitle: string;
|
|
},
|
|
) => {
|
|
const { windowTitle } = data;
|
|
|
|
fn(windowTitle, (error, response) => {
|
|
if (error) {
|
|
ipcRenderer.send("autofill.completeError", {
|
|
windowTitle,
|
|
error: error.message,
|
|
});
|
|
return;
|
|
}
|
|
|
|
ipcRenderer.send("autofill.completeAutotypeRequest", {
|
|
windowTitle,
|
|
response,
|
|
});
|
|
});
|
|
},
|
|
);
|
|
},
|
|
};
|