fix: Windows Store Notifications (#13258)
* 🔧 Basic 'are we in the desktop bridge' check * 🔧 Store the result of the call * 🔧 Create ToastNotifier correctly in UWP environment * 🔧 Actually, improve this all around * ❤️ Implement feedback * 🔧 Fix compiler issues * 🔧 Mutex is banned, go to option 2 * 🔧 Use getProcAddress * 📝 Make comment clearer * ❤️ Implement feedback
This commit is contained in:
parent
9fe456dec1
commit
163e2d3527
3 changed files with 56 additions and 4 deletions
|
@ -58,12 +58,19 @@ bool WindowsToastNotification::Initialize() {
|
|||
&toast_manager_)))
|
||||
return false;
|
||||
|
||||
ScopedHString app_id;
|
||||
if (!GetAppUserModelID(&app_id))
|
||||
return false;
|
||||
if (IsRunningInDesktopBridge()) {
|
||||
// Ironically, the Desktop Bridge / UWP environment
|
||||
// requires us to not give Windows an appUserModelId.
|
||||
return SUCCEEDED(
|
||||
toast_manager_->CreateToastNotifier(&toast_notifier_));
|
||||
} else {
|
||||
ScopedHString app_id;
|
||||
if (!GetAppUserModelID(&app_id))
|
||||
return false;
|
||||
|
||||
return SUCCEEDED(
|
||||
return SUCCEEDED(
|
||||
toast_manager_->CreateToastNotifierWithId(app_id, &toast_notifier_));
|
||||
}
|
||||
}
|
||||
|
||||
WindowsToastNotification::WindowsToastNotification(
|
||||
|
|
|
@ -23,6 +23,7 @@ std::string GetApplicationVersion();
|
|||
PCWSTR GetRawAppUserModelID();
|
||||
bool GetAppUserModelID(ScopedHString* app_id);
|
||||
void SetAppUserModelID(const base::string16& name);
|
||||
bool IsRunningInDesktopBridge();
|
||||
#endif
|
||||
|
||||
} // namespace brightray
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
|
||||
#include <windows.h> // windows.h must be included first
|
||||
|
||||
#include <appmodel.h>
|
||||
#include <shlobj.h>
|
||||
#include <VersionHelpers.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
|
@ -62,4 +64,46 @@ bool GetAppUserModelID(ScopedHString* app_id) {
|
|||
return app_id->success();
|
||||
}
|
||||
|
||||
bool IsRunningInDesktopBridgeImpl() {
|
||||
if (IsWindows8OrGreater()) {
|
||||
// GetPackageFamilyName is not available on Windows 7
|
||||
using GetPackageFamilyNameFuncPtr = decltype(&GetPackageFamilyName);
|
||||
|
||||
static bool initialize_get_package_family_name = true;
|
||||
static GetPackageFamilyNameFuncPtr get_package_family_namePtr = NULL;
|
||||
|
||||
if (initialize_get_package_family_name) {
|
||||
initialize_get_package_family_name = false;
|
||||
HMODULE kernel32_base = GetModuleHandle(L"Kernel32.dll");
|
||||
if (!kernel32_base) {
|
||||
NOTREACHED() << " " << __FUNCTION__ << "(): Can't open Kernel32.dll";
|
||||
return false;
|
||||
}
|
||||
|
||||
get_package_family_namePtr =
|
||||
reinterpret_cast<GetPackageFamilyNameFuncPtr>(
|
||||
GetProcAddress(kernel32_base, "GetPackageFamilyName"));
|
||||
|
||||
if (!get_package_family_namePtr) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
UINT32 length;
|
||||
wchar_t packageFamilyName[PACKAGE_FAMILY_NAME_MAX_LENGTH + 1];
|
||||
HANDLE proc = GetCurrentProcess();
|
||||
LONG result =
|
||||
(*get_package_family_namePtr)(proc, &length, packageFamilyName);
|
||||
|
||||
return result == ERROR_SUCCESS;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool IsRunningInDesktopBridge() {
|
||||
static bool result = IsRunningInDesktopBridgeImpl();
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace brightray
|
||||
|
|
Loading…
Add table
Reference in a new issue