diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index 75be28028d3f..455e2225a3a8 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -10,6 +10,7 @@ #include "atom/browser/browser.h" #include "atom/browser/native_window.h" #include "atom/common/native_mate_converters/callback.h" +#include "atom/common/native_mate_converters/file_path_converter.h" #include "atom/common/native_mate_converters/gfx_converter.h" #include "atom/common/native_mate_converters/gurl_converter.h" #include "atom/common/native_mate_converters/image_converter.h" @@ -28,6 +29,7 @@ #if defined(OS_WIN) #include "atom/browser/ui/win/taskbar_host.h" +#include "ui/base/win/shell.h" #endif #include "atom/common/node_includes.h" @@ -708,6 +710,25 @@ bool Window::SetThumbnailToolTip(const std::string& tooltip) { return window->taskbar_host().SetThumbnailToolTip( window_->GetAcceleratedWidget(), tooltip); } + +void Window::SetAppDetails(const mate::Dictionary& options) { + base::string16 app_id; + base::FilePath app_icon_path; + int app_icon_index = 0; + base::string16 relaunch_command; + base::string16 relaunch_display_name; + + options.Get("appId", &app_id); + options.Get("appIconPath", &app_icon_path); + options.Get("appIconIndex", &app_icon_index); + options.Get("relaunchCommand", &relaunch_command); + options.Get("relaunchDisplayName", &relaunch_display_name); + + ui::win::SetAppDetailsForWindow( + app_id, app_icon_path, app_icon_index, + relaunch_command, relaunch_display_name, + window_->GetAcceleratedWidget()); +} #endif #if defined(TOOLKIT_VIEWS) @@ -916,6 +937,7 @@ void Window::BuildPrototype(v8::Isolate* isolate, .SetMethod("unhookAllWindowMessages", &Window::UnhookAllWindowMessages) .SetMethod("setThumbnailClip", &Window::SetThumbnailClip) .SetMethod("setThumbnailToolTip", &Window::SetThumbnailToolTip) + .SetMethod("setAppDetails", &Window::SetAppDetails) #endif #if defined(TOOLKIT_VIEWS) .SetMethod("setIcon", &Window::SetIcon) diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index 8a5b95ba8f9e..5819c7b2f2a4 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -187,6 +187,7 @@ class Window : public mate::TrackableObject, void UnhookAllWindowMessages(); bool SetThumbnailClip(const gfx::Rect& region); bool SetThumbnailToolTip(const std::string& tooltip); + void SetAppDetails(const mate::Dictionary& options); #endif #if defined(TOOLKIT_VIEWS) diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 40a2ccacac38..2a6c2c57e34b 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -1109,6 +1109,22 @@ the entire window by specifying an empty region: Sets the toolTip that is displayed when hovering over the window thumbnail in the taskbar. +#### `win.setAppDetails(options)` _Windows_ + +* `options` Object + * `appId` String (optional) - Window's [App User Model ID](https://msdn.microsoft.com/en-us/library/windows/desktop/dd391569(v=vs.85).aspx). + It has to be set, otherwise the other options will have no effect. + * `appIconPath` String (optional) - Window's [Relaunch Icon](https://msdn.microsoft.com/en-us/library/windows/desktop/dd391573(v=vs.85).aspx). + * `appIconIndex` Integer (optional) - Index of the icon in `appIconPath`. + Ignored when `appIconPath` is not set. Default is `0`. + * `relaunchCommand` String (optional) - Window's [Relaunch Command](https://msdn.microsoft.com/en-us/library/windows/desktop/dd391571(v=vs.85).aspx). + * `relaunchDisplayName` String (optional) - Window's [Relaunch Display Name](https://msdn.microsoft.com/en-us/library/windows/desktop/dd391572(v=vs.85).aspx). + +Sets the properties for the window's taskbar button. + +**Note:** `relaunchCommand` and `relaunchDisplayName` must always be set +together. If one of those properties is not set, then neither will be used. + #### `win.showDefinitionForSelection()` _macOS_ Same as `webContents.showDefinitionForSelection()`. diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index f7aa6436a47c..034461a4bf38 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -518,6 +518,35 @@ describe('browser-window module', function () { }) }) + describe('BrowserWindow.setAppDetails(options)', function () { + it('supports setting the app details', function () { + if (process.platform !== 'win32') return this.skip() + + const iconPath = path.join(fixtures, 'assets', 'icon.ico') + + assert.doesNotThrow(function () { + w.setAppDetails({appId: 'my.app.id'}) + w.setAppDetails({appIconPath: iconPath, appIconIndex: 0}) + w.setAppDetails({appIconPath: iconPath}) + w.setAppDetails({relaunchCommand: 'my-app.exe arg1 arg2', relaunchDisplayName: 'My app name'}) + w.setAppDetails({relaunchCommand: 'my-app.exe arg1 arg2'}) + w.setAppDetails({relaunchDisplayName: 'My app name'}) + w.setAppDetails({ + appId: 'my.app.id', + appIconPath: iconPath, + appIconIndex: 0, + relaunchCommand: 'my-app.exe arg1 arg2', + relaunchDisplayName: 'My app name' + }) + w.setAppDetails({}) + }) + + assert.throws(function () { + w.setAppDetails() + }, /Insufficient number of arguments\./) + }) + }) + describe('BrowserWindow.fromId(id)', function () { it('returns the window with id', function () { assert.equal(w.id, BrowserWindow.fromId(w.id).id)