Saltar al contenido principal

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.

Nota: Esto no afectará a process.argv. El uso previsto de esta función is controlar el comportamiento de Chromium.

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')

Nota: Esto no afectará a process.argv. El uso previsto de esta función is controlar el comportamiento de Chromium.

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: Cando el interruptor no esta presento o no tiene un valor, revuelve una cadena vacía.

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

Nota: Esto no afectará a process.argv. El uso previsto de esta función is controlar el comportamiento de Chromium.