]> khamidou — GitHub mirrors - electron.git/commitdiff
win: Do not set app user model id by default
authorCheng Zhao <zcbenz@gmail.com>
Tue, 3 Nov 2015 06:55:43 +0000 (14:55 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Tue, 3 Nov 2015 06:55:43 +0000 (14:55 +0800)
When user drags exe file into taskbar directly the pinned icon will not
has an app user model id, so if we set app user model id in the
application two icons will show in the taskbar.

For apps installed with a installer it is not a problem since the
shortcut icon will be created with app user model id, but we should also
keep the ability to make portable apps work out of box.

Fix #3303.

atom/browser/browser.cc
atom/browser/browser.h
atom/browser/browser_win.cc

index 739921fda90f5b86b2ddc974e17179c46cd3b829..e80cb4e60e20842e7e3f545691c79ffa6297927e 100644 (file)
@@ -89,10 +89,6 @@ std::string Browser::GetName() const {
 
 void Browser::SetName(const std::string& name) {
   name_override_ = name;
-
-#if defined(OS_WIN)
-  SetAppUserModelID(name);
-#endif
 }
 
 bool Browser::OpenFile(const std::string& file_path) {
index 8719e18f3140779fea38193116e34d1e1e43a7d8..0500e317755bdf2d64627c2b03afe73bcadd2e22 100644 (file)
@@ -100,8 +100,13 @@ class Browser : public WindowListObserver {
   // Add a custom task to jump list.
   void SetUserTasks(const std::vector<UserTask>& tasks);
 
-  // Set the application user model ID, called when "SetName" is called.
-  void SetAppUserModelID(const std::string& name);
+  // Set the application user model ID.
+  void SetAppUserModelID(const base::string16& name);
+
+  // Returns the application user model ID, if there isn't one, then create
+  // one from app's name.
+  // The returned string managed by Browser, and should not be modified.
+  PCWSTR GetAppUserModelID();
 #endif
 
   // Tell the application to open a file.
index b861af945421a5cf009b3db572df4798427981cd..0e5ce8e2d9550a330a048b5121a59864a80c56c2 100644 (file)
@@ -56,7 +56,7 @@ void Browser::AddRecentDocument(const base::FilePath& path) {
   if (SUCCEEDED(hr)) {
     SHARDAPPIDINFO info;
     info.psi = item;
-    info.pszAppID = app_user_model_id_.c_str();
+    info.pszAppID = GetAppUserModelID();
     SHAddToRecentDocs(SHARD_APPIDINFO, &info);
   }
 }
@@ -66,7 +66,7 @@ void Browser::ClearRecentDocuments() {
   if (FAILED(destinations.CoCreateInstance(CLSID_ApplicationDestinations,
                                            NULL, CLSCTX_INPROC_SERVER)))
     return;
-  if (FAILED(destinations->SetAppID(app_user_model_id_.c_str())))
+  if (FAILED(destinations->SetAppID(GetAppUserModelID())))
     return;
   destinations->RemoveAllDestinations();
 }
@@ -75,7 +75,7 @@ void Browser::SetUserTasks(const std::vector<UserTask>& tasks) {
   CComPtr<ICustomDestinationList> destinations;
   if (FAILED(destinations.CoCreateInstance(CLSID_DestinationList)))
     return;
-  if (FAILED(destinations->SetAppID(app_user_model_id_.c_str())))
+  if (FAILED(destinations->SetAppID(GetAppUserModelID())))
     return;
 
   // Start a transaction that updates the JumpList of this application.
@@ -117,12 +117,18 @@ void Browser::SetUserTasks(const std::vector<UserTask>& tasks) {
   destinations->CommitList();
 }
 
-void Browser::SetAppUserModelID(const std::string& name) {
-  app_user_model_id_ = base::string16(L"electron.app.");
-  app_user_model_id_ += base::UTF8ToUTF16(name);
+void Browser::SetAppUserModelID(const base::string16& name) {
+  app_user_model_id_ = name;
   SetCurrentProcessExplicitAppUserModelID(app_user_model_id_.c_str());
 }
 
+PCWSTR Browser::GetAppUserModelID() {
+  if (app_user_model_id_.empty())
+    SetAppUserModelID(base::UTF8ToUTF16(GetName()));
+
+  return app_user_model_id_.c_str();
+}
+
 std::string Browser::GetExecutableFileVersion() const {
   base::FilePath path;
   if (PathService::Get(base::FILE_EXE, &path)) {