Skip to content

Commit

Permalink
Support Edge browser
Browse files Browse the repository at this point in the history
  • Loading branch information
kmaki565 committed Nov 22, 2021
1 parent dd5db02 commit fa52b1e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
40 changes: 29 additions & 11 deletions BentoEx/Model/BrowserAutomation.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.Win32;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Edge;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -32,9 +33,21 @@ class BrowserAutomation
/// <param name="pw"></param>
public BrowserAutomation(string company, string id, string pw)
{
// I use Chrome
string webDriverPath = new DriverManager().SetUpDriver(new ChromeConfig(), VersionResolveStrategy.MatchingBrowser);
webDriver = new ChromeDriver(Path.GetDirectoryName(webDriverPath));
// Use Chromium Edge, or Chrome.
if (EnvCheck.IsMsEdgeInstalled())
{
string webDriverPath = new DriverManager().SetUpDriver(new EdgeConfig(), VersionResolveStrategy.MatchingBrowser);
webDriver = new EdgeDriver(Path.GetDirectoryName(webDriverPath));
}
else if (EnvCheck.IsChromeInstalled())
{
string webDriverPath = new DriverManager().SetUpDriver(new ChromeConfig(), VersionResolveStrategy.MatchingBrowser);
webDriver = new ChromeDriver(Path.GetDirectoryName(webDriverPath));
}
else
{
throw new InvalidOperationException("Chromium Edge or Chrome browser is required for UI automation.");
}

companyCode = company;
userId = id;
Expand Down Expand Up @@ -135,18 +148,23 @@ void Confirm()
}
}

class BrowserEnvCheck
static class EnvCheck
{
const string keyPath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe";

static public bool IsChromeInstalled()
public static bool IsChromeInstalled()
{
RegistryKey regkey = Registry.LocalMachine.OpenSubKey(keyPath, false);

return (regkey != null);
RegistryKey regkey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe");
return regkey != null;
}
/// <summary>
/// Checks if Chromium version of Edge browser is installed.
/// </summary>
/// <returns></returns>
public static bool IsMsEdgeInstalled()
{
return File.Exists(@"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe");
}

static public bool IsVpnConnected()
public static bool IsVpnConnected()
{
if (NetworkInterface.GetIsNetworkAvailable())
{
Expand Down
6 changes: 3 additions & 3 deletions BentoEx/ViewModel/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ private async Task RunProcessNoWindow(string cmd, string arg)

public void OnLoaded()
{
NeedBrowserInstall = !BrowserEnvCheck.IsChromeInstalled();
var task = Update(LoadMenu(selectedDay));
NeedBrowserInstall = !EnvCheck.IsMsEdgeInstalled() && !EnvCheck.IsChromeInstalled();
_ = Update(LoadMenu(selectedDay));
}

private async Task LoadMenu(DateTime date)
{
NeedKillVpn = requireVpnOff && BrowserEnvCheck.IsVpnConnected();
NeedKillVpn = requireVpnOff && EnvCheck.IsVpnConnected();

if (!IsLoggedIn)
{
Expand Down

0 comments on commit fa52b1e

Please sign in to comment.