Fix Notepad++ doesn't exit correctly while Windows 10 update restart

If Windows 10 update needs to restart, and Notepad++ has one (some) dirty document(s), and "Enable session snapshot and periodic backup" is not enabled, then WM_ENDSESSION is send with wParam == FALSE, not waiting for WM_QUERYENDSESSION's treatment finish. In this case Notepad++ should quit after saving its current session.

Fix #6086, fix #5831, fix #7854
This commit is contained in:
Don HO 2020-02-24 03:57:15 +01:00
parent 4d5abdf1c8
commit 62efa463b0
2 changed files with 18 additions and 0 deletions

View File

@ -382,6 +382,12 @@ private:
bool _isFileOpening = false;
bool _isAdministrator = false;
bool _isEndingSessionButNotReady = false; // If Windows 10 update needs to restart
// and Notepad++ has one (some) dirty document(s)
// and "Enable session snapshot and periodic backup" is not enabled
// then WM_ENDSESSION is send with wParam == FALSE
// in this case this boolean is set true, so Notepad++ will quit and its current session will be saved
ScintillaCtrls _scintillaCtrls4Plugins;
std::vector<std::pair<int, int> > _hideLinesMarks;

View File

@ -1855,13 +1855,25 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
updater.run(nppParam.shouldDoUAC());
}
}
// _isEndingSessionButNotReady is true means WM_QUERYENDSESSION is sent but no time to finish saving data
// then WM_ENDSESSION is sent with wParam == FALSE - Notepad++ should exit in this case
if (_isEndingSessionButNotReady)
::DestroyWindow(hwnd);
return TRUE;
}
case WM_ENDSESSION:
{
if (wParam == TRUE)
{
::DestroyWindow(hwnd);
}
else
{
_isEndingSessionButNotReady = true;
}
return 0;
}