forked from ElectronNET/Electron.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e90ef9e
commit 0709d61
Showing
6 changed files
with
107 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.