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
|
|
|
|
2018-10-17 18:01:11 +00:00
|
|
|
#include "atom/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>
|
2017-05-18 22:06:57 +00:00
|
|
|
#include <string>
|
2018-09-13 00:25:56 +00:00
|
|
|
#include <utility>
|
2017-06-23 10:39:42 +00:00
|
|
|
#include <vector>
|
2017-05-18 22:06:57 +00:00
|
|
|
|
2017-04-03 08:48:18 +00:00
|
|
|
#include "third_party/skia/include/core/SkBitmap.h"
|
2017-03-15 12:56:06 +00:00
|
|
|
|
2018-10-17 18:01:11 +00:00
|
|
|
namespace atom {
|
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();
|
|
|
|
this->notification_ref_ = std::move(existing->notification_ref_);
|
|
|
|
this->notification_ref_.Set(options.title, options.msg, image);
|
|
|
|
} else {
|
|
|
|
this->notification_ref_ =
|
|
|
|
presenter->AddNotification(options.title, options.msg, image);
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2018-10-17 18:01:11 +00:00
|
|
|
} // namespace atom
|