반응형
[ref:] https://www.electronjs.org/docs/latest/api/browser-window#event-close
const dialogPop = require('electron').remote.dialog;
// it starts with onbeforeunload with the boolean value true
let doNotCloseWindow = true;
window.onbeforeunload = (event) => {
//if the boolean value is true, the window do not close
if(doNotCloseWindow)
{
// equivalent to `return false` but not recommended
// it will prevent the window to be closed
event.returnValue = true;
//open popup
const dialogOpts = {
type: 'info',
title: 'close',
message: 'r u sure?',
buttons: ['OK', 'Cancel']
};
dialogPop.showMessageBox(dialogOpts).then((response) => {
// if OK, response.resonse = 0, else 1
if(response.response === 0){
doNotCloseWindow = false;
// it will call onbeforeunload again
window.close();
}
});
}
else
{
console.log('It should be closed')
//the window closes no matter what.. so not sure if destroy() works
window.destroy();
}
}
반응형
'초짜 IT보이 서바이벌 스토리' 카테고리의 다른 글
#electron #js #Crypto 사용 #복호화 #암호화 #예제 #example (0) | 2022.12.26 |
---|---|
Spring? & Spring Framework Overview (0) | 2022.09.19 |
#Windows10 #HDD #SDD #드라이브 #문자가 부팅 시 삭제 문제 해결 (31) | 2021.07.21 |
#windows #batch 에서 #linux #touch 명령어 같은 #echo (0) | 2020.09.21 |
#크롬브라우저 #NET::ERR_CERT_DATE_INVALID #SSL오류 (0) | 2020.06.08 |