2017-08-29 6 views
0

実行中の電子プログラムにパラメータ値を渡したいが失敗した。どうすればいいのか教えてください。実行中のElectronプログラムに引数値を渡すにはどうすればよいですか?

私は何が欠けていますか?

// package.json 
{ 
    "name": "electron-quick-start", 
    "version": "1.0.0", 
    "description": "A minimal Electron application", 
    "main": "main.js" 
    ... 
} 

以下はメインプロセスファイルです。

CMD> npm start ARG1 ARG2 --enable-logging 
[ '{PROJECT_PATH}\\electron.exe', 
    '.', 
    'ARG1', 
    'ARG2' ] 

新しいコマンドプロンプト含量:以下にコマンドプロンプト結果に上記のコード実行

// main.js 
const electron = require('electron') 
const app = electron.app 
const console = require('console'); 
app.console = new console.Console(process.stdout, process.stderr); 

let mainWindow 

/* Single Instance Check */ 
var iShouldQuit = app.makeSingleInstance(function(commandLine, workingDirectory) { 
    if (mainWindow) { 
     if (mainWindow.isMinimized()) mainWindow.restore(); 
     mainWindow.show(); 
     mainWindow.focus(); 
    } 
    return true; 
}); 
if(iShouldQuit){app.quit();return;} 

// Argument value output. 
console.log(process.argv) 

セカンドランで

CMD> npm start ARG3 ARG4 --enable-logging 
// "There is no message." 

を、所望の結果が表示されません。

私はあなたに何をすべきかを知ってほしいです。

**私が望む結果は次のとおりです。**

新しいコマンドプロンプト内容:

// While the program is already running ... 
CMD> npm start ARG5 ARG6 --enable-logging 
[ '{PROJECT_PATH}\\electron.exe', 
    '.', 
    'ARG5', 
    'ARG6' ] 

答えて

0

私は問題を解決!

'makeSingleInstance'の最初のパラメータ値が正しいです!

私はマニュアルをよく見なければなりませんでした!

// main.js 
/* Single Instance Check */ 
var iShouldQuit = app.makeSingleInstance(function(commandLine, workingDirectory) { 

    // Here was the answer I was looking for! 
    console.log(commandLine) 

    if (mainWindow) { 
     if (mainWindow.isMinimized()) mainWindow.restore(); 
     mainWindow.show(); 
     mainWindow.focus(); 
    } 
    return true; 
}); 
if(iShouldQuit){app.quit();return;} 
関連する問題