Skip to content

Commit

Permalink
Added check for WebView2 runtime evergreen and install if not found.
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeYeager2 committed Mar 7, 2021
1 parent 2f9dc84 commit 8da4534
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
53 changes: 52 additions & 1 deletion Photino.Native/Photino.Windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#include <atomic>
#include <Shlwapi.h>
#include <wrl.h>
#include <windows.h>
#include <cstdio>
#pragma comment(lib, "Urlmon.lib")

#define WM_USER_SHOWMESSAGE (WM_USER + 0x0001)
#define WM_USER_INVOKE (WM_USER + 0x0002)
Expand Down Expand Up @@ -192,7 +195,10 @@ void Photino::Show()
// until the window is shown.
if (!_webviewController)
{
AttachWebView();
if (EnsureWebViewIsInstalled())
AttachWebView();
else
exit(0);
}
}

Expand Down Expand Up @@ -240,6 +246,51 @@ void Photino::Invoke(ACTION callback)
waitInfo.completionNotifier.wait(uLock, [&] { return waitInfo.isCompleted; });
}

bool Photino::EnsureWebViewIsInstalled()
{
LPWSTR* versionInfo = new wchar_t*[100] ;
HRESULT ensureInstalledResult = GetAvailableCoreWebView2BrowserVersionString(nullptr, versionInfo);

if (ensureInstalledResult != S_OK)
return InstallWebView2();

return true;
}

bool Photino::InstallWebView2()
{
const wchar_t* srcURL = L"https://go.microsoft.com/fwlink/p/?LinkId=2124703";
const wchar_t* destFile = L"MicrosoftEdgeWebview2Setup.exe";

if (S_OK == URLDownloadToFile(NULL, srcURL, destFile, 0, NULL))
{
LPWSTR command = new wchar_t[100]{ L"MicrosoftEdgeWebview2Setup.exe\0" }; //add these switches? /silent /install

STARTUPINFO si;
PROCESS_INFORMATION pi;

ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));

bool installed = CreateProcess(
NULL, // No module name (use command line)
command, // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi); // Pointer to PROCESS_INFORMATION structure

return installed;
}

return false;
}

void Photino::AttachWebView()
{
std::atomic_flag flag = ATOMIC_FLAG_INIT;
Expand Down
2 changes: 2 additions & 0 deletions Photino.Native/Photino.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class Photino
wil::com_ptr<ICoreWebView2Controller> _webviewController;
std::map<std::wstring, WebResourceRequestedCallback> _schemeToRequestHandler;
void AttachWebView();
bool EnsureWebViewIsInstalled();
bool InstallWebView2();
#elif OS_LINUX
GtkWidget* _window;
GtkWidget* _webview;
Expand Down

0 comments on commit 8da4534

Please sign in to comment.