feat: add logUsage to shell.openExternal() options (#37139)
Co-authored-by: Milan Burda <miburda@microsoft.com>
This commit is contained in:
parent
3972073116
commit
a38b711fb1
4 changed files with 17 additions and 4 deletions
|
@ -40,6 +40,8 @@ Open the given file in the desktop's default manner.
|
||||||
* `options` Object (optional)
|
* `options` Object (optional)
|
||||||
* `activate` boolean (optional) _macOS_ - `true` to bring the opened application to the foreground. The default is `true`.
|
* `activate` boolean (optional) _macOS_ - `true` to bring the opened application to the foreground. The default is `true`.
|
||||||
* `workingDirectory` string (optional) _Windows_ - The working directory.
|
* `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>`
|
Returns `Promise<void>`
|
||||||
|
|
||||||
|
|
|
@ -64,6 +64,7 @@ v8::Local<v8::Promise> OpenExternal(const GURL& url, gin::Arguments* args) {
|
||||||
if (args->GetNext(&obj)) {
|
if (args->GetNext(&obj)) {
|
||||||
obj.Get("activate", &options.activate);
|
obj.Get("activate", &options.activate);
|
||||||
obj.Get("workingDirectory", &options.working_dir);
|
obj.Get("workingDirectory", &options.working_dir);
|
||||||
|
obj.Get("logUsage", &options.log_usage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ void OpenPath(const base::FilePath& full_path, OpenCallback callback);
|
||||||
struct OpenExternalOptions {
|
struct OpenExternalOptions {
|
||||||
bool activate = true;
|
bool activate = true;
|
||||||
base::FilePath working_dir;
|
base::FilePath working_dir;
|
||||||
|
bool log_usage = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Open the given external protocol URL in the desktop's default manner.
|
// Open the given external protocol URL in the desktop's default manner.
|
||||||
|
|
|
@ -246,10 +246,19 @@ std::string OpenExternalOnWorkerThread(
|
||||||
L"\"";
|
L"\"";
|
||||||
std::wstring working_dir = options.working_dir.value();
|
std::wstring working_dir = options.working_dir.value();
|
||||||
|
|
||||||
if (reinterpret_cast<ULONG_PTR>(
|
SHELLEXECUTEINFO info = {};
|
||||||
ShellExecuteW(nullptr, L"open", escaped_url.c_str(), nullptr,
|
info.cbSize = sizeof(SHELLEXECUTEINFO);
|
||||||
working_dir.empty() ? nullptr : working_dir.c_str(),
|
info.fMask = SEE_MASK_NOASYNC | SEE_MASK_FLAG_NO_UI;
|
||||||
SW_SHOWNORMAL)) <= 32) {
|
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: " +
|
return "Failed to open: " +
|
||||||
logging::SystemErrorCodeToString(logging::GetLastSystemErrorCode());
|
logging::SystemErrorCodeToString(logging::GetLastSystemErrorCode());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue