fix: menus on Linux after window modification (#37908)

* fix: menus on Linux after window modification

Co-authored-by: David Sanders <dsanders11@ucsbalum.com>

* test: don't run on CI

Co-authored-by: David Sanders <dsanders11@ucsbalum.com>

* Update .patches

* chore: update patches

* test: refactor since types are off

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: David Sanders <dsanders11@ucsbalum.com>
Co-authored-by: Cheng Zhao <zcbenz@gmail.com>
Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
This commit is contained in:
trop[bot]
2023-04-14 09:18:42 -07:00
committed by GitHub
parent 07debe81dd
commit 5ecf2e24e4
3 changed files with 284 additions and 1 deletions

View File

@@ -1,6 +1,6 @@
import * as cp from 'child_process';
import * as path from 'path';
import { expect } from 'chai';
import { assert, expect } from 'chai';
import { BrowserWindow, Menu, MenuItem } from 'electron/main';
import { sortMenuItems } from '../lib/browser/api/menu-utils';
import { emittedOnce } from './events-helpers';
@@ -886,6 +886,48 @@ describe('Menu module', function () {
throw new Error('Menu is garbage-collected while popuping');
}
});
// https://github.com/electron/electron/issues/35724
// Maximizing window is enough to trigger the bug
// FIXME(dsanders11): Test always passes on CI, even pre-fix
ifit(process.platform === 'linux' && !process.env.CI)('does not trigger issue #35724', (done) => {
const showAndCloseMenu = async () => {
await delay(1000);
menu.popup({ window: w, x: 50, y: 50 });
await delay(500);
const closed = new Promise((resolve) => {
menu.once('menu-will-close', resolve);
});
menu.closePopup();
await closed;
};
const failOnEvent = () => { done(new Error('Menu closed prematurely')); };
assert(!w.isVisible());
w.on('show', async () => {
assert(!w.isMaximized());
// Show the menu once, then maximize window
await showAndCloseMenu();
// NOTE - 'maximize' event never fires on CI for Linux
const maximized = emittedOnce(w, 'maximize');
w.maximize();
await maximized;
// Bug only seems to trigger programmatically after showing the menu once more
await showAndCloseMenu();
// Now ensure the menu stays open until we close it
await delay(500);
menu.once('menu-will-close', failOnEvent);
menu.popup({ window: w, x: 50, y: 50 });
await delay(1500);
menu.removeListener('menu-will-close', failOnEvent);
menu.once('menu-will-close', () => done());
menu.closePopup();
});
w.show();
});
});
describe('Menu.setApplicationMenu', () => {