Save the taskbar object
This commit is contained in:
parent
2d6f8350cb
commit
8da7803f3e
2 changed files with 27 additions and 21 deletions
|
@ -4,12 +4,9 @@
|
|||
|
||||
#include "atom/browser/ui/win/taskbar_host.h"
|
||||
|
||||
#include <shobjidl.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "base/stl_util.h"
|
||||
#include "base/win/scoped_comptr.h"
|
||||
#include "base/win/scoped_gdi_object.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "third_party/skia/include/core/SkBitmap.h"
|
||||
|
@ -57,13 +54,8 @@ TaskbarHost::~TaskbarHost() {
|
|||
|
||||
bool TaskbarHost::SetThumbarButtons(
|
||||
HWND window, const std::vector<ThumbarButton>& buttons) {
|
||||
base::win::ScopedComPtr<ITaskbarList3> taskbar;
|
||||
if (FAILED(taskbar.CreateInstance(CLSID_TaskbarList,
|
||||
nullptr,
|
||||
CLSCTX_INPROC_SERVER)) ||
|
||||
FAILED(taskbar->HrInit())) {
|
||||
if (!InitailizeTaskbar())
|
||||
return false;
|
||||
}
|
||||
|
||||
callback_map_.clear();
|
||||
|
||||
|
@ -115,30 +107,26 @@ bool TaskbarHost::SetThumbarButtons(
|
|||
// Finally add them to taskbar.
|
||||
HRESULT r;
|
||||
if (thumbar_buttons_added_)
|
||||
r = taskbar->ThumbBarUpdateButtons(window, kMaxButtonsCount, thumb_buttons);
|
||||
r = taskbar_->ThumbBarUpdateButtons(window, kMaxButtonsCount,
|
||||
thumb_buttons);
|
||||
else
|
||||
r = taskbar->ThumbBarAddButtons(window, kMaxButtonsCount, thumb_buttons);
|
||||
r = taskbar_->ThumbBarAddButtons(window, kMaxButtonsCount, thumb_buttons);
|
||||
|
||||
thumbar_buttons_added_ = true;
|
||||
return SUCCEEDED(r);
|
||||
}
|
||||
|
||||
bool TaskbarHost::SetProgressBar(HWND window, double value) {
|
||||
base::win::ScopedComPtr<ITaskbarList3> taskbar;
|
||||
if (FAILED(taskbar.CreateInstance(CLSID_TaskbarList,
|
||||
nullptr,
|
||||
CLSCTX_INPROC_SERVER)) ||
|
||||
FAILED(taskbar->HrInit())) {
|
||||
if (!InitailizeTaskbar())
|
||||
return false;
|
||||
}
|
||||
|
||||
HRESULT r;
|
||||
if (value > 1.0)
|
||||
r = taskbar->SetProgressState(window, TBPF_INDETERMINATE);
|
||||
r = taskbar_->SetProgressState(window, TBPF_INDETERMINATE);
|
||||
else if (value < 0)
|
||||
r = taskbar->SetProgressState(window, TBPF_NOPROGRESS);
|
||||
r = taskbar_->SetProgressState(window, TBPF_NOPROGRESS);
|
||||
else
|
||||
r= taskbar->SetProgressValue(window, static_cast<int>(value * 100), 100);
|
||||
r= taskbar_->SetProgressValue(window, static_cast<int>(value * 100), 100);
|
||||
return SUCCEEDED(r);
|
||||
}
|
||||
|
||||
|
@ -152,4 +140,15 @@ bool TaskbarHost::HandleThumbarButtonEvent(int button_id) {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool TaskbarHost::InitailizeTaskbar() {
|
||||
if (FAILED(taskbar_.CreateInstance(CLSID_TaskbarList,
|
||||
nullptr,
|
||||
CLSCTX_INPROC_SERVER)) ||
|
||||
FAILED(taskbar_->HrInit())) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
|
|
@ -5,13 +5,14 @@
|
|||
#ifndef ATOM_BROWSER_UI_WIN_TASKBAR_HOST_H_
|
||||
#define ATOM_BROWSER_UI_WIN_TASKBAR_HOST_H_
|
||||
|
||||
#include <windows.h>
|
||||
#include <shobjidl.h>
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "base/callback.h"
|
||||
#include "base/win/scoped_comptr.h"
|
||||
#include "ui/gfx/image/image.h"
|
||||
|
||||
namespace atom {
|
||||
|
@ -39,9 +40,15 @@ class TaskbarHost {
|
|||
bool HandleThumbarButtonEvent(int button_id);
|
||||
|
||||
private:
|
||||
// Initailize the taskbar object.
|
||||
bool InitailizeTaskbar();
|
||||
|
||||
using CallbackMap = std::map<int, base::Closure>;
|
||||
CallbackMap callback_map_;
|
||||
|
||||
// The COM object of taskbar.
|
||||
base::win::ScopedComPtr<ITaskbarList3> taskbar_;
|
||||
|
||||
// Whether we have already added the buttons to thumbar.
|
||||
bool thumbar_buttons_added_;
|
||||
|
||||
|
|
Loading…
Reference in a new issue