exit Settings on fatal error

fix error checking
This commit is contained in:
Enrico Giordani
2019-10-05 08:47:04 +02:00
committed by Enrico Giordani
parent 5f8c4ea143
commit 4b273a7e39

View File

@@ -205,16 +205,13 @@ void receive_message_from_webview(const std::wstring& msg) {
void initialize_webview() { void initialize_webview() {
try { try {
if (!g_webview_process) {
g_webview_process = WebViewControlProcess(); g_webview_process = WebViewControlProcess();
WINRT_VERIFY(g_webview_process);
}
auto asyncwebview = g_webview_process.CreateWebViewControlAsync((int64_t)g_main_wnd, client_rect_to_bounds_rect(g_main_wnd)); auto asyncwebview = g_webview_process.CreateWebViewControlAsync((int64_t)g_main_wnd, client_rect_to_bounds_rect(g_main_wnd));
asyncwebview.Completed([=](IAsyncOperation<WebViewControl> const& sender, AsyncStatus status) { asyncwebview.Completed([=](IAsyncOperation<WebViewControl> const& sender, AsyncStatus status) {
if (status == AsyncStatus::Completed) { if (status == AsyncStatus::Completed) {
WINRT_VERIFY(sender); WINRT_VERIFY(sender != nullptr);
g_webview = sender.GetResults(); g_webview = sender.GetResults();
WINRT_VERIFY(g_webview); WINRT_VERIFY(g_webview != nullptr);
// In order to receive window.external.notify() calls in ScriptNotify // In order to receive window.external.notify() calls in ScriptNotify
g_webview.Settings().IsScriptNotifyAllowed(true); g_webview.Settings().IsScriptNotifyAllowed(true);
@@ -247,19 +244,18 @@ void initialize_webview() {
NavigateToLocalhostReactServer(); NavigateToLocalhostReactServer();
#else #else
// Navigates to settings-html/index.html. // Navigates to settings-html/index.html.
NavigateToUri(L"index.html"); NavigateToUri(L"index.html");
#endif #endif
} else if (status == AsyncStatus::Error) { } else if (status == AsyncStatus::Error) {
// TODO: report the error and quit, or try to use WebView2. MessageBox(NULL, L"Failed to create the WebView control.\nPlease report the bug to https://github.com/microsoft/PowerToys/issues", L"PowerToys Settings Error", MB_OK);
exit(1);
} else if (status == AsyncStatus::Started) { } else if (status == AsyncStatus::Started) {
// Ignore. // Ignore.
} else if (status == AsyncStatus::Canceled) { } else if (status == AsyncStatus::Canceled) {
// Ignore. // Ignore.
} }
}); });
} } catch (hresult_error const& e) {
catch (hresult_error const& e) {
WCHAR message[1024] = L""; WCHAR message[1024] = L"";
StringCchPrintf(message, ARRAYSIZE(message), L"failed: %ls", e.message().c_str()); StringCchPrintf(message, ARRAYSIZE(message), L"failed: %ls", e.message().c_str());
MessageBox(g_main_wnd, message, L"Error", MB_OK); MessageBox(g_main_wnd, message, L"Error", MB_OK);
@@ -358,7 +354,7 @@ void register_classes(HINSTANCE hInstance) {
HWND create_main_window(HINSTANCE hInstance) { HWND create_main_window(HINSTANCE hInstance) {
RECT desktopRect; RECT desktopRect;
const HWND hDesktop = GetDesktopWindow(); const HWND hDesktop = GetDesktopWindow();
WINRT_VERIFY(hDesktop); WINRT_VERIFY(hDesktop != nullptr);
WINRT_VERIFY(GetWindowRect(hDesktop, &desktopRect)); WINRT_VERIFY(GetWindowRect(hDesktop, &desktopRect));
int wind_width = 1024; int wind_width = 1024;
@@ -427,7 +423,8 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _
if (is_process_elevated()) { if (is_process_elevated()) {
if (!drop_elevated_privileges()) { if (!drop_elevated_privileges()) {
MessageBox(NULL, L"Failed to drop admin privileges.\nPlease report the bug to https://github.com/microsoft/PowerToys/issues.", L"PowerToys Settings Error", MB_OK); MessageBox(NULL, L"Failed to drop admin privileges.\nPlease report the bug to https://github.com/microsoft/PowerToys/issues", L"PowerToys Settings Error", MB_OK);
exit(1);
} }
} }
@@ -436,7 +433,8 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _
register_classes(hInstance); register_classes(hInstance);
g_main_wnd = create_main_window(hInstance); g_main_wnd = create_main_window(hInstance);
if (g_main_wnd == nullptr) { if (g_main_wnd == nullptr) {
MessageBox(NULL, L"Failed to create main window.\nPlease report the bug to https://github.com/microsoft/PowerToys/issues.", L"PowerToys Settings Error", MB_OK); MessageBox(NULL, L"Failed to create main window.\nPlease report the bug to https://github.com/microsoft/PowerToys/issues", L"PowerToys Settings Error", MB_OK);
exit(1);
} }
initialize_webview(); initialize_webview();
ShowWindow(g_main_wnd, nShowCmd); ShowWindow(g_main_wnd, nShowCmd);