Skip to content

Commit

Permalink
fixup! fix: respect system language preferences on Win/macOS (#23247)
Browse files Browse the repository at this point in the history
  • Loading branch information
ckerr committed May 6, 2020
1 parent d24c298 commit 5f1fbb1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 0 additions & 2 deletions filenames.gni
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,6 @@ filenames = {
"shell/common/language_util_linux.cc",
"shell/common/language_util_mac.mm",
"shell/common/language_util_win.cc",
"shell/common/mac/main_application_bundle.h",
"shell/common/mac/main_application_bundle.mm",
"shell/common/mouse_util.cc",
"shell/common/mouse_util.h",
"shell/common/mac/main_application_bundle.h",
Expand Down
12 changes: 9 additions & 3 deletions shell/browser/api/atom_api_top_level_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -661,10 +661,16 @@ void TopLevelWindow::SetMenu(v8::Isolate* isolate, v8::Local<v8::Value> value) {
gin::V8ToString(isolate, object->GetConstructorName()) == "Menu" &&
mate::ConvertFromV8(isolate, value, &menu) && !menu.IsEmpty()) {
menu_.Reset(isolate, menu.ToV8());
window_->SetMenu(menu->model());

// We only want to update the menu if the menu has a non-zero item count,
// or we risk crashes.
if (menu->model()->GetItemCount() == 0) {
RemoveMenu();
} else {
window_->SetMenu(menu->model());
}
} else if (value->IsNull()) {
menu_.Reset();
window_->SetMenu(nullptr);
RemoveMenu();
} else {
isolate->ThrowException(
v8::Exception::TypeError(mate::StringToV8(isolate, "Invalid Menu")));
Expand Down
6 changes: 6 additions & 0 deletions spec-main/api-menu-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ describe('Menu module', function () {
}).to.throw(/Invalid template for MenuItem: must have at least one of label, role or type/)
})

it('throws when an non-array is passed as a template', () => {
expect(() => {
Menu.buildFromTemplate('hello' as any);
}).to.throw(/Invalid template for Menu: Menu template must be an array/);
});

describe('Menu sorting and building', () => {
describe('sorts groups', () => {
it('does a simple sort', () => {
Expand Down

0 comments on commit 5f1fbb1

Please sign in to comment.