mirror of
https://github.com/bitwarden/browser
synced 2025-12-29 22:53:44 +00:00
claude: Type Safety for IPC Messages
This commit is contained in:
@@ -20,15 +20,15 @@ export class MainDesktopAutotypeService {
|
||||
}
|
||||
|
||||
init() {
|
||||
ipcMain.handle("autofill.initAutotype", () => {
|
||||
ipcMain.handle(AUTOTYPE_IPC_CHANNELS.INIT, () => {
|
||||
this.init();
|
||||
});
|
||||
|
||||
ipcMain.handle("autofill.autotypeIsInitialized", () => {
|
||||
ipcMain.handle(AUTOTYPE_IPC_CHANNELS.INITIALIZED, () => {
|
||||
return this.isInitialized;
|
||||
});
|
||||
|
||||
ipcMain.on("autofill.toggleAutotype", (_event, enable: boolean) => {
|
||||
ipcMain.on(AUTOTYPE_IPC_CHANNELS.TOGGLE, (_event, enable: boolean) => {
|
||||
if (enable) {
|
||||
this.enableAutotype();
|
||||
} else {
|
||||
@@ -36,7 +36,7 @@ export class MainDesktopAutotypeService {
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.on("autofill.configureAutotype", (_event, config: AutotypeConfig) => {
|
||||
ipcMain.on(AUTOTYPE_IPC_CHANNELS.CONFIGURE, (_event, config: AutotypeConfig) => {
|
||||
const newKeyboardShortcut = new AutotypeKeyboardShortcut();
|
||||
const newKeyboardShortcutIsValid = newKeyboardShortcut.set(config.keyboardShortcut);
|
||||
|
||||
@@ -48,7 +48,7 @@ export class MainDesktopAutotypeService {
|
||||
this.setKeyboardShortcut(newKeyboardShortcut);
|
||||
});
|
||||
|
||||
ipcMain.on("autofill.completeAutotypeRequest", (_event, data) => {
|
||||
ipcMain.on(AUTOTYPE_IPC_CHANNELS.EXECUTE, (_event, data) => {
|
||||
const { response } = data;
|
||||
|
||||
if (
|
||||
@@ -91,7 +91,7 @@ export class MainDesktopAutotypeService {
|
||||
() => {
|
||||
const windowTitle = autotype.getForegroundWindowTitle();
|
||||
|
||||
this.windowMain.win.webContents.send("autofill.listenAutotypeRequest", {
|
||||
this.windowMain.win.webContents.send(AUTOTYPE_IPC_CHANNELS.LISTEN, {
|
||||
windowTitle,
|
||||
});
|
||||
},
|
||||
|
||||
9
apps/desktop/src/autofill/models/ipc-channels.ts
Normal file
9
apps/desktop/src/autofill/models/ipc-channels.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export const AUTOTYPE_IPC_CHANNELS = {
|
||||
INIT: "autofill.initAutotype",
|
||||
INITIALIZED: "autofill.autotypeIsInitialized",
|
||||
TOGGLE: "autofill.toggleAutotype",
|
||||
CONFIGURE: "autofill.configureAutotype",
|
||||
LISTEN: "autofill.listenAutotypeRequest",
|
||||
EXECUTION_ERROR: "autofill.autotypeExecutionError",
|
||||
EXECUTE: "autofill.executeAutotype",
|
||||
} as const;
|
||||
@@ -6,6 +6,7 @@ import { Command } from "../platform/main/autofill/command";
|
||||
import { RunCommandParams, RunCommandResult } from "../platform/main/autofill/native-autofill.main";
|
||||
|
||||
import { AutotypeConfig } from "./models/autotype-configure";
|
||||
import { AUTOTYPE_IPC_CHANNELS } from "./models/ipc-channels";
|
||||
|
||||
export default {
|
||||
runCommand: <C extends Command>(params: RunCommandParams<C>): Promise<RunCommandResult<C>> =>
|
||||
@@ -130,16 +131,16 @@ export default {
|
||||
);
|
||||
},
|
||||
initAutotype: () => {
|
||||
return ipcRenderer.invoke("autofill.initAutotype");
|
||||
return ipcRenderer.invoke(AUTOTYPE_IPC_CHANNELS.INIT);
|
||||
},
|
||||
autotypeIsInitialized: () => {
|
||||
return ipcRenderer.invoke("autofill.autotypeIsInitialized");
|
||||
return ipcRenderer.invoke(AUTOTYPE_IPC_CHANNELS.INITIALIZED);
|
||||
},
|
||||
configureAutotype: (config: AutotypeConfig) => {
|
||||
ipcRenderer.send("autofill.configureAutotype", config);
|
||||
ipcRenderer.send(AUTOTYPE_IPC_CHANNELS.CONFIGURE, config);
|
||||
},
|
||||
toggleAutotype: (enable: boolean) => {
|
||||
ipcRenderer.send("autofill.toggleAutotype", enable);
|
||||
ipcRenderer.send(AUTOTYPE_IPC_CHANNELS.TOGGLE, enable);
|
||||
},
|
||||
listenAutotypeRequest: (
|
||||
fn: (
|
||||
@@ -151,7 +152,7 @@ export default {
|
||||
) => void,
|
||||
) => {
|
||||
ipcRenderer.on(
|
||||
"autofill.listenAutotypeRequest",
|
||||
AUTOTYPE_IPC_CHANNELS.LISTEN,
|
||||
(
|
||||
event,
|
||||
data: {
|
||||
@@ -162,14 +163,14 @@ export default {
|
||||
|
||||
fn(windowTitle, (error, response) => {
|
||||
if (error) {
|
||||
ipcRenderer.send("autofill.completeError", {
|
||||
ipcRenderer.send(AUTOTYPE_IPC_CHANNELS.EXECUTION_ERROR, {
|
||||
windowTitle,
|
||||
error: error.message,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
ipcRenderer.send("autofill.completeAutotypeRequest", {
|
||||
ipcRenderer.send(AUTOTYPE_IPC_CHANNELS.EXECUTE, {
|
||||
windowTitle,
|
||||
response,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user