Skip to content

Commit

Permalink
941 Handle offline installation
Browse files Browse the repository at this point in the history
stevencohn#941
handle offline installation
  • Loading branch information
stevencohn committed Sep 5, 2023
1 parent 37bc85e commit b0fea38
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 0 deletions.
11 changes: 11 additions & 0 deletions OneMore/Commands/File/ImportWebCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace River.OneMoreAddIn.Commands
{
using Microsoft.Win32;
using River.OneMoreAddIn.Models;
using River.OneMoreAddIn.UI;
using System;
Expand Down Expand Up @@ -37,6 +38,9 @@ namespace River.OneMoreAddIn.Commands
/// </summary>
internal class ImportWebCommand : Command
{
private const string ClientKey = @"SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients";
private const string RuntimeId = "{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}";

private sealed class WebPageInfo
{
public string Content;
Expand All @@ -62,6 +66,13 @@ public override async Task Execute(params object[] args)
return;
}

var key = Registry.LocalMachine.OpenSubKey($"{ClientKey}\\{RuntimeId}");
if (key == null)
{
UIHelper.ShowError("Unable to use this command; Edge WebView2 is not installed");
return;
}

using (var dialog = new ImportWebDialog())
{
if (dialog.ShowDialog(owner) != DialogResult.OK)
Expand Down
Binary file modified OneMore/Properties/AssemblyInfo.cs
Binary file not shown.
Binary file modified OneMoreCalendar/Properties/AssemblyInfo.cs
Binary file not shown.
Binary file modified OneMoreProtocolHandler/Properties/AssemblyInfo.cs
Binary file not shown.
Binary file modified OneMoreSetup/OneMoreSetup.vdproj
Binary file not shown.
42 changes: 42 additions & 0 deletions OneMoreSetupActions/Actions/EdgeWebViewAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace OneMoreSetupActions
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Net.NetworkInformation;
using System.Text.RegularExpressions;
using System.Threading;

Expand Down Expand Up @@ -55,8 +56,15 @@ public override int Install()
Path.GetTempPath(),
Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + ".exe");

if (!IsNetworkAvailable())
{
logger.WriteLine("no internet connection; skipping WebView2 installation");
return SUCCESS;
}

if (!DownloadBootstrap(bootstrap))
{
logger.WriteLine("unable to download WebView2 bootstrap installer");
return FAILURE;
}

Expand Down Expand Up @@ -91,6 +99,40 @@ public override int Install()
}


private static bool IsNetworkAvailable()
{
// only recognizes changes related to Internet adapters
if (NetworkInterface.GetIsNetworkAvailable())
{
// however, this will include all adapters
var interfaces = NetworkInterface.GetAllNetworkInterfaces();
foreach (var face in interfaces)
{
// filter so we see only Internet adapters
if (face.OperationalStatus == OperationalStatus.Up)
{
if ((face.NetworkInterfaceType != NetworkInterfaceType.Tunnel) &&
(face.NetworkInterfaceType != NetworkInterfaceType.Loopback))
{
var statistics = face.GetIPv4Statistics();

// all testing seems to prove that once an interface comes online
// it has already accrued statistics for both received and sent...

if ((statistics.BytesReceived > 0) &&
(statistics.BytesSent > 0))
{
return true;
}
}
}
}
}

return false;
}


private bool DownloadBootstrap(string bootstrap)
{
using (var client = new HttpClient())
Expand Down
Binary file modified OneMoreSetupActions/Properties/AssemblyInfo.cs
Binary file not shown.

0 comments on commit b0fea38

Please sign in to comment.