Skip to content
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

feat: add logUsage to shell.openExternal() options #37291

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/api/shell.md
Expand Up @@ -40,6 +40,8 @@ Open the given file in the desktop's default manner.
* `options` Object (optional)
* `activate` boolean (optional) _macOS_ - `true` to bring the opened application to the foreground. The default is `true`.
* `workingDirectory` string (optional) _Windows_ - The working directory.
* `logUsage` boolean (optional) _Windows_ - Indicates a user initiated launch that enables tracking of frequently used programs and other behaviors.
The default is `false`.

Returns `Promise<void>`

Expand Down
1 change: 1 addition & 0 deletions shell/common/api/electron_api_shell.cc
Expand Up @@ -64,6 +64,7 @@ v8::Local<v8::Promise> OpenExternal(const GURL& url, gin::Arguments* args) {
if (args->GetNext(&obj)) {
obj.Get("activate", &options.activate);
obj.Get("workingDirectory", &options.working_dir);
obj.Get("logUsage", &options.log_usage);
}
}

Expand Down
1 change: 1 addition & 0 deletions shell/common/platform_util.h
Expand Up @@ -28,6 +28,7 @@ void OpenPath(const base::FilePath& full_path, OpenCallback callback);
struct OpenExternalOptions {
bool activate = true;
base::FilePath working_dir;
bool log_usage = false;
};

// Open the given external protocol URL in the desktop's default manner.
Expand Down
17 changes: 13 additions & 4 deletions shell/common/platform_util_win.cc
Expand Up @@ -246,10 +246,19 @@ std::string OpenExternalOnWorkerThread(
L"\"";
std::wstring working_dir = options.working_dir.value();

if (reinterpret_cast<ULONG_PTR>(
ShellExecuteW(nullptr, L"open", escaped_url.c_str(), nullptr,
working_dir.empty() ? nullptr : working_dir.c_str(),
SW_SHOWNORMAL)) <= 32) {
SHELLEXECUTEINFO info = {};
info.cbSize = sizeof(SHELLEXECUTEINFO);
info.fMask = SEE_MASK_NOASYNC | SEE_MASK_FLAG_NO_UI;
info.lpVerb = L"open";
info.lpFile = escaped_url.c_str();
info.lpDirectory = working_dir.empty() ? nullptr : working_dir.c_str();
info.nShow = SW_SHOWNORMAL;

if (options.log_usage) {
info.fMask |= SEE_MASK_FLAG_LOG_USAGE;
}

if (!ShellExecuteEx(&info)) {
return "Failed to open: " +
logging::SystemErrorCodeToString(logging::GetLastSystemErrorCode());
}
Expand Down