Add option to normalize dialog access keys
This commit is contained in:
parent
0e5fc9c4e4
commit
eb533e04b9
1 changed files with 28 additions and 1 deletions
|
@ -38,6 +38,29 @@ const parseArgs = function (window, options, callback, ...args) {
|
||||||
return [window, options, callback]
|
return [window, options, callback]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const normalizeAccessKey = (text) => {
|
||||||
|
if (typeof text !== 'string') return text
|
||||||
|
|
||||||
|
// macOS does not have access keys so remove single ampersands
|
||||||
|
// and replace double ampersands with a single ampersand
|
||||||
|
if (process.platform === 'darwin') {
|
||||||
|
return text.replace(/&(&?)/g, '$1')
|
||||||
|
}
|
||||||
|
|
||||||
|
// Linux uses a single underscore as an access key prefix so escape
|
||||||
|
// existing single underscores with a second underscore, replace double
|
||||||
|
// ampersands with a single ampersand, and replace a single ampersand with
|
||||||
|
// a single underscore
|
||||||
|
if (process.platform === 'linux') {
|
||||||
|
return text.replace(/_/g, '__').replace(/&(.?)/g, (match, after) => {
|
||||||
|
if (after === '&') return after
|
||||||
|
return `_${after}`
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return text
|
||||||
|
}
|
||||||
|
|
||||||
const checkAppInitialized = function () {
|
const checkAppInitialized = function () {
|
||||||
if (!app.isReady()) {
|
if (!app.isReady()) {
|
||||||
throw new Error('dialog module can only be used after app is ready')
|
throw new Error('dialog module can only be used after app is ready')
|
||||||
|
@ -154,7 +177,7 @@ module.exports = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let {buttons, cancelId, defaultId, detail, icon, message, title, type} = options
|
let {buttons, cancelId, defaultId, detail, icon, message, title, type, normalizeAccessKeys} = options
|
||||||
|
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
type = 'none'
|
type = 'none'
|
||||||
|
@ -171,6 +194,10 @@ module.exports = {
|
||||||
throw new TypeError('Buttons must be an array')
|
throw new TypeError('Buttons must be an array')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (normalizeAccessKeys) {
|
||||||
|
buttons = buttons.map(normalizeAccessKey)
|
||||||
|
}
|
||||||
|
|
||||||
if (title == null) {
|
if (title == null) {
|
||||||
title = ''
|
title = ''
|
||||||
} else if (typeof title !== 'string') {
|
} else if (typeof title !== 'string') {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue