{"id":26706900,"url":"https://github.com/zoubingwu/electron-rpc-remote","last_synced_at":"2026-04-27T21:32:05.305Z","repository":{"id":57221902,"uuid":"248095170","full_name":"zoubingwu/electron-rpc-remote","owner":"zoubingwu","description":"RPC-styled API for electron ipc.","archived":false,"fork":false,"pushed_at":"2020-07-07T03:22:16.000Z","size":18,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-02-16T19:32:50.396Z","etag":null,"topics":["electron","ipc","ipcmain","ipcrenderer","rpc"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zoubingwu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-03-17T23:36:46.000Z","updated_at":"2020-03-18T00:48:05.000Z","dependencies_parsed_at":"2022-08-31T09:41:41.146Z","dependency_job_id":null,"html_url":"https://github.com/zoubingwu/electron-rpc-remote","commit_stats":null,"previous_names":["shadeofgod/electron-rpc-remote"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zoubingwu/electron-rpc-remote","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoubingwu%2Felectron-rpc-remote","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoubingwu%2Felectron-rpc-remote/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoubingwu%2Felectron-rpc-remote/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoubingwu%2Felectron-rpc-remote/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zoubingwu","download_url":"https://codeload.github.com/zoubingwu/electron-rpc-remote/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoubingwu%2Felectron-rpc-remote/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32356598,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-27T20:07:02.737Z","status":"ssl_error","status_checked_at":"2026-04-27T20:07:00.910Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["electron","ipc","ipcmain","ipcrenderer","rpc"],"created_at":"2025-03-27T06:19:47.804Z","updated_at":"2026-04-27T21:32:05.291Z","avatar_url":"https://github.com/zoubingwu.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# electron-rpc-remote\n\nA library that provides RPC-styled API for electron ipc.\n\n## Motivation\n\nIn Electron, There are several ways to communicate between the main process and renderer processes, such as `ipcRenderer`, `ipcMain` and `remote`.\n\n`ipcRenderer` and `ipcMain` provides event-based APIs to send synchronous and asynchronous messages, you may have to frequently add and remove event listeners on it and it's easy to cause a memory leak. This makes it hard to maintain the code if there are lots of ipc calls everywhere or you often need to pass some data back and forth.\n\n`remote` module is considered harmful and you should avoid to use it. for more information you can see [here](https://www.electronjs.org/docs/tutorial/security#15-disable-the-remote-module) and [here](https://medium.com/@nornagon/electrons-remote-module-considered-harmful-70d69500f31).\n\nThis package provides a RPC-styled API to ease the pain doing ipc calls in your Electron apps.\n\n## Exampe\n\n```sh\nnpm install electron-rpc-remote\n\n# or\nyarn add electron-rpc-remote\n```\n\n```js\n// main\nimport ipc from 'electron-rpc-remote';\n\nlet count = 0;\n\nipc.handle({\n  inc() {\n    count++;\n    return count;\n  },\n  async incAsync() {\n    await delay(1000);\n    count++;\n    return count;\n  },\n});\n\n// renderer\nawait ipc.invokeMain('inc'); // -\u003e 1\n```\n\n## API\n\n**_both processes_**\n\n- **`ipc.handle(obj: Handles): void`**\n\n```ts\ninterface Handles {\n  [method: string]: (...args: any[]) =\u003e any;\n}\n\nipc.handle({\n  someMethod() {\n    /** ... */\n  },\n});\n```\n\n**_`main` process_**\n\n- **`ipc.invokeRenderer(webContentId: number, method: string, args?: any): Promise\u003cany\u003e`**\n- **`ipc.invokeAllRenderers(method: string, args?: any): Promise\u003cany\u003e`**\n\n**_`renderer` process_**\n\n- **`ipc.invokeMain(method: string, args?: any): Promise\u003cany\u003e`**\n- **`ipc.invokeRenderer(webContentId: number, method: string, args?: any): Promise\u003cany\u003e`**\n\n## Warning\n\n\u003e All data passed across processes will be serialized with the Structured Clone Algorithm. Sending Functions, Promises, Symbols, WeakMaps, or WeakSets will throw an exception.\n\nAlso You should try to avoid sending **large objects** or **non-standard JavaScript types** such as DOM objects or special Electron objects.\n\n## Recipes\n\n- **get some values**\n\n```js\n// main\nipc.handle({\n  getValueThatOnlyCanBeAccessedInMain() {\n    return someValue;\n  },\n});\n\n// renderer\nconst val = await ipc.invokeMain('getValueThatOnlyCanBeAccessedInMain');\n```\n\n- **pass arguments**\n\n```js\n// main\nipc.handle({\n  add(...numbers) {\n    return numbers.reduce((a, b) =\u003e a + b, 0);\n  },\n});\n\n// renderer\nconst val = await ipc.invokeMain('add', [1, 2, 3, 4, 5]);\n```\n\n- **open native dialog**\n\n```js\n// main\nipc.handle({\n  async openNativeDialog({ message, buttons = ['confirm', 'cancel'] }) {\n    const res = await dialog.showMessageBox({\n      message,\n      buttons,\n      type: 'question',\n      defaultId: 0,\n    });\n\n    return res;\n  },\n});\n\n// renderer\nconst res = await ipc.invokeMain('openNativeDialog', { message: 'hi?' });\nif (res === 0) {\n  // ...\n}\n```\n\n- **show native notification**\n\n```js\n// main\nipc.handle({\n  showNotification(options) {\n    if (!Notification.isSupported()) {\n      return false;\n    }\n    const instance = new Notification(Object.assign(defaultOptions, options));\n    instance.show();\n    return true;\n  },\n});\n\n// renderer\nconst showed = await ipc.invokeMain('showNotification', {\n  body: 'test notification!',\n});\n```\n\n- **from main process to renderer**\n\n```js\n// main\npowerMonitor.on('suspend', () =\u003e {\n  const focused = BrowserWindow.getFocusedWindow().webContents.id;\n  ipc.invokeRenderer(focused, 'handlePowerSuspend');\n\n  // or\n  ipc.invokeAllRenderers('handlePowerSuspend');\n});\n\n// renderer\nipc.handle({\n  handlePowerSuspend() {\n    // ...\n  },\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzoubingwu%2Felectron-rpc-remote","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzoubingwu%2Felectron-rpc-remote","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzoubingwu%2Felectron-rpc-remote/lists"}