Clase: CommandLine
Clase: CommandLine
Manipula los argumentos de la línea de comandos para tu aplicación que Chromium lee
Process: Main
This class is not exported from the 'electron'
module. Sólo está disponible como un valor de retorno de otros métodos en la API de Electron.
El siguiente ejemplo muestra como comprobar si la bandera --disable-gpu
está activada.
const { app } = require('electron')
app.commandLine.hasSwitch('disable-gpu')
For more information on what kinds of flags and switches you can use, check out the Command Line Switches document.
Métodos de Instancia
commandLine.appendSwitch(switch[, value])
switch
string - A command-line switch, without the leading--
.value
string (opcional) - Un valor para el cambio dado.
Adjuntar un cambio (con valor
opcional) al comando de de línea de Chromium.
[!NOTE] This will not affect
process.argv
. The intended usage of this function is to control Chromium's behavior.
const { app } = require('electron')
app.commandLine.appendSwitch('remote-debugging-port', '8315')
commandLine.appendArgument(value)
valor
string - El argumento a adjuntar a la línea de comando.
Agrega un argumento a la línea de comando de Chromium. El argumento será citado correctamente. Los interruptores precederán a los argumentos independientemente de orden agregado.
Si estas añadiendo un argumento como --switch=value
, considere usar en su lugar appendSwitch('switch', 'value')
.
const { app } = require('electron')
app.commandLine.appendArgument('--enable-experimental-web-platform-features')
[!NOTE] This will not affect
process.argv
. The intended usage of this function is to control Chromium's behavior.
commandLine.hasSwitch(switch)
switch
string - Un cambio en la línea de comando.
Devuelve boolean
- Si el interruptor de la línea de comando esta presente.
const { app } = require('electron')
app.commandLine.appendSwitch('remote-debugging-port', '8315')
const hasPort = app.commandLine.hasSwitch('remote-debugging-port')
console.log(hasPort) // true
commandLine.getSwitchValue(switch)
switch
string - Un cambio en la línea de comando.
Devuelve string
- El valor del interruptor de la linea de comando.
This function is meant to obtain Chromium command line switches. It is not meant to be used for application-specific command line arguments. For the latter, please use process.argv
.
const { app } = require('electron')
app.commandLine.appendSwitch('remote-debugging-port', '8315')
const portValue = app.commandLine.getSwitchValue('remote-debugging-port')
console.log(portValue) // '8315'
[!NOTE] When the switch is not present or has no value, it returns empty string.
commandLine.removeSwitch(switch)
switch
string - Un cambio en la línea de comando.
Removes the specified switch from Chromium's command line.
const { app } = require('electron')
app.commandLine.appendSwitch('remote-debugging-port', '8315')
console.log(app.commandLine.hasSwitch('remote-debugging-port')) // true
app.commandLine.removeSwitch('remote-debugging-port')
console.log(app.commandLine.hasSwitch('remote-debugging-port')) // false
[!NOTE] This will not affect
process.argv
. The intended usage of this function is to control Chromium's behavior.