// Copyright (c) 2014 GitHub, Inc. All rights reserved. // Use of this source code is governed by the MIT license that can be // found in the LICENSE file. #include "atom/browser/api/atom_api_tray.h" #include #include "atom/browser/api/atom_api_menu.h" #include "atom/browser/ui/tray_icon.h" #include "atom/common/native_mate_converters/image_converter.h" #include "native_mate/constructor.h" #include "native_mate/dictionary.h" #include "atom/common/node_includes.h" namespace atom { namespace api { Tray::Tray(const gfx::ImageSkia& image) : tray_icon_(TrayIcon::Create()) { tray_icon_->SetImage(image); tray_icon_->AddObserver(this); } Tray::~Tray() { } // static mate::Wrappable* Tray::New(const gfx::ImageSkia& image) { return new Tray(image); } void Tray::OnClicked() { Emit("clicked"); } void Tray::OnDoubleClicked() { Emit("double-clicked"); } void Tray::SetImage(const gfx::ImageSkia& image) { tray_icon_->SetImage(image); } void Tray::SetPressedImage(const gfx::ImageSkia& image) { tray_icon_->SetPressedImage(image); } void Tray::SetToolTip(const std::string& tool_tip) { tray_icon_->SetToolTip(tool_tip); } void Tray::SetTitle(const std::string& title) { tray_icon_->SetTitle(title); } void Tray::SetHighlightMode(bool highlight) { tray_icon_->SetHighlightMode(highlight); } void Tray::SetContextMenu(Menu* menu) { tray_icon_->SetContextMenu(menu->model()); } // static void Tray::BuildPrototype(v8::Isolate* isolate, v8::Handle prototype) { mate::ObjectTemplateBuilder(isolate, prototype) .SetMethod("setImage", &Tray::SetImage) .SetMethod("setPressedImage", &Tray::SetPressedImage) .SetMethod("setToolTip", &Tray::SetToolTip) .SetMethod("setTitle", &Tray::SetTitle) .SetMethod("setHighlightMode", &Tray::SetHighlightMode) .SetMethod("_setContextMenu", &Tray::SetContextMenu); } } // namespace api } // namespace atom namespace { void Initialize(v8::Handle exports, v8::Handle unused, v8::Handle context, void* priv) { using atom::api::Tray; v8::Isolate* isolate = context->GetIsolate(); v8::Handle constructor = mate::CreateConstructor( isolate, "Tray", base::Bind(&Tray::New)); mate::Dictionary dict(isolate, exports); dict.Set("Tray", static_cast>(constructor)); } } // namespace NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_browser_tray, Initialize)