1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-30 07:03:26 +00:00

improve IPC message args

This commit is contained in:
neuronull
2025-10-29 09:48:45 -06:00
parent 45ec0f64f2
commit dc743355fb
4 changed files with 20 additions and 9 deletions

View File

@@ -5,6 +5,7 @@ import { LogService } from "@bitwarden/logging";
import { WindowMain } from "../../main/window.main";
import { stringIsNotUndefinedNullAndEmpty } from "../../utils";
import { AutotypeConfig } from "../models/autotype-configure";
import { AutotypeKeyboardShortcut } from "../models/main-autotype-keyboard-shortcut";
export class MainDesktopAutotypeService {
@@ -27,17 +28,17 @@ export class MainDesktopAutotypeService {
}
init() {
ipcMain.on("autofill.toggleAutotype", (event, data) => {
if (data.enable) {
ipcMain.on("autofill.toggleAutotype", (_event, enable: boolean) => {
if (enable) {
this.enableAutotype();
} else {
this.disableAutotype();
}
});
ipcMain.on("autofill.configureAutotype", (event, data) => {
ipcMain.on("autofill.configureAutotype", (_event, config: AutotypeConfig) => {
const newKeyboardShortcut = new AutotypeKeyboardShortcut();
const newKeyboardShortcutIsValid = newKeyboardShortcut.set(data.keyboardShortcut);
const newKeyboardShortcutIsValid = newKeyboardShortcut.set(config.keyboardShortcut);
if (!newKeyboardShortcutIsValid) {
this.logService.error("Configure autotype failed: the keyboard shortcut is invalid.");
@@ -47,7 +48,7 @@ export class MainDesktopAutotypeService {
this.setKeyboardShortcut(newKeyboardShortcut);
});
ipcMain.on("autofill.completeAutotypeRequest", (event, data) => {
ipcMain.on("autofill.completeAutotypeRequest", (_event, data) => {
const { response } = data;
if (

View File

@@ -0,0 +1,3 @@
export interface AutotypeConfig {
keyboardShortcut: string[];
}

View File

@@ -5,6 +5,8 @@ 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),
@@ -133,11 +135,11 @@ export default {
autotypeIsInitialized: () => {
return ipcRenderer.invoke("autofill.autotypeIsInitialized");
},
configureAutotype: (keyboardShortcut: string[]) => {
ipcRenderer.send("autofill.configureAutotype", { keyboardShortcut });
configureAutotype: (config: AutotypeConfig) => {
ipcRenderer.send("autofill.configureAutotype", config);
},
toggleAutotype: (enable: boolean) => {
ipcRenderer.send("autofill.toggleAutotype", { enable });
ipcRenderer.send("autofill.toggleAutotype", enable);
},
listenAutotypeRequest: (
fn: (

View File

@@ -26,6 +26,8 @@ import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.servi
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
import { UserId } from "@bitwarden/user-core";
import { AutotypeConfig } from "../models/autotype-configure";
import { DesktopAutotypeDefaultSettingPolicy } from "./desktop-autotype-policy.service";
export const defaultWindowsAutotypeKeyboardShortcut: string[] = ["Control", "Shift", "B"];
@@ -122,7 +124,10 @@ export class DesktopAutotypeService {
this.autotypeKeyboardShortcut$
.pipe(
concatMap(async (keyboardShortcut) => {
ipc.autofill.configureAutotype(keyboardShortcut);
const config: AutotypeConfig = {
keyboardShortcut,
};
ipc.autofill.configureAutotype(config);
}),
)
.subscribe();