mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-01-19 06:53:26 +08:00
exit Settings on fatal error
fix error checking
This commit is contained in:
parent
5f8c4ea143
commit
4b273a7e39
@ -205,16 +205,13 @@ void receive_message_from_webview(const std::wstring& msg) {
|
||||
|
||||
void initialize_webview() {
|
||||
try {
|
||||
if (!g_webview_process) {
|
||||
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));
|
||||
asyncwebview.Completed([=](IAsyncOperation<WebViewControl> const& sender, AsyncStatus status) {
|
||||
if (status == AsyncStatus::Completed) {
|
||||
WINRT_VERIFY(sender);
|
||||
WINRT_VERIFY(sender != nullptr);
|
||||
g_webview = sender.GetResults();
|
||||
WINRT_VERIFY(g_webview);
|
||||
WINRT_VERIFY(g_webview != nullptr);
|
||||
|
||||
// In order to receive window.external.notify() calls in ScriptNotify
|
||||
g_webview.Settings().IsScriptNotifyAllowed(true);
|
||||
@ -247,19 +244,18 @@ void initialize_webview() {
|
||||
NavigateToLocalhostReactServer();
|
||||
#else
|
||||
// Navigates to settings-html/index.html.
|
||||
|
||||
NavigateToUri(L"index.html");
|
||||
#endif
|
||||
} 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) {
|
||||
// Ignore.
|
||||
} else if (status == AsyncStatus::Canceled) {
|
||||
// Ignore.
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (hresult_error const& e) {
|
||||
} catch (hresult_error const& e) {
|
||||
WCHAR message[1024] = L"";
|
||||
StringCchPrintf(message, ARRAYSIZE(message), L"failed: %ls", e.message().c_str());
|
||||
MessageBox(g_main_wnd, message, L"Error", MB_OK);
|
||||
@ -358,7 +354,7 @@ void register_classes(HINSTANCE hInstance) {
|
||||
HWND create_main_window(HINSTANCE hInstance) {
|
||||
RECT desktopRect;
|
||||
const HWND hDesktop = GetDesktopWindow();
|
||||
WINRT_VERIFY(hDesktop);
|
||||
WINRT_VERIFY(hDesktop != nullptr);
|
||||
WINRT_VERIFY(GetWindowRect(hDesktop, &desktopRect));
|
||||
|
||||
int wind_width = 1024;
|
||||
@ -427,7 +423,8 @@ int WINAPI WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _
|
||||
|
||||
if (is_process_elevated()) {
|
||||
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);
|
||||
g_main_wnd = create_main_window(hInstance);
|
||||
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();
|
||||
ShowWindow(g_main_wnd, nShowCmd);
|
||||
|
Loading…
Reference in New Issue
Block a user