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