任务栏的进度条 (Windows, macOS, Unity)
在 Windows 中的任务栏按钮可以被用于显示一个进度条。 这可以让一个窗口提供进度信息给用户,而不必切自行切换到这个窗口。
在 macOS,进度条将显示为 dock 图标的一部分。
Unity DE 也具有同样的特性,在运行器上显示进度条。
任务栏按钮中的进度栏:
三个系统中都是用相同的API - setProgressBar()
方法是 BrowserWindows
的方法。 是用 0
到 1
之间的数字来表示你的进度。 你正在运行一个长时间的任务, 当前进度为63%, 您可以使用 setProgressBar(0.63)
来调用它。
一般来说,将参数设置为 0 以下的值(例如 -1
)将会去掉进度条,而设置为 1 以上(例如 2
)将会切换这个进度条为不确定的进度。
参见 API documentation for more options and modes。
const { BrowserWindow } = require('electron')
const win = new BrowserWindow()
win.setProgressBar(0.5)
Progress Bar in Taskbar (Windows, macOS, Unity)
On Windows a taskbar button can be used to display a progress bar. This enables a window to provide progress information to the user without the user having to switch to the window itself.
On macOS the progress bar will be displayed as a part of the dock icon.
The Unity DE also has a similar feature that allows you to specify the progress bar in the launcher.
Progress bar in taskbar button:
All three cases are covered by the same API - the setProgressBar()
method available on instances of BrowserWindows
. Call it with a number between 0
and 1
to indicate your progress. If you have a long-running task that's currently at 63% towards completion, you'd call it with setProgressBar(0.63)
.
Generally speaking, setting the parameter to a value below zero (like -1
) will remove the progress bar while setting it to a value higher than one (like 2
) will switch the progress bar to intermediate mode.
See the API documentation for more options and modes.
const { BrowserWindow } = require('electron')
const win = new BrowserWindow()
win.setProgressBar(0.5)