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

electron-progressbar-custom

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

electron-progressbar-custom

Progress bar component for Electron applications

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

npm Hits

electron-progressbar

electron-progressbar provides an easy-to-use and highly customizable API to show and control progress bars on Electron applications.

You can customize the aspects of the windows (electron's BrowserWindow), progress bars' visual aspects (CSS), texts and also all visible information.

NPM

Demo

Indeterminate progress bar:
Indeterminate progress bar

Determinate progress bar:
Determinate progress bar

Additionally, as of electron-progressbar v1.1.0, a progress bar is automatically added to the taskbar (through BrowserWindow's setProgressBar). This enables a window to provide progress information to the user without the user having to switch to the window itself.

taskbar for indeterminate progress bar:
Taskbar for indeterminate progress bar

taskbar for determinate progress bar:
Taskbar for determinate progress bar


Table of Contents

Installation

Install with npm:

$ npm install electron-progressbar --save

Examples

Indeterminate progress bar

Example of an indeterminate progress bar - used when your application can't calculate how long the task will last:

Indeterminate progress bar

const {app} = require('electron');
const ProgressBar = require('electron-progressbar');

app.on('ready', function() {
  var progressBar = new ProgressBar({
    text: 'Preparing data...',
    detail: 'Wait...'
  });
  
  progressBar
    .on('completed', function() {
      console.info(`completed...`);
      progressBar.detail = 'Task completed. Exiting...';
    })
    .on('aborted', function() {
      console.info(`aborted...`);
    });
  
  // launch a task...
  // launchTask();
  
  // when task is completed, set the progress bar to completed
  // ps: setTimeout is used here just to simulate an interval between the start and the end of a task
  setTimeout(function() {
    progressBar.setCompleted();
  }, 3000);
});

Determinate progress bar

Example of a determinate progress bar - used when your application can accurately calculate how long the task will last:

Determinate progress bar

const {app} = require('electron');
const ProgressBar = require('electron-progressbar');

app.on('ready', function() {
  var progressBar = new ProgressBar({
    indeterminate: false,
    text: 'Preparing data...',
    detail: 'Wait...'
  });
  
  progressBar
    .on('completed', function() {
      console.info(`completed...`);
      progressBar.detail = 'Task completed. Exiting...';
    })
    .on('aborted', function(value) {
      console.info(`aborted... ${value}`);
    })
    .on('progress', function(value) {
      progressBar.detail = `Value ${value} out of ${progressBar.getOptions().maxValue}...`;
    });
  
  // launch a task and set the value of the progress bar each time a part of the task is done;
  // the progress bar will be set as completed when it reaches its maxValue (default maxValue: 100);
  // ps: setInterval is used here just to simulate a task being done
  setInterval(function() {
    if(!progressBar.isCompleted()){
      progressBar.value += 1;
    }
  }, 20);
});

More examples in folder examples.

API

Methods

new ProgressBar(options, [electronApp])

Create a new progress bar. Because electron's BrowserWindow is used to display the progress bar and it only works after electron's "ready" event, you have wait for the "ready" event before creating a progress bar; optionally, you can just pass electron's app as a second parameter (electronApp).

ParamTypeDefaultDescription
[options]objectelectron-progressbar options
[options.abortOnError]booleanfalseWhether progress bar should abort and close if an error occurs internally.
[options.indeterminate]booleantrueWhether progress bar should be indeterminate. If false, progress bar will be determinate.
[options.initialValue]number0Progress bar's initial value. Used only for determinate progress bar.
[options.maxValue]number100Progress bar's maximum value. When progress bar's value reaches this number, it will be set as completed and event complete will be fired. Used only for determinate progress bar.
[options.closeOnComplete]booleantrueWhether progress bar window should be automatically closed after completed. If false, the progress bar must be manually closed by calling its close method.
[options.title]string'Wait...'Text shown on title bar.
[options.text]string'Wait...'Text shown inside the window and above the progress bar.
[options.detail]stringText shown between text and the progress bar element. Used to display the current status, i.e., what part of the whole task is being done. Usually setting this property later is more useful because your application can determine and display, in real time, what is currently happening.
[options.style]objectVisual styles for elements: text, detail, bar and value. All elements' properties are purely CSS, just the way it is used in a CSS file.
[options.style.text]objectAn object containing any CSS properties for styling the text element.
[options.style.detail]objectAn object containing any CSS properties for styling the detail element.
[options.style.bar]object{'width':'100%', 'background-color':'#BBE0F1'}An object containing any CSS properties for styling the bar in the progress bar.
[options.style.value]object{'background-color':'#0976A9'}An object containing any CSS properties for styling the value in the progress bar.
[options.browserWindow]objectElectron's BrowserWindow options. Although only a few properties are used per default, you can specify any of Electron's BrowserWindow options.
[options.browserWindow.parent]instance of BrowserWindownullA BrowserWindow instance. If informed, the progress bar window will always show on top of the parent window and will block it so user can't interact with it until the progress bar is completed/aborted and closed.
[options.browserWindow.modal]booleantrueWhether this is a modal window. This actually only works if progress bar window is a child window, i.e., when its parent is informed.
[options.browserWindow.resizable]booleanfalseWhether window is resizable.
[options.browserWindow.closable]booleanfalseWhether window is closable.
[options.browserWindow.minimizable]booleanfalseWhether window is minimizable.
[options.browserWindow.maximizable]booleanfalseWhether window is maximizable.
[options.browserWindow.width]number450Progress bar window's width in pixels.
[options.browserWindow.height]number175Progress bar window's height in pixels.

getOptions()object

Return a copy of all current options.


on(eventName, listener)reference to this

Adds the listener function to the end of the listeners array for the event named eventName. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of eventName and listener will result in the listener being added, and called, multiple times.

Returns a reference to this so that calls can be chained.

Events

Event nameReceives parameterDescription
readyFired when progress bar is created and ready to be used and controlled.
progressvalueAvailable only for determinate progress bar. Fired every time the progress bar's value is changed. The listener receives, as first parameter, the current progress bar's value.
completedvalueFired when progress bar is completed, i.e., its value reaches maxValue or method complete is called. The listener receives, as first parameter, the current progress bar's value.
abortedvalueFired if progress bar is closed when it's not completed yet, i.e., when user closes progress bar window or method close is called before progress bar is completed. The listener receives, as first parameter, the current progress bar's value.

setCompleted()

Set progress bar as complete. This means the whole task is finished.

If progress bar is indeterminate, a manual call to this method is required because it's the only way to complete the task and trigger the complete event, otherwise the progress bar would be displayed forever.


close()

Close progress bar window. If progress bar is not completed yet, it'll be aborted and event aborted will be fired.


isInProgress()boolean

Return true if progress bar is currently in progress, i.e., it hasn't been completed nor aborted yet, otherwise false.


isCompleted()boolean

Return true if progress bar is completed, otherwise false.


Properties

valuenumber

Get or set progress bar's value. Only available for determinate progress bar.


textstring

Get or set the text. This information is shown inside the window and above the progress bar.


detailstring

Get or set the detail. This information is shown between text and the progress bar element. Useful to display the current status in real time, i.e., what part of the whole task is being done, what is currently happening.


License

MIT. See LICENSE.md for details.

Keywords

FAQs

Package last updated on 03 Jun 2019

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