Skip to content

Commit

Permalink
fix: pass noLink correctly on Windows (#21386)
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere authored and deepak1556 committed Dec 5, 2019
1 parent 93802a7 commit 9e189ea
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 16 deletions.
6 changes: 3 additions & 3 deletions lib/browser/api/dialog.js
Expand Up @@ -163,6 +163,7 @@ const messageBox = (sync, window, options) => {
defaultId = -1,
detail = '',
icon = null,
noLink = false,
message = '',
title = '',
type = 'none'
Expand All @@ -173,6 +174,7 @@ const messageBox = (sync, window, options) => {
if (!Array.isArray(buttons)) throw new TypeError('Buttons must be an array')
if (options.normalizeAccessKeys) buttons = buttons.map(normalizeAccessKey)
if (typeof title !== 'string') throw new TypeError('Title must be a string')
if (typeof noLink !== 'boolean') throw new TypeError('noLink must be a boolean')
if (typeof message !== 'string') throw new TypeError('Message must be a string')
if (typeof detail !== 'string') throw new TypeError('Detail must be a string')
if (typeof checkboxLabel !== 'string') throw new TypeError('checkboxLabel must be a string')
Expand All @@ -195,15 +197,13 @@ const messageBox = (sync, window, options) => {
}
}

const flags = options.noLink ? messageBoxOptions.noLink : 0

const settings = {
window,
messageBoxType,
buttons,
defaultId,
cancelId,
flags,
noLink,
title,
message,
detail,
Expand Down
7 changes: 1 addition & 6 deletions shell/browser/ui/message_box.h
Expand Up @@ -25,11 +25,6 @@ enum class MessageBoxType {
kQuestion,
};

enum MessageBoxOptions {
MESSAGE_BOX_NONE = 0,
MESSAGE_BOX_NO_LINK = 1 << 0,
};

using DialogResult = std::pair<int, bool>;

struct MessageBoxSettings {
Expand All @@ -38,7 +33,7 @@ struct MessageBoxSettings {
std::vector<std::string> buttons;
int default_id;
int cancel_id;
int options = electron::MessageBoxOptions::MESSAGE_BOX_NONE;
bool no_link = false;
std::string title;
std::string message;
std::string detail;
Expand Down
12 changes: 6 additions & 6 deletions shell/browser/ui/message_box_win.cc
Expand Up @@ -83,7 +83,7 @@ DialogResult ShowTaskDialogUTF16(NativeWindow* parent,
const std::vector<base::string16>& buttons,
int default_id,
int cancel_id,
int options,
bool no_link,
const base::string16& title,
const base::string16& message,
const base::string16& detail,
Expand Down Expand Up @@ -156,7 +156,7 @@ DialogResult ShowTaskDialogUTF16(NativeWindow* parent,
// and custom buttons in pButtons.
std::map<int, int> id_map;
std::vector<TASKDIALOG_BUTTON> dialog_buttons;
if (options & MESSAGE_BOX_NO_LINK) {
if (no_link) {
for (size_t i = 0; i < buttons.size(); ++i)
dialog_buttons.push_back(
{static_cast<int>(i + kIDStart), buttons[i].c_str()});
Expand All @@ -166,7 +166,7 @@ DialogResult ShowTaskDialogUTF16(NativeWindow* parent,
if (dialog_buttons.size() > 0) {
config.pButtons = &dialog_buttons.front();
config.cButtons = dialog_buttons.size();
if (!(options & MESSAGE_BOX_NO_LINK))
if (!no_link)
config.dwFlags |= TDF_USE_COMMAND_LINKS; // custom buttons as links.
}

Expand Down Expand Up @@ -200,7 +200,7 @@ DialogResult ShowTaskDialogUTF8(const MessageBoxSettings& settings) {

return ShowTaskDialogUTF16(
settings.parent_window, settings.type, utf16_buttons, settings.default_id,
settings.cancel_id, settings.options, title_16, message_16, detail_16,
settings.cancel_id, settings.no_link, title_16, message_16, detail_16,
checkbox_label_16, settings.checkbox_checked, settings.icon);
}

Expand Down Expand Up @@ -242,8 +242,8 @@ void ShowMessageBox(const MessageBoxSettings& settings,

void ShowErrorBox(const base::string16& title, const base::string16& content) {
electron::UnresponsiveSuppressor suppressor;
ShowTaskDialogUTF16(nullptr, MessageBoxType::kError, {}, -1, 0, 0, L"Error",
title, content, L"", false, gfx::ImageSkia());
ShowTaskDialogUTF16(nullptr, MessageBoxType::kError, {}, -1, 0, false,
L"Error", title, content, L"", false, gfx::ImageSkia());
}

} // namespace electron
2 changes: 1 addition & 1 deletion shell/common/gin_converters/message_box_converter.cc
Expand Up @@ -24,11 +24,11 @@ bool Converter<electron::MessageBoxSettings>::FromV8(
dict.Get("buttons", &out->buttons);
dict.Get("defaultId", &out->default_id);
dict.Get("cancelId", &out->cancel_id);
dict.Get("options", &out->options);
dict.Get("title", &out->title);
dict.Get("message", &out->message);
dict.Get("detail", &out->detail);
dict.Get("checkboxLabel", &out->checkbox_label);
dict.Get("noLink", &out->no_link);
dict.Get("checkboxChecked", &out->checkbox_checked);
dict.Get("icon", &out->icon);
return true;
Expand Down

0 comments on commit 9e189ea

Please sign in to comment.