From ed3da927cc1acfac4097ba7584737f9810d21c34 Mon Sep 17 00:00:00 2001 From: ge0rdi Date: Wed, 9 Sep 2020 21:11:10 +0200 Subject: [PATCH] Update: Use desktop toast notifications on Windows 10 Use toast notification to announce new update on modern Windows versions. The advantage of toasts is that they look more natural and they are persistent. So one can find the information about new update in action center even after notification timed out. --- Src/Setup/BuildBinaries.bat | 3 + Src/Setup/Setup.wxs | 15 ++++- Src/Update/Update.cpp | 109 +++++++++++++++++++++--------------- 3 files changed, 80 insertions(+), 47 deletions(-) diff --git a/Src/Setup/BuildBinaries.bat b/Src/Setup/BuildBinaries.bat index 55b03ac..f1f8149 100644 --- a/Src/Setup/BuildBinaries.bat +++ b/Src/Setup/BuildBinaries.bat @@ -38,6 +38,7 @@ copy /B ..\ClassicIE\Setup\ClassicIE_32.exe Output > nul copy /B ..\StartMenu\Setup\StartMenu.exe Output > nul copy /B ..\StartMenu\Setup\StartMenuDLL.dll Output > nul copy /B ..\Update\Release\Update.exe Output > nul +copy /B ..\Update\DesktopToasts\Release\DesktopToasts.dll Output > nul copy /B ..\StartMenu\StartMenuHelper\Setup\StartMenuHelper32.dll Output > nul copy /B ..\Setup\SetupHelper\Release\SetupHelper.exe Output > nul @@ -99,6 +100,8 @@ copy /B ..\StartMenu\StartMenuHelper\Setup\StartMenuHelper32.pdb Output\PDB32 > copy /B Output\StartMenuHelper32.dll Output\PDB32 > nul copy /B ..\Update\Release\Update.pdb Output\PDB32 > nul copy /B Output\Update.exe Output\PDB32 > nul +copy /B ..\Update\DesktopToasts\Release\DesktopToasts.pdb Output\PDB32 > nul +copy /B Output\DesktopToasts.dll Output\PDB32 > nul REM Menu 64 copy /B ..\StartMenu\Setup64\StartMenu.pdb Output\PDB64 > nul diff --git a/Src/Setup/Setup.wxs b/Src/Setup/Setup.wxs index 9706cac..eb9c07d 100644 --- a/Src/Setup/Setup.wxs +++ b/Src/Setup/Setup.wxs @@ -105,7 +105,9 @@ + + @@ -476,6 +478,9 @@ + + + @@ -551,6 +556,11 @@ + + + + + @@ -564,7 +574,10 @@ START_MENU_FOLDER=1 - + + + + START_MENU_FOLDER=1 diff --git a/Src/Update/Update.cpp b/Src/Update/Update.cpp index 1a99e80..6f522b5 100644 --- a/Src/Update/Update.cpp +++ b/Src/Update/Update.cpp @@ -16,6 +16,7 @@ #include "ResourceHelper.h" #include "Translations.h" #include +#include "DesktopToasts/DesktopToasts.h" void ClosingSettings( HWND hWnd, int flags, int command ) @@ -487,8 +488,6 @@ int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpstrC CString language=GetSettingString(L"Language"); ParseTranslations(NULL,language); - g_Instance=hInstance; - HINSTANCE resInstance=LoadTranslationDll(language); LoadTranslationResources(resInstance,g_LoadDialogs); @@ -500,6 +499,9 @@ int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpstrC COwnerWindow ownerWindow; ownerWindow.Create(NULL,0,0,WS_POPUP); + + DesktopToasts toasts(L"OpenShell.Update"); + if (wcsstr(lpstrCmdLine,L"-popup")!=NULL) { g_UpdateDlg.UpdateData(); @@ -507,52 +509,67 @@ int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpstrC int sleep=5000-(timeGetTime()-time0); if (sleep>0) Sleep(sleep); - HWND balloon=CreateWindowEx(WS_EX_TOPMOST|WS_EX_TOOLWINDOW|(IsLanguageRTL()?WS_EX_LAYOUTRTL:0),TOOLTIPS_CLASS,NULL,WS_POPUP|TTS_CLOSE|TTS_NOPREFIX,0,0,0,0,NULL,NULL,g_Instance,NULL); - SendMessage(balloon,TTM_SETMAXTIPWIDTH,0,500); - TOOLINFO tool={sizeof(tool),TTF_ABSOLUTE|TTF_TRANSPARENT|TTF_TRACK|(IsLanguageRTL()?TTF_RTLREADING:0U)}; - tool.uId=1; - CString message=LoadStringEx(g_UpdateDlg.HasNewLanguage()?IDS_LANG_NEWVERSION:IDS_NEWVERSION); - tool.lpszText=(wchar_t*)(const wchar_t*)message; - SendMessage(balloon,TTM_ADDTOOL,0,(LPARAM)&tool); - SendMessage(balloon,TTM_SETTITLE,(WPARAM)LoadIcon(g_Instance,MAKEINTRESOURCE(IDI_APPICON)),(LPARAM)(const wchar_t*)LoadStringEx(IDS_UPDATE_TITLE)); - APPBARDATA appbar={sizeof(appbar)}; - SHAppBarMessage(ABM_GETTASKBARPOS,&appbar); - MONITORINFO info={sizeof(info)}; - GetMonitorInfo(MonitorFromWindow(appbar.hWnd,MONITOR_DEFAULTTOPRIMARY),&info); - SendMessage(balloon,TTM_TRACKPOSITION,0,0); - SendMessage(balloon,TTM_TRACKACTIVATE,TRUE,(LPARAM)&tool); - RECT rc; - GetWindowRect(balloon,&rc); - LONG pos; - if (appbar.uEdge==ABE_LEFT) - pos=MAKELONG(info.rcWork.left,info.rcWork.bottom-rc.bottom+rc.top); - else if (appbar.uEdge==ABE_RIGHT) - pos=MAKELONG(info.rcWork.right-rc.right+rc.left,info.rcWork.bottom-rc.bottom+rc.top); - else if (appbar.uEdge==ABE_TOP) - pos=MAKELONG(IsLanguageRTL()?info.rcWork.left:info.rcWork.right-rc.right+rc.left,info.rcWork.top); - else - pos=MAKELONG(IsLanguageRTL()?info.rcWork.left:info.rcWork.right-rc.right+rc.left,info.rcWork.bottom-rc.bottom+rc.top); - SendMessage(balloon,TTM_TRACKPOSITION,0,pos); - SetWindowSubclass(balloon,SubclassBalloonProc,0,'CLSH'); - PlaySound(L"SystemNotification",NULL,SND_APPLICATION|SND_ALIAS|SND_ASYNC|SND_NODEFAULT|SND_SYSTEM); - int time0=timeGetTime(); - while (IsWindowVisible(balloon)) + + auto title = LoadStringEx(IDS_UPDATE_TITLE); + auto message = LoadStringEx(g_UpdateDlg.HasNewLanguage() ? IDS_LANG_NEWVERSION : IDS_NEWVERSION); + + if (toasts) { - if (time0 && (timeGetTime()-time0)>=15000) - { - time0=0; - TOOLINFO tool={sizeof(tool)}; - tool.uId=1; - SendMessage(balloon,TTM_TRACKACTIVATE,FALSE,(LPARAM)&tool); - } - MSG msg; - while (PeekMessage(&msg,0,0,0,PM_REMOVE)) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - Sleep(10); + toasts.DisplaySimpleToast(title, message); } + else + { + HWND balloon = CreateWindowEx(WS_EX_TOPMOST | WS_EX_TOOLWINDOW | (IsLanguageRTL() ? WS_EX_LAYOUTRTL : 0), TOOLTIPS_CLASS, NULL, WS_POPUP | TTS_CLOSE | TTS_NOPREFIX, 0, 0, 0, 0, NULL, NULL, g_Instance, NULL); + SendMessage(balloon, TTM_SETMAXTIPWIDTH, 0, 500); + TOOLINFO tool = { sizeof(tool),TTF_ABSOLUTE | TTF_TRANSPARENT | TTF_TRACK | (IsLanguageRTL() ? TTF_RTLREADING : 0U) }; + tool.uId = 1; + tool.lpszText = (wchar_t*)(const wchar_t*)message; + SendMessage(balloon, TTM_ADDTOOL, 0, (LPARAM)&tool); + SendMessage(balloon, TTM_SETTITLE, (WPARAM)LoadIcon(g_Instance, MAKEINTRESOURCE(IDI_APPICON)), (LPARAM)(const wchar_t*)title); + APPBARDATA appbar = { sizeof(appbar) }; + SHAppBarMessage(ABM_GETTASKBARPOS, &appbar); + MONITORINFO info = { sizeof(info) }; + GetMonitorInfo(MonitorFromWindow(appbar.hWnd, MONITOR_DEFAULTTOPRIMARY), &info); + SendMessage(balloon, TTM_TRACKPOSITION, 0, 0); + SendMessage(balloon, TTM_TRACKACTIVATE, TRUE, (LPARAM)&tool); + RECT rc; + GetWindowRect(balloon, &rc); + LONG pos; + if (appbar.uEdge == ABE_LEFT) + pos = MAKELONG(info.rcWork.left, info.rcWork.bottom - rc.bottom + rc.top); + else if (appbar.uEdge == ABE_RIGHT) + pos = MAKELONG(info.rcWork.right - rc.right + rc.left, info.rcWork.bottom - rc.bottom + rc.top); + else if (appbar.uEdge == ABE_TOP) + pos = MAKELONG(IsLanguageRTL() ? info.rcWork.left : info.rcWork.right - rc.right + rc.left, info.rcWork.top); + else + pos = MAKELONG(IsLanguageRTL() ? info.rcWork.left : info.rcWork.right - rc.right + rc.left, info.rcWork.bottom - rc.bottom + rc.top); + SendMessage(balloon, TTM_TRACKPOSITION, 0, pos); + SetWindowSubclass(balloon, SubclassBalloonProc, 0, 'CLSH'); + PlaySound(L"SystemNotification", NULL, SND_APPLICATION | SND_ALIAS | SND_ASYNC | SND_NODEFAULT | SND_SYSTEM); + int time0 = timeGetTime(); + while (IsWindowVisible(balloon)) + { + if (time0 && (timeGetTime() - time0) >= 15000) + { + time0 = 0; + TOOLINFO tool = { sizeof(tool) }; + tool.uId = 1; + SendMessage(balloon, TTM_TRACKACTIVATE, FALSE, (LPARAM)&tool); + } + MSG msg; + while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + Sleep(10); + } + } + } + else if (wcsstr(lpstrCmdLine, L"-ToastActivated")) + { + g_UpdateDlg.UpdateData(); + g_UpdateDlg.Run(); } else {