2017-01-27 8 views
2

NodeJSとソケットioでチャットアプリケーションプロジェクトを開始しました。電子とソケットでウィンドウを閉じることができません

後でElectronフレームワークにアプリを追加することに決めました。チャットはウィンドウで開始しますが、このウィンドウを閉じることはできません。終了ボタンは何もしません。

問題がどこから来たのかを理解するために私のコードを研究したところ、私のmain.htmlのsocket.io.js行を削除してからアプリケーションを閉じることができましたが、クライアントのWebSocketはすべて動作を停止します。

<script src="/socket.io/socket.io.js"></script> 

私のmain.jsからの私のcreateWindow関数です

function createWindow() { 

    // Instantiate Express App 
    app.server = require(__dirname + '/app/app')(); 

    // Create the browser window. 
    win = new BrowserWindow(); 
    // win.maximize(); 

    // and load the index.html of the app. 
    win.loadURL('http://localhost:'+config.server.port); 
    // Open the DevTools. 
    // win.webContents.openDevTools(); 

    win.focus(); 

    // Emitted when the window is closed. 
    win.on('closed',() => { 
    console.log("close"); 
    // Dereference the window object, usually you would store windows 
    // in an array if your app supports multi windows, this is the time 
    // when you should delete the corresponding element. 
    win = null 
    }); 
} 

マイプロジェクトファイルツリーの外観のこの

main.js // Electron, create the window load the app.js 
/app/app.js // Express, all my socket function 
/views/main.html // Html 

のような私を助けてください!

答えて

2

私のmain.htmlで解決されたerffすべてを削除した後、この機能を持っていました。

/** 
    * Alert when user leave the page 
    * 
    */ 
    window.onbeforeunload = function (event) { 
    var message = 'Sure you want to leave?'; 
    if (typeof event == 'undefined') { 
     event = window.event; 
    } 
    if (event) { 
     event.returnValue = message; 
    } 
    return message; 
    } 
関連する問題