From ac9e0b458d3924773b595c46df85a112c1555988 Mon Sep 17 00:00:00 2001 From: Tereza Tomcova Date: Sat, 12 Nov 2016 17:21:31 +0100 Subject: [PATCH 1/7] Added BrowserWindow.setAppDetails to set user model id, icon and relaunch command --- atom/browser/api/atom_api_window.cc | 22 ++++++++++++++++++++++ atom/browser/api/atom_api_window.h | 1 + 2 files changed, 23 insertions(+) diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index 75be28028d3f..f719cead7527 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" @@ -20,6 +21,7 @@ #include "content/public/common/content_switches.h" #include "native_mate/constructor.h" #include "native_mate/dictionary.h" +#include "ui/base/win/shell.h" #include "ui/gfx/geometry/rect.h" #if defined(TOOLKIT_VIEWS) @@ -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; + 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) From 38b14fc9125afa50d9e3f453a2592ca74266050a Mon Sep 17 00:00:00 2001 From: Tereza Tomcova Date: Sat, 12 Nov 2016 17:59:57 +0100 Subject: [PATCH 2/7] Include shell.h only for Windows --- atom/browser/api/atom_api_window.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index f719cead7527..66ae006ce28b 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -21,7 +21,6 @@ #include "content/public/common/content_switches.h" #include "native_mate/constructor.h" #include "native_mate/dictionary.h" -#include "ui/base/win/shell.h" #include "ui/gfx/geometry/rect.h" #if defined(TOOLKIT_VIEWS) @@ -30,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" From 782417b1fa48e693acf45abe2c60776312fd44ec Mon Sep 17 00:00:00 2001 From: Tereza Tomcova Date: Fri, 18 Nov 2016 21:28:24 +0100 Subject: [PATCH 3/7] Added tests for BrowserWindow.setAppDetails --- spec/api-browser-window-spec.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index cdfdb384421d..c2f6260c1088 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -518,6 +518,34 @@ describe('browser-window module', function () { }) }) + describe('BrowserWindow.setAppDetails(options)', function () { + if (process.platform !== 'win32') return + + it('supports setting the app details', function () { + 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) From b305020c1d2e14f512938e97020851360f68907a Mon Sep 17 00:00:00 2001 From: Tereza Tomcova Date: Fri, 18 Nov 2016 21:29:04 +0100 Subject: [PATCH 4/7] Added documentation for BrowserWindow.setAppDetails --- docs/api/browser-window.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 5ff2380a5813..339d08724d0b 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -1103,6 +1103,26 @@ 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 is used. + #### `win.showDefinitionForSelection()` _macOS_ Same as `webContents.showDefinitionForSelection()`. From fff59271af33c0b181d1b1ae38f593009eb1447c Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 28 Nov 2016 14:26:30 -0800 Subject: [PATCH 5/7] Initialize app icon index to 0 --- atom/browser/api/atom_api_window.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index 66ae006ce28b..455e2225a3a8 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -714,7 +714,7 @@ bool Window::SetThumbnailToolTip(const std::string& tooltip) { void Window::SetAppDetails(const mate::Dictionary& options) { base::string16 app_id; base::FilePath app_icon_path; - int app_icon_index; + int app_icon_index = 0; base::string16 relaunch_command; base::string16 relaunch_display_name; From 5abecadfd31163865a6557cae9849d3af0d715d5 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 28 Nov 2016 14:29:21 -0800 Subject: [PATCH 6/7] Tweak setAppDetails docs --- docs/api/browser-window.md | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 339d08724d0b..862d28d3f26a 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -1106,22 +1106,18 @@ 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). + * `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). + * `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). + * `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 is used. +**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_ From 3897a880823d0881565086b4c934dcc9d061dddc Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 28 Nov 2016 14:30:43 -0800 Subject: [PATCH 7/7] Use skip for setAppDetails spec --- spec/api-browser-window-spec.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index c2f6260c1088..aefaf20bd150 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -519,9 +519,9 @@ describe('browser-window module', function () { }) describe('BrowserWindow.setAppDetails(options)', function () { - if (process.platform !== 'win32') return - 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 () { @@ -540,9 +540,10 @@ describe('browser-window module', function () { }) w.setAppDetails({}) }) + assert.throws(function () { w.setAppDetails() - }, /Insufficient number of arguments./) + }, /Insufficient number of arguments\./) }) })