8000 feat: read/write Toast Activator CLSID in shortcuts by bitdisaster · Pull Request #25493 · electron/electron · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: read/write Toast Activator CLSID in shortcuts 8000 #25493

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/api/structures/shortcut-details.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
1 change: 1 addition & 0 deletions filenames.gni
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions shell/common/api/electron_api_shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -108,6 +109,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);
Expand All @@ -121,6 +123,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,
Expand All @@ -145,6 +149,7 @@ v8::Local<v8::Value> 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
Expand Down
19 changes: 19 additions & 0 deletions shell/common/gin_converters/guid_converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@

#if defined(OS_WIN)
#include <rpc.h>

#include "base/strings/sys_string_conversions.h"
#include "base/win/win_util.h"
#endif
#include <string>

#include "gin/converter.h"

#if defined(OS_WIN)
typedef GUID UUID;
const GUID GUID_NULL = {};
#else
typedef struct {
} UUID;
Expand All @@ -34,6 +38,9 @@ struct Converter<UUID> {
UUID uid;

if (guid.length() > 0) {
if (guid[0] == '{' && guid[guid.length() - 1] == '}') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any particular reason to support these extra optional curlies? should we just require that the raw uuid be passed in?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its very common to have the curly brackets on Windows. Our own base::win::WStringFromGUID method adds them. So for consistency, I added support to read them with our without.

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) {
Expand All @@ -46,6 +53,18 @@ struct Converter<UUID> {
return false;
#else
return false;
#endif
}
static v8::Local<v8::Value> 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
}
};
Expand Down
6 changes: 4 additions & 2 deletions spec/api-shell-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)', () => {
Expand Down Expand Up @@ -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);
Expand Down
Binary file modified spec/fixtures/assets/shortcut.lnk
Binary file not shown.
0