Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

electron-window

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

electron-window

Convenience methods for Electron windows.

  • 0.6.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
24K
increased by31.72%
Maintainers
1
Weekly downloads
 
Created
Source

electron-window

Convenience methods for Electron windows.

Installation

npm i --save electron-window

Usage

TL;DR:

electron-window converts this:

var app = require('app')
var path = require('path')
var url = require('url')
var BrowserWindow = require('browser-window')

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the javascript object is GCed.
var mainWindow = null

app.on('ready', function () {
  mainWindow = new BrowserWindow({ width: 1000, height: 400, show: false })

  var someArgs = { data: 'hi' }
  var indexPath = path.resolve(__dirname, '..', 'weird-location', 'index.html')
  var indexUrl = url.format({
    protocol: 'file',
    pathname: indexPath,
    slashes: true,
    hash: encodeURIComponent(JSON.stringify(someArgs))
  })

  mainWindow.on('closed', function() {
    mainWindow = null
  })

  mainWindow.webContents.on('did-finish-load', function() {
    mainWindow.show()
    console.log('window is now visible!')
  })

  mainWindow.loadUrl(indexUrl)
})

to this:

var app = require('app')
var path = require('path')
var window = require('electron-window')

app.on('ready', function () {
  var mainWindow = window.createWindow({width: 1000, height: 400})
  var someArgs = { data: 'hi' }
  var indexPath = path.resolve(__dirname, '..', 'weird-location', 'index.html')
  mainWindow.showUrl(indexPath, someArgs, function () {
    console.log('window is now visible!')
  })
})

API Methods

createWindow(options)

Class method that creates a new BrowserWindow with the following default options: {show: false}. No need to worry about keeping a global reference to prevent garbage collection, this is handled for you.

parseArgs()

Instance method to parse arguments in window. You would only need to call from your renderer preload script if you pass in preload.

showUrl(httpOrFileUrl, [argsForRenderer], [callback])

Instance method that shows the url. When the url is finished loading, the callback is returned. If the optional argsForRenderer is set then __args__ will be a global object for the page in the renderer process. This is a convenient way to pass arguments from the main process to the renderer process.

unref()

Instance method to call if you ever want to remove the global reference. Should only need to be called if destroy() is ever called. Most likely, you won't need to use this.

API Properties

windows

Class property to get a reference to all windows created and their ids.

Example

main process

var window = require('electron-window')

var windowOptions = {
 width: 1000,
 height: 400
}
var mainWindow = window.createWindow(windowOptions)

// can access at window.__args__ from scripts
// ran from index.html
var args = {
  data: 'some secret data'
}
mainWindow.showUrl('index.html', args, function() {
  console.log('the window should be showing with the contents of the URL now')
})

renderer process

// only call if `preload` is set in `windowOptions`
require('electron-window').parseArgs()

console.log(window.__args__)
// => Object {data: "some secret data"}

License

MIT

Keywords

FAQs

Package last updated on 08 Apr 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc