クラス: CommandLine
クラス: CommandLine
Chromium が読み取るアプリのコマンドライン引数を操作します
Process: Main
This class is not exported from the 'electron'
module. Electron API では、他のメソッドの戻り値としてのみ利用できます。
以下の例は、-disable-gpu
フラグが設定されているかどうかを確認する方法を示しています。
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.
インスタンスメソッド
commandLine.appendSwitch(switch[, value])
switch
string - A command-line switch, without the leading--
.value
string (任意) - 与えられたスイッチの値.
Chromiumのコマンドラインに (オプションの value
と一緒に) スイッチを追加します。
注: これはprocess.argv
に影響を与えません。 この関数は主に Chromium の振る舞いを制御するために使われます。
const { app } = require('electron')
app.commandLine.appendSwitch('remote-debugging-port', '8315')
commandLine.appendArgument(value)
value
string - コマンドラインに追加された引数.
Chromiumのコマンドラインに引数を追加します。 引数は正しく引用符で囲ってください。 スイッチは、追加順序に関係なく引数に先行します。
--switch=value
のような引数を追加している場合は、代わりに appendSwitch('switch', 'value')
を使用することを検討してください。
const { app } = require('electron')
app.commandLine.appendArgument('--enable-experimental-web-platform-features')
注: これはprocess.argv
に影響を与えません。 この関数は主に Chromium の振る舞いを制御するために使われます。
commandLine.hasSwitch(switch)
switch
string - コマンドラインスイッチ.
戻り値 boolean
- コマンドラインスイッチがあるかどうか。
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 - コマンドラインスイッチ.
戻り値 string
- コマンドラインスイッチの値
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'
注意: スイッチが存在しないか値がない場合、これは空文字列を返します。
commandLine.removeSwitch(switch)
switch
string - コマンドラインスイッチ.
Chromium のコマンドラインから指定したスイッチを削除します。
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
注: これはprocess.argv
に影響を与えません。 この関数は主に Chromium の振る舞いを制御するために使われます。