diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index 265ed8f36b7..ce6a7d33c6a 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -614,6 +614,16 @@ void Initialize(v8::Local exports, v8::Local 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 diff --git a/atom/browser/browser.h b/atom/browser/browser.h index 2c167808303..601f40044b2 100644 --- a/atom/browser/browser.h +++ b/atom/browser/browser.h @@ -149,7 +149,14 @@ class Browser : public WindowListObserver { // one from app's name. // The returned string managed by Browser, and should not be modified. PCWSTR GetAppUserModelID(); -#endif +#endif // defined(OS_WIN) + +#if defined(OS_LINUX) + // Set/Get unity dock's badge counter. + bool UnityLauncherAvailable(); + void UnityLauncherSetBadgeCount(int count); + int UnityLauncherGetBadgeCount(); +#endif // defined(OS_LINUX) // Tell the application to open a file. bool OpenFile(const std::string& file_path); @@ -216,6 +223,8 @@ class Browser : public WindowListObserver { std::string version_override_; std::string name_override_; + int current_badge_count_ = 0; + #if defined(OS_WIN) base::string16 app_user_model_id_; #endif diff --git a/atom/browser/browser_linux.cc b/atom/browser/browser_linux.cc index d994bb4109b..668da661802 100644 --- a/atom/browser/browser_linux.cc +++ b/atom/browser/browser_linux.cc @@ -10,6 +10,7 @@ #include "atom/browser/window_list.h" #include "atom/common/atom_version.h" #include "brightray/common/application_info.h" +#include "chrome/browser/ui/libgtk2ui/unity_service.h" namespace atom { @@ -54,4 +55,17 @@ std::string Browser::GetExecutableFileProductName() const { return brightray::GetApplicationName(); } +bool Browser::UnityLauncherAvailable() { + return unity::IsRunning(); +} + +void Browser::UnityLauncherSetBadgeCount(int count) { + current_badge_count_ = count; + unity::SetDownloadCount(count); +} + +int Browser::UnityLauncherGetBadgeCount() { + return current_badge_count_; +} + } // namespace atom diff --git a/lib/browser/api/app.js b/lib/browser/api/app.js index 34210f42090..1fd972c57ca 100644 --- a/lib/browser/api/app.js +++ b/lib/browser/api/app.js @@ -45,6 +45,13 @@ if (process.platform === 'darwin') { } } +if (process.platform === 'linux' && bindings.unityLauncherAvailable()) { + app.unityLauncher = { + setBadgeCount: bindings.unityLauncherSetBadgeCount, + getBadgeCount: bindings.unityLauncherGetBadgeCount + }; +} + app.allowNTLMCredentialsForAllDomains = function (allow) { if (!process.noDeprecations) { deprecate.warn('app.allowNTLMCredentialsForAllDomains', 'session.allowNTLMCredentialsForDomains')