2018-10-17 18:01:11 +00:00
|
|
|
// Copyright (c) 2015 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2018-06-26 00:00:50 +00:00
|
|
|
#ifndef WIN32_LEAN_AND_MEAN
|
2017-03-15 12:56:06 +00:00
|
|
|
#define WIN32_LEAN_AND_MEAN
|
2018-06-26 00:00:50 +00:00
|
|
|
#endif
|
2017-05-18 22:06:57 +00:00
|
|
|
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/notifications/win/win32_notification.h"
|
2017-05-18 22:06:57 +00:00
|
|
|
|
2017-03-15 12:56:06 +00:00
|
|
|
#include <windows.h>
|
2018-09-13 00:25:56 +00:00
|
|
|
#include <utility>
|
2017-05-18 22:06:57 +00:00
|
|
|
|
2021-03-18 19:55:51 +00:00
|
|
|
#include "base/strings/utf_string_conversions.h"
|
2017-04-03 08:48:18 +00:00
|
|
|
#include "third_party/skia/include/core/SkBitmap.h"
|
2017-03-15 12:56:06 +00:00
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2017-03-15 12:56:06 +00:00
|
|
|
|
2017-06-24 11:03:27 +00:00
|
|
|
void Win32Notification::Show(const NotificationOptions& options) {
|
2018-06-21 23:45:45 +00:00
|
|
|
auto* presenter = static_cast<NotificationPresenterWin7*>(this->presenter());
|
2018-04-18 01:56:12 +00:00
|
|
|
if (!presenter)
|
|
|
|
return;
|
|
|
|
|
|
|
|
HBITMAP image = NULL;
|
|
|
|
|
|
|
|
if (!options.icon.drawsNothing()) {
|
|
|
|
if (options.icon.colorType() == kBGRA_8888_SkColorType) {
|
|
|
|
BITMAPINFOHEADER bmi = {sizeof(BITMAPINFOHEADER)};
|
|
|
|
bmi.biWidth = options.icon.width();
|
|
|
|
bmi.biHeight = -options.icon.height();
|
|
|
|
bmi.biPlanes = 1;
|
|
|
|
bmi.biBitCount = 32;
|
|
|
|
bmi.biCompression = BI_RGB;
|
|
|
|
|
|
|
|
HDC hdcScreen = GetDC(NULL);
|
|
|
|
image =
|
|
|
|
CreateDIBitmap(hdcScreen, &bmi, CBM_INIT, options.icon.getPixels(),
|
|
|
|
reinterpret_cast<BITMAPINFO*>(&bmi), DIB_RGB_COLORS);
|
|
|
|
ReleaseDC(NULL, hdcScreen);
|
2017-03-15 12:56:06 +00:00
|
|
|
}
|
2018-04-18 01:56:12 +00:00
|
|
|
}
|
2017-03-15 12:56:06 +00:00
|
|
|
|
2018-04-18 01:56:12 +00:00
|
|
|
Win32Notification* existing = nullptr;
|
|
|
|
if (!options.tag.empty())
|
|
|
|
existing = presenter->GetNotificationObjectByTag(options.tag);
|
|
|
|
|
|
|
|
if (existing) {
|
|
|
|
existing->tag_.clear();
|
2019-06-11 23:39:25 +00:00
|
|
|
|
2018-04-18 01:56:12 +00:00
|
|
|
this->notification_ref_ = std::move(existing->notification_ref_);
|
2021-07-12 04:33:26 +00:00
|
|
|
this->notification_ref_.Set(options.title, options.msg, image);
|
2019-06-11 23:39:25 +00:00
|
|
|
// Need to remove the entry in the notifications set that
|
|
|
|
// NotificationPresenter is holding
|
|
|
|
existing->Destroy();
|
2018-04-18 01:56:12 +00:00
|
|
|
} else {
|
|
|
|
this->notification_ref_ =
|
2021-07-12 04:33:26 +00:00
|
|
|
presenter->AddNotification(options.title, options.msg, image);
|
2018-04-18 01:56:12 +00:00
|
|
|
}
|
2017-03-15 12:56:06 +00:00
|
|
|
|
2018-04-18 01:56:12 +00:00
|
|
|
this->tag_ = options.tag;
|
2017-03-15 12:56:06 +00:00
|
|
|
|
2018-04-18 01:56:12 +00:00
|
|
|
if (image)
|
|
|
|
DeleteObject(image);
|
2017-03-15 12:56:06 +00:00
|
|
|
}
|
|
|
|
|
2017-04-03 10:11:39 +00:00
|
|
|
void Win32Notification::Dismiss() {
|
2018-04-18 01:56:12 +00:00
|
|
|
notification_ref_.Close();
|
2017-03-15 12:56:06 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|