native-progress-bar
v1.0.3
Published
This module allows your Electron app to display native dialogs with progress bars in them on Windows and macOS.
Downloads
23,142
Maintainers
Readme
native-progress-bar
This module allows your Electron app to display native dialogs with progress bars in them on Windows and macOS.
It has no dependencies other than binding
and creates a ~85KB Node addon.
To see various examples for progress bars, check out test/src/progress-bars.js
.
Screenshots
Application required (macOS)
On macOS, the module only works in Node.js environments that run within a proper application (like Electron).
It therefore does not run in simple Node.js scripts that you might execute with node myscript.js
.
API
import { ProgressBar } from "native-progress-bar"
let progressBar, interval;
// All arguments are optional
progressBar = new ProgressBar({
// Window title
title: "Running disk operation",
// Message, shown above the progress bar
message: "Running format C:",
// Initial progress value
progress: 0,
// Can be "hud", "utility", or "default". Only of effect on macOS.
style: "hud"
// Zero or more buttons
buttons: [{
label: "Cancel",
click: (progressBar) => {
console.log("Cancel button clicked");
progressBar.close();
}
}],
// A function called when the dialog is closed. Useful to cleanup intervals.
onClose: () => {
clearInterval(interval);
},
});
interval = setInterval(() => {
if (progressBar.progress >= 100) {
clearInterval(interval);
// You can dynamically change buttons
progressBar.buttons = [{
label: "Done",
click: (progressBar) => {
console.log("Done button clicked");
progressBar.close();
}
}]
return
}
progressBar.progress += 1;
}, 200);
What about Linux?
I didn't need Linux but I'd welcome PRs implementing it there.