From 2cfa41e6e024559a9f2be187dca6a15acbcd4704 Mon Sep 17 00:00:00 2001 From: bitdisaster Date: Thu, 17 Sep 2020 15:17:44 -0700 Subject: [PATCH] feat: read/write Toast Activator CLSID in shortcuts (#25493) * read/write Toast Activator CLSID * docs * tests * tweaks --- docs/api/structures/shortcut-details.md | 2 ++ filenames.gni | 1 + shell/common/api/electron_api_shell.cc | 5 +++++ shell/common/gin_converters/guid_converter.h | 19 +++++++++++++++++++ spec/api-shell-spec.js | 6 ++++-- spec/fixtures/assets/shortcut.lnk | Bin 402 -> 445 bytes 6 files changed, 31 insertions(+), 2 deletions(-) diff --git a/docs/api/structures/shortcut-details.md b/docs/api/structures/shortcut-details.md index e7b272d0999..d45ae4d0176 100644 --- a/docs/api/structures/shortcut-details.md +++ b/docs/api/structures/shortcut-details.md @@ -13,3 +13,5 @@ target's icon. DLL or EXE. Default is 0. * `appUserModelId` String (optional) - The Application User Model ID. Default is empty. +* `toastActivatorClsid` String (optional) - The Application Toast Activator CLSID. Needed +for participating in Action Center. diff --git a/filenames.gni b/filenames.gni index 0e171f24dd9..b4041dca575 100644 --- a/filenames.gni +++ b/filenames.gni @@ -490,6 +490,7 @@ filenames = { "shell/common/gin_converters/file_path_converter.h", "shell/common/gin_converters/gfx_converter.cc", "shell/common/gin_converters/gfx_converter.h", + "shell/common/gin_converters/guid_converter.h", "shell/common/gin_converters/gurl_converter.h", "shell/common/gin_converters/image_converter.cc", "shell/common/gin_converters/image_converter.h", diff --git a/shell/common/api/electron_api_shell.cc b/shell/common/api/electron_api_shell.cc index 826d4563378..9f302331e26 100644 --- a/shell/common/api/electron_api_shell.cc +++ b/shell/common/api/electron_api_shell.cc @@ -6,6 +6,7 @@ #include "shell/common/gin_converters/callback_converter.h" #include "shell/common/gin_converters/file_path_converter.h" +#include "shell/common/gin_converters/guid_converter.h" #include "shell/common/gin_converters/gurl_converter.h" #include "shell/common/gin_helper/dictionary.h" #include "shell/common/gin_helper/error_thrower.h" @@ -127,6 +128,7 @@ bool WriteShortcutLink(const base::FilePath& shortcut_path, base::win::ShortcutProperties properties; base::FilePath path; base::string16 str; + UUID toastActivatorClsid; int index; if (options.Get("target", &path)) properties.set_target(path); @@ -140,6 +142,8 @@ bool WriteShortcutLink(const base::FilePath& shortcut_path, properties.set_icon(path, index); if (options.Get("appUserModelId", &str)) properties.set_app_id(str); + if (options.Get("toastActivatorClsid", &toastActivatorClsid)) + properties.set_toast_activator_clsid(toastActivatorClsid); base::win::ScopedCOMInitializer com_initializer; return base::win::CreateOrUpdateShortcutLink(shortcut_path, properties, @@ -164,6 +168,7 @@ v8::Local ReadShortcutLink(gin_helper::ErrorThrower thrower, options.Set("icon", properties.icon); options.Set("iconIndex", properties.icon_index); options.Set("appUserModelId", properties.app_id); + options.Set("toastActivatorClsid", properties.toast_activator_clsid); return gin::ConvertToV8(thrower.isolate(), options); } #endif diff --git a/shell/common/gin_converters/guid_converter.h b/shell/common/gin_converters/guid_converter.h index 6df8e132cbf..4ecdc9c5bfd 100644 --- a/shell/common/gin_converters/guid_converter.h +++ b/shell/common/gin_converters/guid_converter.h @@ -7,6 +7,9 @@ #if defined(OS_WIN) #include + +#include "base/strings/sys_string_conversions.h" +#include "base/win/win_util.h" #endif #include @@ -14,6 +17,7 @@ #if defined(OS_WIN) typedef GUID UUID; +const GUID GUID_NULL = {}; #else typedef struct { } UUID; @@ -34,6 +38,9 @@ struct Converter { UUID uid; if (guid.length() > 0) { + if (guid[0] == '{' && guid[guid.length() - 1] == '}') { + guid = guid.substr(1, guid.length() - 2); + } unsigned char* uid_cstr = (unsigned char*)guid.c_str(); RPC_STATUS result = UuidFromStringA(uid_cstr, &uid); if (result == RPC_S_INVALID_STRING_UUID) { @@ -46,6 +53,18 @@ struct Converter { return false; #else return false; +#endif + } + static v8::Local ToV8(v8::Isolate* isolate, UUID val) { +#if defined(OS_WIN) + if (val == GUID_NULL) { + return StringToV8(isolate, ""); + } else { + std::wstring uid = base::win::WStringFromGUID(val); + return StringToV8(isolate, base::SysWideToUTF8(uid)); + } +#else + return v8::Undefined(isolate); #endif } }; diff --git a/spec/api-shell-spec.js b/spec/api-shell-spec.js index 9f38b407c6c..284dd62864d 100644 --- a/spec/api-shell-spec.js +++ b/spec/api-shell-spec.js @@ -15,7 +15,8 @@ describe('shell module', () => { args: 'args', appUserModelId: 'appUserModelId', icon: 'icon', - iconIndex: 1 + iconIndex: 1, + toastActivatorClsid: '{0E3CFA27-6FEA-410B-824F-A174B6E865E5}' }; describe('shell.readShortcutLink(shortcutPath)', () => { @@ -76,7 +77,8 @@ describe('shell module', () => { args: 'args2', appUserModelId: 'appUserModelId2', icon: 'icon2', - iconIndex: 2 + iconIndex: 2, + toastActivatorClsid: '{C51A3996-CAD9-4934-848B-16285D4A1496}' }; expect(shell.writeShortcutLink(tmpShortcut, 'replace', change)).to.be.true(); expect(shell.readShortcutLink(tmpShortcut)).to.deep.equal(change); diff --git a/spec/fixtures/assets/shortcut.lnk b/spec/fixtures/assets/shortcut.lnk index 5f325ca733ea337dd986b4544cda6570430e083d..8f04d3bfef2f752487d4c4a829a36ef8ca07dd38 100755 GIT binary patch delta 101 zcmbQlyq9^xOKmv@Js^xBhMf3HpRZCX S$0q-UCEH%4KAjxOXbS+nIThsq delta 77 zcmdnXJc)V2OGeJgB8>Vrr3?%VoD2*LWPr3`a6s^*t_Zh1J{Hcq{|HZ3n~{4CD9qps bl?&DInO`~I(tE{)hgWnTUj00|fzcKKXkHoo