Skip to content

Commit

Permalink
add Auto Update demo sample
Browse files Browse the repository at this point in the history
  • Loading branch information
GregorBiswanger committed May 21, 2019
1 parent e90ef9e commit 0709d61
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 3 deletions.
31 changes: 31 additions & 0 deletions ElectronNET.WebApp/Controllers/UpdateController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Linq;
using ElectronNET.API;
using Microsoft.AspNetCore.Mvc;

namespace ElectronNET.WebApp.Controllers
{
public class UpdateController : Controller
{
public IActionResult Index()
{
if (HybridSupport.IsElectronActive)
{
Electron.IpcMain.On("auto-update", async (args) =>
{
// Electron.NET CLI Command for deploy:
// electronize build /target win /electron-params --publish=always

var currentVersion = await Electron.App.GetVersionAsync();
var updateCheckResult = await Electron.AutoUpdater.CheckForUpdatesAndNotifyAsync();
var availableVersion = updateCheckResult.UpdateInfo.Version;
string information = $"Current version: {currentVersion} - available version: {availableVersion}";

var mainWindow = Electron.WindowManager.BrowserWindows.First();
Electron.IpcMain.Send(mainWindow, "auto-update-reply", information);
});
}

return View();
}
}
}
2 changes: 1 addition & 1 deletion ElectronNET.WebApp/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public async void ElectronBootstrap()
var browserWindow = await Electron.WindowManager.CreateWindowAsync(new BrowserWindowOptions
{
Width = 1152,
Height = 864,
Height = 940,
Show = false
});

Expand Down
10 changes: 10 additions & 0 deletions ElectronNET.WebApp/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<link rel="import" href="clipboard">
<link rel="import" href="pdf">
<link rel="import" href="desktopcapturer">
<link rel="import" href="update">
</head>
<body>

Expand Down Expand Up @@ -83,6 +84,15 @@
<!-- <button type="button" id="button-protocol" data-section="protocol" class="nav-button">Launch app from <em>protocol handler</em></button> -->
</div>

<div class="nav-item u-category-update">
<h5 class="nav-category">
<svg class="nav-icon"><use xlink:href="assets/img/icons.svg#icon-update"></use></svg>
Update
</h5>
<button type="button" id="button-update" data-section="update" class="nav-button">Enable apps to <em>update</em> themselves
</button>
</div>

<div class="nav-item u-category-media">
<h5 class="nav-category">
<svg class="nav-icon"><use xlink:href="assets/img/icons.svg#icon-media"></use></svg>
Expand Down
60 changes: 60 additions & 0 deletions ElectronNET.WebApp/Views/Update/Index.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<template class="task-template">
<section id="update-section" class="section js-section u-category-update">
<header class="section-header">
<div class="section-wrapper">
<h1>
<svg class="section-icon"><use xlink:href="assets/img/icons.svg#icon-update"></use></svg>
Update
</h1>
<h3>The <code>Electron.AutoUpdater</code> allows you to automatically update your application.</h3>
<p>To publish your updates you just need simple file hosting, it does not require a dedicated server.</p>
<p>You find the sample source code in <code>Controllers\UpdateController.cs</code>.</p>
</div>
</header>

<div class="demo">
<div class="demo-wrapper">
<button id="tray-demo-toggle" class="js-container-target demo-toggle-button">
Auto Update this App
<div class="demo-meta u-avoid-clicks">Supports: Win, macOS, Linux | Process: Main</div>
</button>
<div class="demo-box">
<div class="demo-controls">
<button class="demo-button" id="btn-update">View Demo</button>
<span class="demo-response" id="demo-reply"></span>
</div>
<p>The demo button call the <code>Electron.AutoUpdater.CheckForUpdatesAndNotifyAsync()</code> in the main process.</p>

<p>This will immediately download an update, then install in the background when the app quits.</p>
<h5>Main Process (C#)</h5>
<pre><code class="csharp">Electron.IpcMain.On("auto-update", async (args) =>
{
var currentVersion = await Electron.App.GetVersionAsync();
var updateCheckResult = await Electron.AutoUpdater.CheckForUpdatesAndNotifyAsync();
var availableVersion = updateCheckResult.UpdateInfo.Version;
string information = $"Current version: {currentVersion} - available version: {availableVersion}";

var mainWindow = Electron.WindowManager.BrowserWindows.First();
Electron.IpcMain.Send(mainWindow, "auto-update-reply", information);
});
</code></pre>
</div>
</div>
</div>

<script>
(function(){
const { ipcRenderer } = require("electron");
document.getElementById("btn-update").addEventListener("click", () => {
ipcRenderer.send("auto-update");
});
ipcRenderer.on('auto-update-reply', (event, message) => {
document.getElementById('demo-reply').innerHTML = message;
});
}());
</script>

</section>
</template>
1 change: 1 addition & 0 deletions ElectronNET.WebApp/wwwroot/assets/css/variables.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@
.u-category-native-ui { --color-accent: hsl(222, 53%, 50%); }
.u-category-communication { --color-accent: hsl(285, 47%, 46%); }
.u-category-system { --color-accent: hsl(330, 65%, 48%); }
.u-category-update { --color-accent: hsl(0, 92%, 43%); }
.u-category-media { --color-accent: hsl( 36, 77%, 34%); }
6 changes: 4 additions & 2 deletions ElectronNET.WebApp/wwwroot/assets/img/icons.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0709d61

Please sign in to comment.