{"id":15391034,"url":"https://github.com/quramy/electron-connect","last_synced_at":"2025-05-16T18:06:47.372Z","repository":{"id":1742371,"uuid":"37473730","full_name":"Quramy/electron-connect","owner":"Quramy","description":"Livereload tool for Electron","archived":false,"fork":false,"pushed_at":"2023-01-04T14:27:55.000Z","size":242,"stargazers_count":340,"open_issues_count":22,"forks_count":49,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-05-16T18:06:44.342Z","etag":null,"topics":["electron"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/electron-connect","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Quramy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-06-15T15:28:04.000Z","updated_at":"2024-10-02T12:37:28.000Z","dependencies_parsed_at":"2023-01-13T11:21:26.672Z","dependency_job_id":null,"html_url":"https://github.com/Quramy/electron-connect","commit_stats":null,"previous_names":[],"tags_count":38,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Quramy%2Felectron-connect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Quramy%2Felectron-connect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Quramy%2Felectron-connect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Quramy%2Felectron-connect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Quramy","download_url":"https://codeload.github.com/Quramy/electron-connect/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254582905,"owners_count":22095518,"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":["electron"],"created_at":"2024-10-01T15:09:43.212Z","updated_at":"2025-05-16T18:06:47.354Z","avatar_url":"https://github.com/Quramy.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# electron-connect [![Build Status](https://travis-ci.org/Quramy/electron-connect.svg?branch=master)](https://travis-ci.org/Quramy/electron-connect) [![npm version](https://badge.fury.io/js/electron-connect.svg)](http://badge.fury.io/js/electron-connect) ![dependency](https://david-dm.org/quramy/electron-connect.svg)\nUtility tool to develop applications with [Electron](http://electron.atom.io/).\n\nUsing this in your Node.js scripts (e.g. `gulpfile.js`), you can livereload your Electron app.\n\nIt provides the following features:\n\n* start (and restart) Electron application.\n* reload renderer processes.\n* stop Electron application.\n\n## Install\nUse npm:\n\n```bash\nnpm install electron\nnpm install electron-connect --save-dev\n```\n\n## Usage\n`electron-connect` has server and client components. They communicate with each other using WebSocket.\nThe server component manages Electron process and broadcasts reload event to client, and client components reload renderer's resources.\n\n### Server\nHere is an example creating a server in [gulpfile](http://gulpjs.com/).\n\n```js\n'use strict';\n\nvar gulp = require('gulp');\nvar electron = require('electron-connect').server.create();\n\ngulp.task('serve', function () {\n\n  // Start browser process\n  electron.start();\n\n  // Restart browser process\n  gulp.watch('app.js', electron.restart);\n\n  // Reload renderer process\n  gulp.watch(['index.js', 'index.html'], electron.reload);\n});\n```\n\n### Client\nA client can be created in either browser process or renderer process.\n`Note:` Please make sure it is not done in both.\n\n* RendererProcess\n```html\n\u003chtml\u003e\n\u003cbody\u003e\n\u003c!-- build:remove --\u003e\n\u003c!-- Connect to server process --\u003e\n\u003cscript\u003erequire('electron-connect').client.create()\u003c/script\u003e\n\u003c!-- end:build --\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\nDo you want to use this tool for only develop environment ?\nYou can remove the `\u003cscript\u003e` block in your gulpfile using [gulp-useref](https://www.npmjs.com/package/gulp-useref#usage).\n\n* BrowserProcess \n\n```js\n'use strict';\n\nvar app = require('app');\nvar BrowserWindow = require('browser-window');\nvar client = require('electron-connect').client;\n\napp.on('ready', function () {\n  var mainWindow = new BrowserWindow({\n    width: 400,\n    height: 300\n  });\n  mainWindow.loadUrl('file://' + __dirname + '/index.html');\n\n  // Connect to server process\n  client.create(mainWindow);\n});\n```\n\nIf you want details, see [example/simple](example/simple).\n\n## API References\n\n## server.create([options])\n\n* `options` Object\n * `electron` Object. An `electron` module. Set it If you want to use your forked Electron.\n * `useGlobalElectron` Boolean. If set, electron-connect uses `electron` module installed globally (default: `false`).\n * `path` String. A path to your `package.json` file (default: `process.cwd()`).\n * `port` Number. WebSocket server port (default: `30080`).\n * `spawnOpt` Object. Options for [spawn](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options).\n * `logLevel` Number. The granularity of the electron-connect logging in your prompt. `0` - warning only, `1` - warning and info only, `2` - all logs (default: `1`).\n * `stopOnClose` Boolean. If set, closing last remaining window stops the electron application.\n\nReturns a new `ProcessManager` object.\n\nIf neither `electron` nor `useGlobalElectron` option is set, electron-connect searches for `electron` module automatically.\n\n1. First, electron-connect searches `electron` installed locally.\n1. If not hit, electron-connect uses `electron` installed globally.\n\n**New in version 0.5.x and onwards :**\nNow, ProcessManager's `start()`, `restart()` and `stop()` methods invoke ``callback`` with an argument that indicates the `state` of the electron process, which could be one of the following string values -\n* `started`\n* `restarting`\n* `restarted`\n* `stopped`\n\nSee [example/stop-on-close](example/stop-on-close), where you can find sample code that uses `stopOnClose` option and `stopped` state to shutdown gulp process gracefully.\n\n## Class: ProcessManager\n\n### start([args], [callback])\n\n* `args` String or Array. Additional arguments used when create a process.\n* `callback` Function\n\nStarts a server and Electron application process.\n\n### restart([args], [callback])\n\n* `args` String or Array. Additional arguments used when create a process.\n* `callback` Function\n\nKills Electron process if it exsists, and starts new one.\n\nThis method is useful for callback of your browserProcess sourcecodes' change event.\n\n### reload([ids])\n\n* `ids` String or Array. A list of id of target client.\n\nEmit reload event to target clients. Broadcasts reload event to all connected `Client` object if `ids` not set.\nThis method does not kill any Electron processes.\n\nThis method is useful for callback of your rendererProcess sourcecodes' change event.\n\n### stop([callback])\n\n* `callback` Function\n\nKills Electron process and stops server.\n\n### on(eventName, callback)\n\n* `eventName` String\n* `callback` Function\n\nRegisters an eventhandler that gets invoked when an event is emitted by `Client.sendMessage`.\n\n### broadcast(eventName, [data])\n\n* `eventName` String. A message type.\n* `data` Object. A message data.\n\nBroadcasts an event to all clients.\n\n## client.create([browserWindow], [options], [callback])\n\n* `browserWindow` Object. Optional, in rendererProcess only. Required, when client is created in browserProcess.\n* `options` Object\n * `port` Number. WebSocket server port (default: `30080`) that client should connect to.\n * `sendBounds` Boolean\n * `logLevel` Number. See [server.create([options]).logLevel](#servercreateoptions).\n* `callback` Function\n\nCreates a new `Client` object associated with `browserWindow` and connects to `ProcessManager`.\n\nThe `browserWindow` should be an Electron [browser-window](https://github.com/atom/electron/blob/master/docs/api/browser-window.md) instance.\nOnce a client is created and connected to the server, client can receive events (e.g. reload).\n\nIf `sendBounds` is set (default `true`), client sends a bounds object when `browserWindow` moves or resizes.\nAnd when `ProcessManager.restart()` is called, client recovers the bounds stored at server.\n\n## Class: Client\n\n### id\n\nAn identifier of this client. It is a same value `browserWindow.id`.\n\n### on(eventName, callback)\n\n* `eventName` String\n* `callback` Function\n\nRegisters an eventhandler that gets invoked, when an event is emitted by `ProcessManager.broadcast`.\n\n### sendMessage(eventName, [data])\n\n* `eventName` String. A message type.\n* `data` Object. A message data.\n\nEmits an event to `ProcessManager`.\n\n## License\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquramy%2Felectron-connect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fquramy%2Felectron-connect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquramy%2Felectron-connect/lists"}