Merge branch 'master' into native-window-open
This commit is contained in:
commit
61fa8693d2
105 changed files with 2439 additions and 907 deletions
|
@ -154,6 +154,68 @@ const roles = {
|
|||
webContents.setZoomLevel(zoomLevel - 0.5)
|
||||
})
|
||||
}
|
||||
},
|
||||
// Edit submenu (should fit both Mac & Windows)
|
||||
editMenu: {
|
||||
label: 'Edit',
|
||||
submenu: [
|
||||
{
|
||||
role: 'undo'
|
||||
},
|
||||
{
|
||||
role: 'redo'
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
role: 'cut'
|
||||
},
|
||||
{
|
||||
role: 'copy'
|
||||
},
|
||||
{
|
||||
role: 'paste'
|
||||
},
|
||||
|
||||
process.platform === 'darwin' ? {
|
||||
role: 'pasteandmatchstyle'
|
||||
} : null,
|
||||
|
||||
{
|
||||
role: 'delete'
|
||||
},
|
||||
|
||||
process.platform === 'win32' ? {
|
||||
type: 'separator'
|
||||
} : null,
|
||||
|
||||
{
|
||||
role: 'selectall'
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
// Window submenu should be used for Mac only
|
||||
windowMenu: {
|
||||
label: 'Window',
|
||||
submenu: [
|
||||
{
|
||||
role: 'minimize'
|
||||
},
|
||||
{
|
||||
role: 'close'
|
||||
},
|
||||
|
||||
process.platform === 'darwin' ? {
|
||||
type: 'separator'
|
||||
} : null,
|
||||
|
||||
process.platform === 'darwin' ? {
|
||||
role: 'front'
|
||||
} : null
|
||||
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -176,6 +238,19 @@ exports.getDefaultAccelerator = (role) => {
|
|||
if (roles.hasOwnProperty(role)) return roles[role].accelerator
|
||||
}
|
||||
|
||||
exports.getDefaultSubmenu = (role) => {
|
||||
if (!roles.hasOwnProperty(role)) return
|
||||
|
||||
let {submenu} = roles[role]
|
||||
|
||||
// remove null items from within the submenu
|
||||
if (Array.isArray(submenu)) {
|
||||
submenu = submenu.filter((item) => item != null)
|
||||
}
|
||||
|
||||
return submenu
|
||||
}
|
||||
|
||||
exports.execute = (role, focusedWindow, focusedWebContents) => {
|
||||
if (!canExecuteRole(role)) return false
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ const MenuItem = function (options) {
|
|||
for (let key in options) {
|
||||
if (!(key in this)) this[key] = options[key]
|
||||
}
|
||||
|
||||
this.submenu = this.submenu || roles.getDefaultSubmenu(this.role)
|
||||
if (this.submenu != null && this.submenu.constructor !== Menu) {
|
||||
this.submenu = Menu.buildFromTemplate(this.submenu)
|
||||
}
|
||||
|
|
|
@ -156,9 +156,15 @@ class ClientRequest extends EventEmitter {
|
|||
urlStr = url.format(urlObj)
|
||||
}
|
||||
|
||||
const redirectPolicy = options.redirect || 'follow'
|
||||
if (!['follow', 'error', 'manual'].includes(redirectPolicy)) {
|
||||
throw new Error('redirect mode should be one of follow, error or manual')
|
||||
}
|
||||
|
||||
let urlRequestOptions = {
|
||||
method: method,
|
||||
url: urlStr
|
||||
url: urlStr,
|
||||
redirect: redirectPolicy
|
||||
}
|
||||
if (options.session) {
|
||||
if (options.session instanceof Session) {
|
||||
|
@ -240,7 +246,7 @@ class ClientRequest extends EventEmitter {
|
|||
if (typeof name !== 'string') {
|
||||
throw new TypeError('`name` should be a string in setHeader(name, value).')
|
||||
}
|
||||
if (value === undefined) {
|
||||
if (value == null) {
|
||||
throw new Error('`value` required in setHeader("' + name + '", value).')
|
||||
}
|
||||
if (!this.urlRequest.notStarted) {
|
||||
|
@ -249,11 +255,11 @@ class ClientRequest extends EventEmitter {
|
|||
|
||||
const key = name.toLowerCase()
|
||||
this.extraHeaders[key] = value
|
||||
this.urlRequest.setExtraHeader(name, value)
|
||||
this.urlRequest.setExtraHeader(name, value.toString())
|
||||
}
|
||||
|
||||
getHeader (name) {
|
||||
if (arguments.length < 1) {
|
||||
if (name == null) {
|
||||
throw new Error('`name` is required for getHeader(name).')
|
||||
}
|
||||
|
||||
|
@ -266,7 +272,7 @@ class ClientRequest extends EventEmitter {
|
|||
}
|
||||
|
||||
removeHeader (name) {
|
||||
if (arguments.length < 1) {
|
||||
if (name == null) {
|
||||
throw new Error('`name` is required for removeHeader(name).')
|
||||
}
|
||||
|
||||
|
@ -339,6 +345,10 @@ class ClientRequest extends EventEmitter {
|
|||
return this._write(data, encoding, callback, true)
|
||||
}
|
||||
|
||||
followRedirect () {
|
||||
this.urlRequest.followRedirect()
|
||||
}
|
||||
|
||||
abort () {
|
||||
this.urlRequest.cancel()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue