Merge pull request #6309 from electron/app-launcher-rename

Implement app.setBadgeCount on Mac
This commit is contained in:
Cheng Zhao
2016-07-02 01:51:47 +00:00
committed by GitHub
8 changed files with 70 additions and 84 deletions

View File

@@ -520,6 +520,8 @@ void App::BuildPrototype(
base::Bind(&Browser::SetAsDefaultProtocolClient, browser))
.SetMethod("removeAsDefaultProtocolClient",
base::Bind(&Browser::RemoveAsDefaultProtocolClient, browser))
.SetMethod("setBadgeCount", base::Bind(&Browser::SetBadgeCount, browser))
.SetMethod("getBadgeCount", base::Bind(&Browser::GetBadgeCount, browser))
#if defined(OS_MACOSX)
.SetMethod("hide", base::Bind(&Browser::Hide, browser))
.SetMethod("show", base::Bind(&Browser::Show, browser))
@@ -529,8 +531,11 @@ void App::BuildPrototype(
base::Bind(&Browser::GetCurrentActivityType, browser))
#endif
#if defined(OS_WIN)
.SetMethod("setUserTasks",
base::Bind(&Browser::SetUserTasks, browser))
.SetMethod("setUserTasks", base::Bind(&Browser::SetUserTasks, browser))
#endif
#if defined(OS_LINUX)
.SetMethod("isUnityRunning",
base::Bind(&Browser::IsUnityRunning, browser))
#endif
.SetMethod("setPath", &App::SetPath)
.SetMethod("getPath", &App::GetPath)
@@ -614,16 +619,6 @@ void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
dict.SetMethod("dockSetMenu", &DockSetMenu);
dict.SetMethod("dockSetIcon", base::Bind(&Browser::DockSetIcon, browser));
#endif
#if defined(OS_LINUX)
auto browser = base::Unretained(Browser::Get());
dict.SetMethod("unityLauncherAvailable",
base::Bind(&Browser::UnityLauncherAvailable, browser));
dict.SetMethod("unityLauncherSetBadgeCount",
base::Bind(&Browser::UnityLauncherSetBadgeCount, browser));
dict.SetMethod("unityLauncherGetBadgeCount",
base::Bind(&Browser::UnityLauncherGetBadgeCount, browser));
#endif
}
} // namespace

View File

@@ -118,6 +118,10 @@ void Browser::SetName(const std::string& name) {
name_override_ = name;
}
int Browser::GetBadgeCount() {
return badge_count_;
}
bool Browser::OpenFile(const std::string& file_path) {
bool prevent_default = false;
FOR_EACH_OBSERVER(BrowserObserver,

View File

@@ -87,6 +87,10 @@ class Browser : public WindowListObserver {
// Query the current state of default handler for a protocol.
bool IsDefaultProtocolClient(const std::string& protocol);
// Set/Get the badge count.
bool SetBadgeCount(int count);
int GetBadgeCount();
#if defined(OS_MACOSX)
// Hide the application.
void Hide();
@@ -152,10 +156,8 @@ class Browser : public WindowListObserver {
#endif // defined(OS_WIN)
#if defined(OS_LINUX)
// Set/Get unity dock's badge counter.
bool UnityLauncherAvailable();
void UnityLauncherSetBadgeCount(int count);
int UnityLauncherGetBadgeCount();
// Whether Unity launcher is running.
bool IsUnityRunning();
#endif // defined(OS_LINUX)
// Tell the application to open a file.
@@ -223,9 +225,7 @@ class Browser : public WindowListObserver {
std::string version_override_;
std::string name_override_;
#if defined(OS_LINUX)
int current_badge_count_ = 0;
#endif
int badge_count_ = 0;
#if defined(OS_WIN)
base::string16 app_user_model_id_;

View File

@@ -47,6 +47,16 @@ bool Browser::IsDefaultProtocolClient(const std::string& protocol) {
return false;
}
bool Browser::SetBadgeCount(int count) {
if (IsUnityRunning()) {
unity::SetDownloadCount(count);
badge_count_ = count;
return true;
} else {
return false;
}
}
std::string Browser::GetExecutableFileVersion() const {
return brightray::GetApplicationVersion();
}
@@ -55,19 +65,8 @@ std::string Browser::GetExecutableFileProductName() const {
return brightray::GetApplicationName();
}
bool Browser::UnityLauncherAvailable() {
bool Browser::IsUnityRunning() {
return unity::IsRunning();
}
void Browser::UnityLauncherSetBadgeCount(int count) {
if (UnityLauncherAvailable()) {
current_badge_count_ = count;
unity::SetDownloadCount(count);
}
}
int Browser::UnityLauncherGetBadgeCount() {
return current_badge_count_;
}
} // namespace atom

View File

@@ -11,6 +11,7 @@
#include "atom/browser/window_list.h"
#include "base/mac/bundle_locations.h"
#include "base/mac/foundation_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/sys_string_conversions.h"
#include "brightray/common/application_info.h"
#include "net/base/mac/url_conversions.h"
@@ -114,6 +115,12 @@ bool Browser::IsDefaultProtocolClient(const std::string& protocol) {
void Browser::SetAppUserModelID(const base::string16& name) {
}
bool Browser::SetBadgeCount(int count) {
DockSetBadgeText(count != 0 ? base::IntToString(count) : "");
badge_count_ = count;
return true;
}
void Browser::SetUserActivity(const std::string& type,
const base::DictionaryValue& user_info,
mate::Arguments* args) {

View File

@@ -269,6 +269,10 @@ bool Browser::IsDefaultProtocolClient(const std::string& protocol) {
}
}
bool Browser::SetBadgeCount(int count) {
return false;
}
PCWSTR Browser::GetAppUserModelID() {
if (app_user_model_id_.empty()) {
SetAppUserModelID(base::ReplaceStringPlaceholders(