fix: Menu accelerators not working (#15094)
This change fixes the regression in the menu accelerators working in linux, on some environments.
This commit is contained in:
parent
9e2b7dbea5
commit
5994bf6745
4 changed files with 63 additions and 11 deletions
|
@ -742,4 +742,46 @@ describe('Menu module', () => {
|
|||
expect(Menu.getApplicationMenu()).to.be.null()
|
||||
})
|
||||
})
|
||||
|
||||
describe('menu accelerators', () => {
|
||||
let testFn = it
|
||||
try {
|
||||
// We have other tests that check if native modules work, if we fail to require
|
||||
// robotjs let's skip this test to avoid false negatives
|
||||
require('robotjs')
|
||||
} catch (err) {
|
||||
testFn = it.skip
|
||||
}
|
||||
const sendRobotjsKey = (key, modifiers = [], delay = 500) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
require('robotjs').keyTap(key, modifiers)
|
||||
setTimeout(() => {
|
||||
resolve()
|
||||
}, delay)
|
||||
})
|
||||
}
|
||||
|
||||
testFn('menu accelerators perform the specified action', async () => {
|
||||
const menu = Menu.buildFromTemplate([
|
||||
{
|
||||
label: 'Test',
|
||||
submenu: [
|
||||
{
|
||||
label: 'Test Item',
|
||||
accelerator: 'Ctrl+T',
|
||||
click: () => {
|
||||
// Test will succeed, only when the menu accelerator action
|
||||
// is triggered
|
||||
Promise.resolve()
|
||||
},
|
||||
id: 'test'
|
||||
}
|
||||
]
|
||||
}
|
||||
])
|
||||
Menu.setApplicationMenu(menu)
|
||||
expect(Menu.getApplicationMenu()).to.not.be.null()
|
||||
await sendRobotjsKey('t', 'control')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue