Load (canned) proposal from IPC
This commit is contained in:
47
src/ipc/handlers/proposal_handlers.ts
Normal file
47
src/ipc/handlers/proposal_handlers.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { ipcMain, type IpcMainInvokeEvent } from "electron";
|
||||
import type { Proposal } from "@/lib/schemas";
|
||||
|
||||
// Placeholder Proposal data
|
||||
const placeholderProposal: Proposal = {
|
||||
title: "Review: Example Refactoring (from IPC)",
|
||||
securityRisks: [
|
||||
{
|
||||
type: "warning",
|
||||
title: "Potential XSS Vulnerability",
|
||||
description: "User input is directly rendered without sanitization.",
|
||||
},
|
||||
{
|
||||
type: "danger",
|
||||
title: "Hardcoded API Key",
|
||||
description: "API key found in plain text in configuration file.",
|
||||
},
|
||||
],
|
||||
filesChanged: [
|
||||
{
|
||||
name: "ChatInput.tsx",
|
||||
path: "src/components/chat/ChatInput.tsx",
|
||||
summary: "Added review actions and details section.",
|
||||
},
|
||||
{
|
||||
name: "api.ts",
|
||||
path: "src/lib/api.ts",
|
||||
summary: "Refactored API call structure.",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const getProposalHandler = async (
|
||||
_event: IpcMainInvokeEvent,
|
||||
{ chatId }: { chatId: number }
|
||||
): Promise<Proposal> => {
|
||||
console.log(`IPC: get-proposal called for chatId: ${chatId}`);
|
||||
// Simulate async operation
|
||||
await new Promise((resolve) => setTimeout(resolve, 500)); // 500ms delay
|
||||
return placeholderProposal;
|
||||
};
|
||||
|
||||
// Function to register proposal-related handlers
|
||||
export function registerProposalHandlers() {
|
||||
ipcMain.handle("get-proposal", getProposalHandler);
|
||||
console.log("Registered proposal IPC handlers");
|
||||
}
|
||||
@@ -17,6 +17,7 @@ import type {
|
||||
NodeSystemInfo,
|
||||
Version,
|
||||
} from "./ipc_types";
|
||||
import type { Proposal } from "@/lib/schemas";
|
||||
import { showError } from "@/lib/toast";
|
||||
|
||||
export interface ChatStreamCallbacks {
|
||||
@@ -614,6 +615,18 @@ export class IpcClient {
|
||||
}
|
||||
}
|
||||
|
||||
// Get proposal details
|
||||
public async getProposal(chatId: number): Promise<Proposal> {
|
||||
try {
|
||||
const data = await this.ipcRenderer.invoke("get-proposal", { chatId });
|
||||
// Assuming the main process returns data matching the Proposal interface
|
||||
return data as Proposal;
|
||||
} catch (error) {
|
||||
showError(error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
// Example methods for listening to events (if needed)
|
||||
// public on(channel: string, func: (...args: any[]) => void): void {
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import { registerShellHandlers } from "./handlers/shell_handler";
|
||||
import { registerDependencyHandlers } from "./handlers/dependency_handlers";
|
||||
import { registerGithubHandlers } from "./handlers/github_handlers";
|
||||
import { registerNodeHandlers } from "./handlers/node_handlers";
|
||||
import { registerProposalHandlers } from "./handlers/proposal_handlers";
|
||||
|
||||
export function registerIpcHandlers() {
|
||||
// Register all IPC handlers by category
|
||||
@@ -17,4 +18,5 @@ export function registerIpcHandlers() {
|
||||
registerDependencyHandlers();
|
||||
registerGithubHandlers();
|
||||
registerNodeHandlers();
|
||||
registerProposalHandlers();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user