GithubHelp home page GithubHelp logo

opensourcekids / electronify-server Goto Github PK

View Code? Open in Web Editor NEW

This project forked from eliquious/electronify-server

0.0 2.0 0.0 16 KB

electronify-server is a lightweight tool which starts a local web server and opens a url in an Electron shell

License: MIT License

JavaScript 100.00%

electronify-server's Introduction

electionify-server

electronify-server is a lightweight tool which starts a local web server and opens a url in an Electron shell.

Installation

npm install --save electronify-server

How does it work?

When the Electron app loads, electronify-server will start a child process with the command you gave it in the configuration. This command is assumed to be a web server (but it doesn't have to be). If the child process was started successfully, the window will open and load the url to your server.

Examples

There are a couple examples included in the repo. In order to run the examples, you need to have electron installed. If you do not have it installed, perhaps the simplest way is to use electron-prebuilt like so:

npm install -g electron-prebuilt

To run the examples, simply go into each example folder and run:

electron .

The static example has a dependency that will need to be installed first via:

npm install

Short Example

var electronify = require('electronify-server');

electronify({
  url: 'https://google.com',
  noServer: true
});

Long Example

var electronify = require('electronify-server');

electronify({
  command: 'python -m SimpleHTTPServer',
  url: 'http://127.0.0.1:8000',
  debug: true,
  window: {height: 768, width: 1024},
  ready: function(app){
    // application event listeners could be added here
  },
  preLoad: function(app, window){
    // window event listeners could be added here
  },
  postLoad: function(app, window){
    // url finished loading
  },
  showDevTools: false
}).on('child-started', function(child) {
  // child process has started
  console.log('PID: ' + child.pid);

  // setup logging on child process
  child.stdout.on('data', console.log);
  child.stderr.on('data', console.log);

}).on('child-closed', function(app, stderr, stdout) {
  // the child process has finished

}).on('child-error', function(err, app) {
  // close electron if the child crashes
  app.quit();
});

Configuration Options

  • url [String]: URL to load after child process starts
  • command [String]: command to start child process
  • options [Object]: options for exec
  • debug [Boolean]: enables debug output
  • noServer [Boolean]: allows urls to load without starting a child process
  • showDevTools [Boolean]: shows dev tools on startup
  • window [Object]: BrowserWindow configuration
  • ready [Function]: called when the application is ready
    • app [Object]: Electron application
  • preLoad [Function]: called after the window is created but before the url is loaded
    • app [Object]: Electron application
    • window [Object]: Electron BrowserWindow
  • postLoad [Function]: called after the url has finished loading
    • app [Object]: Electron application
    • window [Object]: Electron BrowserWindow

Relevant documentation

Events

electronify also returns an EventEmitter which emits several events for the child process. This allows you to do additional work when the child process starts, exits or fails unexpectantly.

  • child-started: Emitted immediately on successful start of child process
  • child-closed: Emitted when the child process exits gracefully.
    • app: Electron application
    • stderr: Standard error of child process
    • stdout: Standard output of child process
  • child-error: Emitted when the child process fails.
    • err: Error returned from executing child process.
    • app: Electron application
  • error: Configuration error
    • err: Configuration error
    • app: Electron application

electronify-server's People

Contributors

eliquious avatar johman10 avatar

Watchers

James Cloos avatar Anthony Lupinetti avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.