进度条
概览
进度条使窗口能够向用户提供其进度信息,而无需被切换到前台。
在Windows环境下,进度条被显示在任务栏按钮上。
在MacOS环境下,进度条将被显示在dock栏图标上
在Linux系统中,Unity桌面也有相似的特性,能在Launcher上显示进度条。
注意:在 Windows 上,每个窗口都可以有自己的进度条,而在 macOS 和 Linux(unity桌面)上,同一个应用程序只能有一个进度条。
All three cases are covered by the same API - the setProgressBar() method available on an instance of BrowserWindow. 此方法以介于 0 和 1 之间的小数表示进度。 例如,如果有一个耗时很长的任务,它当前的进度是63%,那么你可以用setProgressBar(0.63)来显示这一进度。
将参数设置为负值 (例如, -1) 将删除progress bar。 设定值大于 1 在 Windows 中将表示一个不确定的进度条 ,或在其他操作系统中显示为 100%。 一个不确定的progress bar 仍然处于活动状态,但不显示实际百分比, 并且用于当 您不知道一个操作需要多长时间才能完成的情况。
See the API documentation for more options and modes.
示例
在此示例中,我们将进度栏添加到main window中,该窗口会使用node.js的计时器实现随着时间的推移而进度增长。
<title>Hello World!</title>
<metahttp-equiv="Content-Security-Policy"content="script-src 'self' 'unsafe-inline';"/>
</head>
<body>
<h1>Hello World!</h1>
<p>Keep an eye on the dock (Mac) or taskbar (Windows, Unity) for this application!</p>
<p>It should indicate a progress that advances from 0 to 100%.</p>
<p>It should then show indeterminate (Windows) or pin at 100% (other operating systems)
briefly and then loop.</p>
</body>
</html>