Gathering detailed insights and metrics for electron-progressbar-customhtml
Gathering detailed insights and metrics for electron-progressbar-customhtml
Gathering detailed insights and metrics for electron-progressbar-customhtml
Gathering detailed insights and metrics for electron-progressbar-customhtml
electron-progressbar
The original Progress Bar component for Electron applications
react-circular-progressbar
A circular progress indicator component
electron-to-chromium
Provides a list of electron-to-chromium version mappings
native-progress-bar
This module allows your Electron app to display native dialogs with progress bars in them on Windows and macOS.
npm install electron-progressbar-customhtml
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
8 Commits
1 Watching
1 Branches
2 Contributors
Updated on 15 Jul 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
700%
8
Compared to previous week
Last month
10%
11
Compared to previous month
Last year
0%
609
Compared to previous year
1
| Your help is appreciated! Create a PR or just buy me a coffee |
---|
electron-progressbar provides an easy-to-use and highly customizable API, to show and manipulate progress bars on Electron applications.
With electron-progressbar, you can easily customize the appearance of the progress bars, including the visual aspects using CSS, as well as the text and any other visible information. Additionally, the library allows for customization of the Electron BrowserWindow that contains the progress bars.
Determinate progress bar:
In addition to displaying progress bars within the window, electron-progressbar also enables progress bars to be displayed in the taskbar using the BrowserWindow's setProgressBar method. This feature allows the user to view progress information without needing to switch to the window itself.
example of the taskbar for an indeterminate progress bar:
example of the taskbar for a determinate progress bar:
Methods
.new ProgressBar(options, [electronApp])
.getOptions()
⇒ object
.on(eventName, listener)
⇒ reference to this
.setCompleted()
.close()
.isInProgress()
⇒ boolean
.isCompleted()
⇒ boolean
Properties
Install with npm
:
1$ npm i electron-progressbar
Example of an indeterminate progress bar - this progress bar is useful when your application cannot calculate how long the task will take to complete:
1const {app} = require('electron'); 2const ProgressBar = require('electron-progressbar'); 3 4app.on('ready', function() { 5 var progressBar = new ProgressBar({ 6 text: 'Preparing data...', 7 detail: 'Wait...' 8 }); 9 10 progressBar 11 .on('completed', function() { 12 console.info(`completed...`); 13 progressBar.detail = 'Task completed. Exiting...'; 14 }) 15 .on('aborted', function() { 16 console.info(`aborted...`); 17 }); 18 19 // launch a task... 20 // launchTask(); 21 22 // when task is completed, set the progress bar to completed 23 // ps: setTimeout is used here just to simulate an interval between 24 // the start and the end of a task 25 setTimeout(function() { 26 progressBar.setCompleted(); 27 }, 3000); 28});
Example of a determinate progress bar - this progress bar is useful when your application can accurately calculate how long the task will take to complete:
1const {app} = require('electron'); 2const ProgressBar = require('electron-progressbar'); 3 4app.on('ready', function() { 5 var progressBar = new ProgressBar({ 6 indeterminate: false, 7 text: 'Preparing data...', 8 detail: 'Wait...' 9 }); 10 11 progressBar 12 .on('completed', function() { 13 console.info(`completed...`); 14 progressBar.detail = 'Task completed. Exiting...'; 15 }) 16 .on('aborted', function(value) { 17 console.info(`aborted... ${value}`); 18 }) 19 .on('progress', function(value) { 20 progressBar.detail = `Value ${value} out of ${progressBar.getOptions().maxValue}...`; 21 }); 22 23 // launch a task and increase the value of the progress bar for each step completed of a big task; 24 // the progress bar is set to completed when it reaches its maxValue (default maxValue: 100); 25 // ps: setInterval is used here just to simulate the progress of a task 26 setInterval(function() { 27 if(!progressBar.isCompleted()){ 28 progressBar.value += 1; 29 } 30 }, 20); 31});
Example of a custom progress bar - This option can be useful when you create your own custom HTML:
1const {app} = require('electron'); 2const ProgressBar = require('electron-progressbar'); 3 4const customHTML = `<!DOCTYPE html> 5<html lang="en-us"> 6<head> 7 <meta charset="UTF-8"> 8 <style> 9 * { 10 margin: 0; 11 padding: 0; 12 box-sizing: border-box; 13 } 14 15 html, 16 body { 17 width: 100%; 18 height: 100%; 19 } 20 21 body, 22 table { 23 word-break: break-word; 24 word-wrap: break-word; 25 } 26 27 body { 28 display: flex; 29 flex-direction: column; 30 align-items: center; 31 justify-content: center; 32 margin: 0; 33 padding: 0 50px; 34 margin-bottom: 0; 35 } 36 37 (...) 38 </style> 39</head> 40 41<body> 42 <div id="text"></div> 43 <div id="detail"></div> 44 <div id="progressBarContainer"></div> 45 <script> 46 47 var currentValue = { 48 progress: null, 49 text: null, 50 detail: null 51 }; 52 53 var elements = { 54 text: document.querySelector("#text"), 55 detail: document.querySelector("#detail"), 56 progressBarContainer: document.querySelector("#progressBarContainer"), 57 progressBar: null // set by createProgressBar() 58 }; 59 60 function createProgressBar(settings) { 61 62 if (settings.indeterminate) { 63 var progressBar = document.createElement("div"); 64 progressBar.setAttribute("id", "progressBar"); 65 progressBar.setAttribute("indeterminate", "t"); 66 67 var progressBarValue = document.createElement("div"); 68 progressBarValue.setAttribute("id", "progressBarValue"); 69 progressBar.appendChild(progressBarValue); 70 71 elements.progressBar = progressBar; 72 elements.progressBarContainer.appendChild(elements.progressBar); 73 } else { 74 var progressBar = document.createElement("progress"); 75 progressBar.setAttribute("id", "progressBar"); 76 progressBar.max = settings.maxValue; 77 78 elements.progressBar = progressBar; 79 elements.progressBarContainer.appendChild(elements.progressBar); 80 } 81 82 elements.text.innerHTML = currentValue.text; 83 elements.detail.innerHTML = currentValue.detail; 84 85 window.requestAnimationFrame(synchronizeUi); 86 } 87 88 function synchronizeUi() { 89 elements.progressBar.value = currentValue.progress; 90 window.requestAnimationFrame(synchronizeUi); 91 } 92 const settings = { 93 abortOnError: false, 94 debug: false, 95 96 indeterminate: true, 97 initialValue: 0, 98 maxValue: 100, 99 closeOnComplete: true, 100 title: 'Wait...', 101 text: 'Wait...', 102 detail: null, 103 lang: '', 104 customHTML: '', 105 106 style: { 107 text: {}, 108 detail: {}, 109 bar: { 110 'width': '100%', 111 'background': '#BBE0F1' 112 }, 113 value: { 114 'background': '#0976A9' 115 } 116 }, 117 118 browserWindow: { 119 parent: null, 120 modal: true, 121 resizable: false, 122 closable: false, 123 minimizable: false, 124 maximizable: false, 125 width: 500, 126 height: 170, 127 webPreferences: { 128 nodeIntegration: true, 129 contextIsolation: false, 130 }, 131 }, 132 133 remoteWindow: null 134 }; 135 136 ipcRenderer.on("CREATE_PROGRESS_BAR", (event, settings) => { 137 createProgressBar(settings); 138 }); 139 140 ipcRenderer.on("SET_PROGRESS", (event, value) => { 141 currentValue.progress = value; 142 }); 143 144 ipcRenderer.on("SET_COMPLETED", (event) => { 145 elements.progressBar.classList.add('completed'); 146 }); 147 148 ipcRenderer.on("SET_TEXT", (event, value) => { 149 currentValue.text = value; 150 }); 151 152 ipcRenderer.on("SET_DETAIL", (event, value) => { 153 currentValue.detail = value; 154 }); 155 </script> 156</body> 157 158</html> 159 160` 161 162app.on('ready', function() { 163 var progressBar = new ProgressBar({ 164 indeterminate: false, 165 customHTML: customHTML 166 }); 167 168 progressBar 169 .on('completed', function() { 170 console.info(`completed...`); 171 progressBar.detail = 'Task completed. Exiting...'; 172 }) 173 .on('aborted', function(value) { 174 console.info(`aborted... ${value}`); 175 }) 176 .on('progress', function(value) { 177 progressBar.detail = `Value ${value} out of ${progressBar.getOptions().maxValue}...`; 178 }); 179 180 181 // Please Note Indeterminate progress bar example or Determinate progress bar example. 182});
More examples are available in folder examples.
Methods
new ProgressBar(options, [electronApp])
Create a new progress bar. It's necessary to wait for the ready
event to be emitted by Electron's BrowserWindow, since the progress bar is displayed within it. Optionally, you can pass the electron app as a second parameter (parameter electronApp
) when creating the progress bar. Check the sample code on this page for detailed examples on how to set properties to options
.
You can define most of the characteristics of the progress bar using the options
parameter. Below is a list of properties that you can set for the options
parameter.
Option name | Type | Default value | Description |
---|---|---|---|
debug | boolean | false | Specifies whether debugging should be enabled. If set to true , the browser's DevTools panel will automatically open when the progress bar is created. This can be helpful when debugging and/or dealing with issues. |
abortOnError | boolean | false | Specifies whether the progress bar should automatically abort and close if an error occurs internally. |
indeterminate | boolean | true | Specifies whether the progress bar should be indeterminate. If set to false, the progress bar will be determinate. |
initialValue | number | 0 | The initial value for the progress bar. This parameter is only applicable for determinate progress bars. |
maxValue | number | 100 | The maximum value for the progress bar. When the progress bar's value reaches this number, the progress bar will be considered complete and the complete event will be fired. This parameter is only applicable for determinate progress bars. |
closeOnComplete | boolean | true | Specifies whether the progress bar window should be automatically closed after the progress bar completes. If set to false , the progress bar will remain visible until the close method is called by your application. |
lang | string | empty | Specifies the value for the lang attribute of the BrowserWindow's <html> tag. This option has no default value, and the lang attribute is only added to <html> when lang is explicitly set. This option can also be helpful in case of font rendering issues. |
customHTML | string | empty | This is a function that allows you to display a progressbar by customizing HTML. You can insert the entire HTML code starting with the <html> tag in the customHTML attribute. Please insert the contents within the <body> tag by referring to the example. |
title | string | "Wait..." | Specifies the text shown on the progress bar window's title bar. |
text | string | "Wait..." | Specifies the text shown inside the progress bar window, next to the progress bar. |
detail | string | empty | Specifies the text shown between text and the progress bar element. It can be used to display detailed information, such as the current progress of a task. When used for this purpose, it is usually more useful to set this property later so that your application can calculate and display, in real time, the current progress of the task. |
style | object | Specifices the visual styles for the text , detail , bar , and value elements. All properties and values are pure CSS format, in the exact same way they would be used in a CSS file . Check the options for style below. | |
style.text | object | An object containing CSS properties for styling the text element. | |
style.detail | object | An object containing CSS properties for styling the detail element. | |
style.bar | object | {"width":"100%", "background-color":"#BBE0F1"} | An object containing CSS properties for styling the bar element of the progress bar. |
style.value | object | {"background-color":"#0976A9"} | An object containing CSS properties for styling the value element in the progress bar. |
remoteWindow | instance of BrowserWindow | null | Specifies the BrowserWindow where the progress bar will be displayed. If null/undefined/empty or not specified, a new BrowserWindow will be created to show the progress bar. |
browserWindow | object | Specifies the options for Electron's BrowserWindow . Check the options for browserWindow below. P.S.: although only a few options are set by default, you can specify any of Electron's BrowserWindow options. | |
browserWindow.parent | instance of BrowserWindow | null | A BrowserWindow instance to be used as the parent of the progress bar's window. If specified, the progress bar window will always be on top of the given parent window and will block user interaction in parent window until the progress bar is completed (or aborted) and closed. |
browserWindow.modal | boolean | true | Specifies whether the progress bar's window is a modal window. Note that this property only works when the progress bar's window is a child window, i.e., when browserWindow.parent is specified. |
browserWindow.resizable | boolean | false | Specifies whether the user can resize the progress bar's window. |
browserWindow.closable | boolean | false | Specifies whether the user can close the progress bar's window. |
browserWindow.minimizable | boolean | false | Specifies whether the user can minimize the progress bar's window. |
browserWindow.maximizable | boolean | false | Specifies whether the user can maximize the progress bar's window. |
browserWindow.width | number | 450 | Specifies the width of the progress bar's window in pixels. Only numeric values are accepted, for example: 600. |
browserWindow.height | number | 175 | Specifies the height of the progress bar's window in pixels. Only numeric values are accepted, for example: 600. |
browserWindow .webPreferences.nodeIntegration | boolean | true | Specifies whether node integration is enabled. |
browserWindow .webPreferences.contextIsolation | boolean | false | Specifies whether contextIsolation is enabled. |
getOptions()
⇒ object
Return a copy of all the current options.
on(eventName, listener)
⇒ reference to this
Add the listener function to the end of the listeners array for the event named eventName
, and then return a reference to this
so that next calls can be chained.
P.S.: there are no checks to verify if listener
has already been added. If you call the same combination of eventName
and listener
multiple times, the listener
will be added and executed multiple times as well.
setCompleted()
Set the progress bar as complete, indicating that the task has finished.
If progress bar is indeterminate, a manual call to this method is required since it's the only way to trigger the completed
event and indicate that the task has finished. Otherwise, the progress bar will continue to be displayed indefinitely.
close()
Close the progress bar window. If progress bar has not been completed yet, it will be aborted, and the aborted
event will be fired.
isInProgress()
⇒ boolean
Return true
if the progress bar is currently in progress, meaning that it has not been completed or aborted yet; otherwise it will return false
;
isCompleted()
⇒ boolean
Return true
if the progress bar is completed, otherwise false
.
Properties
value
⇒ number
This property allows getting or setting the progress bar's current value. It is only applicable and available for determinate progress bars.
text
⇒ string
This property allows getting or setting the progress bar's text
information that is shown above the progress bar element.
detail
⇒ string
This property allows getting or setting the progress bar's detail
information that is shown between text
and the progress bar element. Useful to display detailed information, such as the current status, in real time, or the current progress of the task.
MIT. See LICENSE.md for details.
No vulnerabilities found.
No security vulnerabilities found.