From a38b711fb10ebc2c8f0ee925fb68453601608396 Mon Sep 17 00:00:00 2001 From: Milan Burda Date: Tue, 14 Feb 2023 09:53:18 +0100 Subject: [PATCH] feat: add logUsage to shell.openExternal() options (#37139) Co-authored-by: Milan Burda --- docs/api/shell.md | 2 ++ shell/common/api/electron_api_shell.cc | 1 + shell/common/platform_util.h | 1 + shell/common/platform_util_win.cc | 17 +++++++++++++---- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/docs/api/shell.md b/docs/api/shell.md index a0e34c0dbe61..f278c4bbddaf 100644 --- a/docs/api/shell.md +++ b/docs/api/shell.md @@ -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` diff --git a/shell/common/api/electron_api_shell.cc b/shell/common/api/electron_api_shell.cc index 690ae39137aa..0039b9596188 100644 --- a/shell/common/api/electron_api_shell.cc +++ b/shell/common/api/electron_api_shell.cc @@ -64,6 +64,7 @@ v8::Local 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); } } diff --git a/shell/common/platform_util.h b/shell/common/platform_util.h index 59004489d293..cdb84f9b3f89 100644 --- a/shell/common/platform_util.h +++ b/shell/common/platform_util.h @@ -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. diff --git a/shell/common/platform_util_win.cc b/shell/common/platform_util_win.cc index 5ddcb49a35b2..233cc6612b88 100644 --- a/shell/common/platform_util_win.cc +++ b/shell/common/platform_util_win.cc @@ -246,10 +246,19 @@ std::string OpenExternalOnWorkerThread( L"\""; std::wstring working_dir = options.working_dir.value(); - if (reinterpret_cast( - 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()); }