diff options
-rw-r--r-- | backends/platform/sdl/win32/win32.cpp | 2 | ||||
-rw-r--r-- | backends/updates/win32/win32-updates.cpp | 29 | ||||
-rw-r--r-- | backends/updates/win32/win32-updates.h | 8 |
3 files changed, 34 insertions, 5 deletions
diff --git a/backends/platform/sdl/win32/win32.cpp b/backends/platform/sdl/win32/win32.cpp index 5f35d46d39..e7dc2af019 100644 --- a/backends/platform/sdl/win32/win32.cpp +++ b/backends/platform/sdl/win32/win32.cpp @@ -117,7 +117,7 @@ void OSystem_Win32::initBackend() { #if defined(USE_SPARKLE) // Initialize updates manager - _updateManager = new Win32UpdateManager(); + _updateManager = new Win32UpdateManager((SdlWindow_Win32*)_window); #endif // Initialize text to speech diff --git a/backends/updates/win32/win32-updates.cpp b/backends/updates/win32/win32-updates.cpp index aebeab531b..868f5d886b 100644 --- a/backends/updates/win32/win32-updates.cpp +++ b/backends/updates/win32/win32-updates.cpp @@ -27,10 +27,12 @@ #include "backends/updates/win32/win32-updates.h" #ifdef USE_SPARKLE +#include "backends/platform/sdl/win32/win32-window.h" #include "common/translation.h" #include "common/config-manager.h" #include <time.h> +#include <windows.h> #include <winsparkle.h> /** @@ -50,10 +52,15 @@ * https://winsparkle.org/ * */ -Win32UpdateManager::Win32UpdateManager() { - const char *appcastUrl = "https://www.scummvm.org/appcasts/macosx/release.xml"; - win_sparkle_set_appcast_url(appcastUrl); +static SdlWindow_Win32 *_window; + +Win32UpdateManager::Win32UpdateManager(SdlWindow_Win32 *window) { + _window = window; + const char *appcastUrl = "https://www.scummvm.org/appcasts/macosx/release.xml"; + win_sparkle_set_appcast_url(appcastUrl); + win_sparkle_set_can_shutdown_callback(canShutdownCallback); + win_sparkle_set_shutdown_request_callback(shutdownRequestCallback); win_sparkle_init(); if (!ConfMan.hasKey("updates_check") @@ -129,4 +136,20 @@ bool Win32UpdateManager::getLastUpdateCheckTimeAndDate(TimeDate &t) { return true; } +// WinSparkle calls this to ask if we can shut down. +// At this point the download has completed, the user has +// selected Install Update, and the installer has started. +// This callback runs on a non-main thread. +int Win32UpdateManager::canShutdownCallback() { + return true; +} + +// WinSparkle calls this to request that we shut down. +// This callback runs on a non-main thread so we post +// a WM_CLOSE message to our window so that we exit +// cleanly, as opposed to calling g_system->quit(). +void Win32UpdateManager::shutdownRequestCallback() { + PostMessage(_window->getHwnd(), WM_CLOSE, 0, 0); +} + #endif diff --git a/backends/updates/win32/win32-updates.h b/backends/updates/win32/win32-updates.h index 71ed9ef685..afa2ef99ef 100644 --- a/backends/updates/win32/win32-updates.h +++ b/backends/updates/win32/win32-updates.h @@ -29,9 +29,11 @@ #include "common/updates.h" +class SdlWindow_Win32; + class Win32UpdateManager : public Common::UpdateManager { public: - Win32UpdateManager(); + Win32UpdateManager(SdlWindow_Win32 *window); virtual ~Win32UpdateManager(); virtual void checkForUpdates(); @@ -43,6 +45,10 @@ public: virtual int getUpdateCheckInterval(); virtual bool getLastUpdateCheckTimeAndDate(TimeDate &t); + +private: + static int canShutdownCallback(); + static void shutdownRequestCallback(); }; #endif |