Skip to content

Commit 23279f7

Browse files
Merge pull request #16 from BorisTheBrave/progress-bar-demo
Adds a demonstration of BrowserWindow.SetProgressBar.
2 parents 1fa77b9 + 2e9cbf5 commit 23279f7

File tree

4 files changed

+101
-1
lines changed

4 files changed

+101
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using ElectronNET.API;
2+
using Microsoft.AspNetCore.Mvc;
3+
using System.Linq;
4+
5+
namespace ElectronNET_API_Demos.Controllers
6+
{
7+
public class ProgressBarController : Controller
8+
{
9+
public IActionResult Index()
10+
{
11+
if (HybridSupport.IsElectronActive)
12+
{
13+
Electron.IpcMain.On("set-progress-bar", async (args) =>
14+
{
15+
var mainWindow = Electron.WindowManager.BrowserWindows.First();
16+
mainWindow.SetProgressBar(0.5);
17+
});
18+
19+
Electron.IpcMain.On("clear-progress-bar", async (args) =>
20+
{
21+
var mainWindow = Electron.WindowManager.BrowserWindows.First();
22+
mainWindow.SetProgressBar(-1);
23+
});
24+
}
25+
26+
return View();
27+
}
28+
}
29+
}

ElectronNET-API-Demos/Views/Home/Index.cshtml

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<link rel="import" href="appsysinformation">
2626
<link rel="import" href="clipboard">
2727
<link rel="import" href="pdf">
28+
<link rel="import" href="progressbar">
2829
<link rel="import" href="desktopcapturer">
2930
</head>
3031
<body>
@@ -61,6 +62,7 @@
6162
<button type="button" id="button-notifications" data-section="notifications" class="nav-button"> Notifications with and without custom <em>image</em></button>
6263
<button type="button" id="button-dialogs" data-section="dialogs" class="nav-button">Use system <em>dialogs</em></button>
6364
<button type="button" id="button-tray" data-section="tray" class="nav-button">Put your app in the <em>tray</em></button>
65+
<button type="button" id="button-progress-bar" data-section="progress-bar" class="nav-button">Show <em>progress</em></button>
6466
</div>
6567

6668
<div class="nav-item u-category-communication">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<template class="task-template">
2+
<section id="progress-bar-section" class="section js-section u-category-native-ui">
3+
<header class="section-header">
4+
<div class="section-wrapper">
5+
<h1>
6+
Set Progress Bar
7+
</h1>
8+
<h3>The <code>BrowserWindow.SetProgressBar</code> method in Electron.NET allows you set a progress bar that appers in the task bar.</h3>
9+
10+
<p>This module works in the main process.</p>
11+
12+
<p>You find the sample source code in <code>Controllers\ProgressBarController.cs</code>.</p>
13+
</div>
14+
</header>
15+
16+
<div class="demo">
17+
<div class="demo-wrapper">
18+
<button id="set-progress-bar-toggle" class="js-container-target demo-toggle-button">
19+
Set the Progress Bar in Taskbar
20+
<div class="demo-meta u-avoid-clicks">Supports: Win, macOS, Linux (Unity only)<span class="demo-meta-divider">|</span> Process: Main</div>
21+
</button>
22+
<div class="demo-box">
23+
<div class="demo-controls">
24+
<button class="demo-button" id="set-progress-bar">View Demo</button>
25+
</div>
26+
<p>This demonstrates using the <code>BrowserWindow.SetProgressBar</code> to set the window's progress.</p>
27+
<p>Clicking the demo button will set the progress to 50%.</p>
28+
<h5>Main Process (C#)</h5>
29+
<pre><code class="csharp">var mainWindow = Electron.WindowManager.BrowserWindows.First();
30+
mainWindow.SetProgressBar(0.5);</code></pre>
31+
</div>
32+
</div>
33+
</div>
34+
35+
<div class="demo">
36+
<div class="demo-wrapper">
37+
<button id="clear-progress-bar-toggle" class="js-container-target demo-toggle-button">
38+
Clear the Progress Bar from Taskbar
39+
<div class="demo-meta u-avoid-clicks">Supports: Win, macOS, Linux (Unity only)<span class="demo-meta-divider">|</span> Process: Main</div>
40+
</button>
41+
<div class="demo-box">
42+
<div class="demo-controls">
43+
<button class="demo-button" id="clear-progress-bar">View Demo</button>
44+
</div>
45+
<p>This demonstrates using the <code>BrowserWindow.SetProgressBar</code> to clear the window's progress.</p>
46+
<h5>Main Process (C#)</h5>
47+
<pre><code class="csharp">var mainWindow = Electron.WindowManager.BrowserWindows.First();
48+
mainWindow.SetProgressBar(-1);</code></pre>
49+
</div>
50+
</div>
51+
</div>
52+
53+
<script>
54+
(function () {
55+
const { ipcRenderer } = require("electron");
56+
57+
document.getElementById("set-progress-bar").addEventListener("click", () => {
58+
ipcRenderer.send("set-progress-bar");
59+
});
60+
61+
document.getElementById("clear-progress-bar").addEventListener("click", () => {
62+
ipcRenderer.send("clear-progress-bar");
63+
});
64+
}());
65+
</script>
66+
67+
68+
</section>
69+
</template>

ElectronNET-API-Demos/Views/Shell/Index.cshtml

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ await Electron.Shell.ShowItemInFolderAsync(path);</code></pre>
4747
<p>When the demo button is clicked, the electron website will open in your browser.<p>
4848
<h5>Main Process (C#)</h5>
4949
<pre><code class="csharp">await Electron.Shell.OpenExternalAsync("https://github.com/ElectronNET");</code></pre>
50+
</div>
5051
</div>
5152
</div>
52-
</div>
5353

5454
<script>
5555
(function(){

0 commit comments

Comments
 (0)