diff --git a/gsmartcontrol/src/hz/launch_url.h b/gsmartcontrol/src/hz/launch_url.h index 20318d9..3a5ad52 100644 --- a/gsmartcontrol/src/hz/launch_url.h +++ b/gsmartcontrol/src/hz/launch_url.h @@ -17,7 +17,14 @@ #include #include -#include "scoped_ptr.h" +#ifdef _WIN32 + #include // seems to be needed by shellapi.h + #include // ShellExecuteW() + #include "scoped_array.h" + #include "win32_tools.h" // hz::win32_utf8_to_utf16 +#else + #include "scoped_ptr.h" +#endif @@ -31,6 +38,19 @@ namespace hz { /// The link is in utf-8 in windows. inline std::string launch_url(GtkWindow* window, const std::string& link) { + // For some reason, gtk_show_uri() crashes on windows, so use our manual implementation. +#ifdef _WIN32 + hz::scoped_array wlink(hz::win32_utf8_to_utf16(link.c_str())); + if (!wlink) + return "Error while executing a command: The specified URI contains non-UTF-8 characters."; + + HINSTANCE inst = ShellExecuteW(0, L"open", wlink.get(), NULL, NULL, SW_SHOWNORMAL); + if (inst > reinterpret_cast(32)) { + return std::string(); + } + return "Error while executing a command: Internal error."; + +#else hz::scoped_ptr error(0, g_error_free); #if GTK_CHECK_VERSION(3, 22, 0) bool status = gtk_show_uri_on_window(window, link.c_str(), GDK_CURRENT_TIME, &error.get_ref()); @@ -43,6 +63,7 @@ inline std::string launch_url(GtkWindow* window, const std::string& link) + ((error && error->message) ? (std::string(": ") + error->message) : "."); } return std::string(); +#endif }