マルチウィンドウの電子アプリケーションがあります。つまり、ランチャー ウィンドウとメイン ウィンドウで構成されています。
メイン プロセスは最初にランチャーを表示し、すべてが初期化された後、ipc を介してイベントを取得し、ランチャーを非表示にしてメイン ウィンドウを表示します。
メイン ウィンドウで使用on('close')
して、ユーザーがメイン ウィンドウを閉じたことを検出し、ランチャーを再度表示して、ティアダウン ロジックを実行します。その後、アプリは終了します。
this.mainWindow = new BrowserWindow({width: 1024, height: 768, webPreferences: {nodeIntegration: true}});
this.mainWindow.setMenu(null);
this.mainWindow.on('close', () => {
this.logger.debug('"close" received');
this.mainWindow.hide();
this.launcherWindow.show();
this.sendShutdown();
});
これは非常にうまく機能します。今度は、この動作を Spectron と統合テストしたいと思います。ユーザーが閉じるをクリックすることをエミュレートして、ウィンドウに閉じる信号を送信する際に問題があります。
it('should start shutting down the services gracefully if the user clicks on the close button', async () => {
await app.client.windowByIndex(1);
await app.client.close();
//..... expectations that verify the launcher window is visible now
});
インデックス 1 のウィンドウがメイン ウィンドウであることを確認しました。メイン ウィンドウを閉じると呼び出さapp.client.close();
れますが、メイン ウィンドウのイベントがトリガーされていないことをログで確認できるon('close', )
ため、ランチャーに戻りません。
私が見逃している/誤解しているものはありますか?