Giter Site home page Giter Site logo

sweet-electron's Introduction

Sweet Electron

Easy, minimalist framework for Electron applications.

const electron = require('electron');
const sweet = require('sweet-electron')(electron);

sweet().url(__dirname, 'index.html').run();

Install sweet-electron: yarn add sweet-electron.
Copy/paste this code. Run it using electron, such as: $ electron script.js.

Sweeeeeet

Implementation

Initialization

sweet-electron requires electron to be passed as an argument when importing it. That makes it more like a wrapper. sweet() returns an instance of SweetElectron.

API

SweetElectron

  • url(String|Array[string]|Function): wrapper around loadURL
    • if String: will use it as a path directly
    • if Array[String]: will call path.join on all the arguments
    • if Function: should return a String or an Array[String]. An instance of electron-is is passed as an argument which means that you can write something like: .url((is) => is.dev() ? 'index_dev.html' : 'index.html')
  • menu(electron.Menu|Array[Object]|Function)
    • if electron.Menu: will use it directly
    • if Array[Object]: wrapper around electron.Menu.buildFromTemplate
    • if Function: will call it with an electron-is instance, the main window instance and a reference on electron.app. Should return an Array[Object] as it will be passed to electron.Menu.buildFromTemplate
  • window(Object|Function): additional options to be passed during the main window creation
    • if Function: should return an Object. Will be passed an electron-is instance as its first parameter
  • ready(Function): function called after Electron's ready event is fired. Requires a function, which will get electron-is and mainWindow parameters.
  • rendererEvents(Object{channel:callback}): will loop over each channel and register its associated callback. Each callback will get a reference to the current main window as its last parameter (e.g (event, payload, mainWindow) => { ... }). Wrapper around ipcMain. Should be combined using ipcRenderer on client-side
  • shortcuts(Object{command:callback}|Function):
    • if Object: based on globalShortcut.register
    • if Function: will get a reference on the main window as its first parameter. Should return an Object
  • on(String, Function): can listen to all of the available events on electron.app. The last argument is a reference to the current main window (e.g mainWindow => { ... }).
  • run()

Advanced Example

const electron = require('electron');
const sweet = require('sweet-electron')(electron);

/**
 * All the code has been folded inside `sweet-electron` methods for the sake of
 * the example.
 * For bigger applications, you can surely split your code into different files
 * which will help you to keep an easy-to-maintain project.
 */

sweet()
  .url(is => [__dirname, is.dev() ? 'index_dev.html' : 'index.html'])
  .window({ height: 800, transparent: true })
  .menu(app => [{ label: app.getName() }, { type: 'separator' }, { role: 'quit' }])
  .rendererEvents({
    setOpacity: (event, opacity, mainWindow) => mainWindow.setOpacity(opacity),
  })
  .run();

sweet-electron's People

Contributors

eveningkid avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

vaporwavie

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.