終了する前にAPI呼び出しを行う必要のあるアプリケーションがあります(ログアウトのようなものです)。私はAPIコールのためにまだいくつかのアプリケーションデータ(reduxストア)にアクセスする必要があるので、私はappで 'before-quit'イベントを聞くことに決めました。電子(アトムシェル)の 'before-quit'イベントの使用
私は、次のコードを試してみました:
import {remote} from 'electron';
let loggedout = false;
remote.app.on('before-quit', (event) => {
if (loggedout) return; // if we are logged out just quit.
console.warn('users tries to quit');
// prevent the default which should cancel the quit
event.preventDefault();
// in the place of the setTimout will be an API call
setTimeout(() => {
// if api call was a success
if (true) {
loggedout = true;
remote.app.quit();
} else {
// tell the user log-out was not successfull. retry and quit after second try.
}
}, 1000);
});
イベントを発生したり、シャットダウンを防止することは動作しないようだことはありません。 before-quit
をbrowser-window-blur
と交換すると、はになり、コードが正常に機能しているように見えます。
私はElectron 1.2.8を使用しています(アップグレードできない依存関係のため)。私はダブルチェックしてbefore-quit
イベントはすでにそのバージョンでimplementedだった。
このイベントが発生していないようなアイデアはありますか?
ありがとうございました!