]> khamidou — GitHub mirrors - electron.git/commitdiff
win: Set app user model ID
authorCheng Zhao <zcbenz@gmail.com>
Mon, 17 Nov 2014 07:55:49 +0000 (15:55 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Mon, 17 Nov 2014 07:55:49 +0000 (15:55 +0800)
This ID is used by Windows to identify your application.

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

index 4761c7ca81f056fa239651728725f8f9033c72a7..b658de4102097500cd2a504b9df2cf48b16b3ffe 100644 (file)
@@ -70,6 +70,10 @@ 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 e058ec25e25101eecd5edd3839b20ce4d9805010..aa3b3c07aa56be9a9442ef1d4a42989814151d84 100644 (file)
 #include "atom/browser/browser_observer.h"
 #include "atom/browser/window_list_observer.h"
 
+#if defined(OS_WIN)
+#include "base/strings/string16.h"
+#endif
+
 namespace base {
 class FilePath;
 }
@@ -76,6 +80,11 @@ class Browser : public WindowListObserver {
   void DockSetMenu(ui::MenuModel* model);
 #endif  // defined(OS_MACOSX)
 
+#if defined(OS_WIN)
+  // Set the application user model ID, called when "SetName" is called.
+  void SetAppUserModelID(const std::string& name);
+#endif
+
   // Tell the application to open a file.
   bool OpenFile(const std::string& file_path);
 
@@ -126,6 +135,10 @@ class Browser : public WindowListObserver {
   std::string version_override_;
   std::string name_override_;
 
+#if defined(OS_WIN)
+  base::string16 app_user_model_id_;
+#endif
+
   DISALLOW_COPY_AND_ASSIGN(Browser);
 };
 
index 85be2d32433ac6a100e69133b7c46c3f6b016e3c..91550ace4a7d5e495105f08bb7e9a00bd951acc4 100644 (file)
@@ -54,11 +54,17 @@ void Browser::AddRecentDocument(const base::FilePath& path) {
   if (SUCCEEDED(hr)) {
     SHARDAPPIDINFO info;
     info.psi = item;
-    info.pszAppID = L"Atom";
+    info.pszAppID = app_user_model_id_.c_str();
     SHAddToRecentDocs(SHARD_APPIDINFO, &info);
   }
 }
 
+void Browser::SetAppUserModelID(const std::string& name) {
+  app_user_model_id_ = base::UTF8ToUTF16(
+      base::StringPrintf("atom-shell.app.%s", name));
+  SetCurrentProcessExplicitAppUserModelID(app_user_model_id_.c_str());
+}
+
 std::string Browser::GetExecutableFileVersion() const {
   base::FilePath path;
   if (PathService::Get(base::FILE_EXE, &path)) {