ワンクリックで
electron-api
Guide for adding new Electron APIs to Pengu. Use when implementing new frontend-to-electron communications via preload/IPC.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Guide for adding new Electron APIs to Pengu. Use when implementing new frontend-to-electron communications via preload/IPC.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
Use when implementing or changing a Waddle feature that must be delivered to GitHub, especially with local installation, a dirty worktree, or diverged remote history.
Guide for publishing Waddle GitHub releases. Use when creating release tags, editing release workflows, changing electron-updater behavior, or verifying auto-update artifacts.
Guide for adding new configuration settings to Pengu. Use when adding a new setting to the configuration system, implementing a new config key, or adding user-customizable settings.
Guide for adding new RPC calls to Pengu. Use when implementing new RPC commands, adding server-client communication methods, or extending the RPC interface with new functionality.
Guide for adding new wsh commands to Pengu. Use when implementing new CLI commands, adding command-line functionality, or extending the wsh command interface.
Guide for creating and displaying context menus in Pengu. Use when implementing right-click menus, adding context menu items, creating submenus, or handling menu interactions with checkboxes and separators.
| name | electron-api |
| description | Guide for adding new Electron APIs to Pengu. Use when implementing new frontend-to-electron communications via preload/IPC. |
Electron APIs allow the frontend to call Electron main process functionality directly via IPC.
frontend/types/custom.d.ts - TypeScript ElectronApi typeemain/preload.ts - Expose method via contextBridgeemain/emain-ipc.ts - Implement IPC handlerfrontend/preview/preview-electron-api.ts - Add a no-op stub to keep the previewElectronApi object in sync with the ElectronApi typeipcRenderer.sendSync() + ipcMain.on() + event.returnValue = ...ipcRenderer.invoke() + ipcMain.handle()ipcRenderer.send() + ipcMain.on()In frontend/types/custom.d.ts:
type ElectronApi = {
captureScreenshot: (rect: Electron.Rectangle) => Promise<string>; // capture-screenshot
};
In emain/preload.ts:
contextBridge.exposeInMainWorld("api", {
captureScreenshot: (rect: Rectangle) => ipcRenderer.invoke("capture-screenshot", rect),
});
electron.ipcMain.handle("capture-screenshot", async (event, rect) => {
const tabView = getPenguTabViewByWebContentsId(event.sender.id);
if (!tabView) throw new Error("No tab view found");
const image = await tabView.webContents.capturePage(rect);
return `data:image/png;base64,${image.toPNG().toString("base64")}`;
});
In frontend/preview/preview-electron-api.ts:
captureScreenshot: (_rect: Electron.Rectangle) => Promise.resolve(""),
import { getApi } from "@/store/global";
const dataUrl = await getApi().captureScreenshot({ x: 0, y: 0, width: 800, height: 600 });
type ElectronApi = {
getUserName: () => string; // get-user-name
};
getUserName: () => ipcRenderer.sendSync("get-user-name"),
electron.ipcMain.on("get-user-name", (event) => {
event.returnValue = process.env.USER || "unknown";
});
import { getApi } from "@/store/global";
const userName = getApi().getUserName(); // blocks until returns
type ElectronApi = {
openExternal: (url: string) => void; // open-external
};
openExternal: (url) => ipcRenderer.send("open-external", url),
electron.ipcMain.on("open-external", (event, url) => {
electron.shell.openExternal(url);
});
type ElectronApi = {
onZoomFactorChange: (callback: (zoomFactor: number) => void) => void; // zoom-factor-change
};
onZoomFactorChange: (callback) =>
ipcRenderer.on("zoom-factor-change", (_event, zoomFactor) => callback(zoomFactor)),
webContents.send("zoom-factor-change", newZoomFactor);
Use Sync when:
event.returnValue or browser hangsUse Async when:
Use Fire-and-forget when:
Electron API vs RPC:
ElectronApi in custom.d.tspreload.tsemain-ipc.tspreview-electron-api.tsevent.returnValue (or browser hangs!)