{"id":15135058,"url":"https://github.com/megahertz/electron-call","last_synced_at":"2025-10-23T11:30:49.271Z","repository":{"id":38523308,"uuid":"411796540","full_name":"megahertz/electron-call","owner":"megahertz","description":"The easiest main-renderer IPC communication","archived":false,"fork":false,"pushed_at":"2024-07-11T12:38:55.000Z","size":65,"stargazers_count":11,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-12-12T15:39:52.106Z","etag":null,"topics":[],"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/megahertz.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-09-29T19:01:02.000Z","updated_at":"2024-07-11T12:39:28.000Z","dependencies_parsed_at":"2024-12-02T18:16:56.099Z","dependency_job_id":null,"html_url":"https://github.com/megahertz/electron-call","commit_stats":{"total_commits":26,"total_committers":1,"mean_commits":26.0,"dds":0.0,"last_synced_commit":"d1f70ea9c2f06e6cc5c4663da8f3cf787bca43ec"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/megahertz%2Felectron-call","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/megahertz%2Felectron-call/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/megahertz%2Felectron-call/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/megahertz%2Felectron-call/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/megahertz","download_url":"https://codeload.github.com/megahertz/electron-call/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230937718,"owners_count":18303332,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-09-26T05:42:26.100Z","updated_at":"2025-10-23T11:30:48.941Z","avatar_url":"https://github.com/megahertz.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# electron-call\n\n[![Tests](https://github.com/megahertz/electron-call/workflows/Tests/badge.svg)](https://github.com/megahertz/electron-call/actions?query=workflow%3ATests)\n[![npm version](https://img.shields.io/npm/v/electron-call?color=brightgreen)](https://www.npmjs.com/package/electron-call)\n[![Dependencies status](https://img.shields.io/david/megahertz/electron-call)](https://david-dm.org/megahertz/electron-call)\n\nThe easiest main-renderer IPC communication. Now calling a method/function in a\nrenderer process looks the same as calling a local one. It supports both main →\nrenderer and renderer → main calls.\n\nWarning: API could be changed frequently until v0.2.0 release.\n\n### Key features\n\n- Very simple API\n- Typescript friendly\n- Lightweight and fast\n- No dependencies\n- Supports context isolation mode\n\n```typescript\n// MainApi.ts\nimport { app } from 'electron';\nimport call from 'electron-call';\n\nexport class MainApi {\n  async getAppName() {\n    return app.getName();\n  }\n}\n\ncall.initialize();\ncall.provide('MainApi', new MainApi());\n```\n\n```typescript\n// renderer.ts\nimport call from 'electron-call';\nimport type { MainApi } from '../main/MainApi';\n\nconst mainApi = call.use\u003cMainApi\u003e('MainApi');\nconsole.log(await mainApi.getAppName());\n```\n\n## Installation\n\nInstall with [npm](https://npmjs.org/package/electron-call):\n\n    npm install electron-call\n\n## Usage\n\n### Initialization\n\nFirst of all, electron-call should be able to communicate between main and\nrenderer processes:\n\n`call.initialize()`\n\nUnder the hood `call.initialize()` attempts to inject a preload script via\n`session.setPreloads()`. By default, it only does this for the `defaultSession`.\n\nAlternatively, you can import `electron-call` in your preload script.\n\n### Providing API\n\nThere are 3 ways of defining API:\n\n#### Using a class\n\nPreferred way, since it provides the best type support\n\n```typescript\nexport class FsApi {\n  async selectDirectory(defaultPath: string) {\n    return dialog.showOpenDialog({\n      defaultPath,\n      properties: ['openDirectory'],\n    });\n  }\n}\n\ncall.provide('FsApi', new FsApi());\n```\n\n#### Using an object\n\nIt works the same as above, but there's a lack of types. That's fine if you\ndon't use TypeScript or prefer a separated interface for ApiName\n\n```js\ncall.provide('FsApi', {\n  async selectDirectory(defaultPath) {\n    return dialog.showOpenDialog({\n      defaultPath,\n      properties: ['openDirectory'],\n    });\n  },\n});\n```\n\n#### Using a function\n\n```js\ncall.provideFunction('selectDirectory', async (defaultPath) =\u003e {\n  return dialog.showOpenDialog({\n    defaultPath,\n    properties: ['openDirectory'],\n  });\n});\n```\n\n### Consuming API\n\n#### Using a class/object\n\nYou can omit using FsApi generic if you don't need type support\n\n```typescript\nconst fsApi = call.use\u003cFsApi\u003e('FsApi');\nconsole.log(await fsApi.selectDirectory(defaultPath));\n```\n\nAlso, you can get a remote class constructor instead of an instance\n\nconst FsApiProxy = call.use\u003cFsApi\u003e('FsApi') console.log(await new\nFsApiProxy().selectDirectory(defaultPath));\n\n#### Using a function\n\n```js\nconst selectDirectory = call.useFunction('selectDirectory');\nconsole.log(await selectDirectory(defaultPath));\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmegahertz%2Felectron-call","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmegahertz%2Felectron-call","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmegahertz%2Felectron-call/lists"}