From 3a1a23a608c45fa3e29b1c1f113dcd89babeb246 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Bibb=C3=B3?= Date: Fri, 10 May 2024 19:27:48 +0200 Subject: [PATCH 1/2] Add update closed event --- include/winsparkle.h | 17 +++++++++++++++++ src/appcontroller.cpp | 12 ++++++++++++ src/appcontroller.h | 11 +++++++++++ src/dll_api.cpp | 9 +++++++++ src/ui.cpp | 4 +++- 5 files changed, 52 insertions(+), 1 deletion(-) diff --git a/include/winsparkle.h b/include/winsparkle.h index 5a614187..38255e6e 100644 --- a/include/winsparkle.h +++ b/include/winsparkle.h @@ -459,6 +459,23 @@ typedef void (__cdecl *win_sparkle_update_cancelled_callback_t)(); */ WIN_SPARKLE_API void __cdecl win_sparkle_set_update_cancelled_callback(win_sparkle_update_cancelled_callback_t callback); +/// Callback type for win_sparkle_update_closed_callback_t() +typedef void(__cdecl *win_sparkle_update_closed_callback_t)(); + +/** + Set callback to be called when the download dialog is closed + even by the user or at the end of the process. + + This is useful in combination with + win_sparkle_check_update_with_ui_and_install() as it allows you to perform + some action when the update download process end (by user action or installation starts). + + @since 8.2 + + @see win_sparkle_check_update_with_ui_and_install() +*/ +WIN_SPARKLE_API void __cdecl win_sparkle_set_update_closed_callback(win_sparkle_update_closed_callback_t callback); + /// Callback type for win_sparkle_update_skipped_callback() typedef void(__cdecl* win_sparkle_update_skipped_callback_t)(); diff --git a/src/appcontroller.cpp b/src/appcontroller.cpp index bf0a68d7..e381ea73 100644 --- a/src/appcontroller.cpp +++ b/src/appcontroller.cpp @@ -37,6 +37,7 @@ win_sparkle_shutdown_request_callback_t ApplicationController::ms_cbRequestSh win_sparkle_did_find_update_callback_t ApplicationController::ms_cbDidFindUpdate = NULL; win_sparkle_did_not_find_update_callback_t ApplicationController::ms_cbDidNotFindUpdate = NULL; win_sparkle_update_cancelled_callback_t ApplicationController::ms_cbUpdateCancelled = NULL; +win_sparkle_update_closed_callback_t ApplicationController::ms_cbUpdateClosed = NULL; win_sparkle_update_skipped_callback_t ApplicationController::ms_cbUpdateSkipped = NULL; win_sparkle_update_postponed_callback_t ApplicationController::ms_cbUpdatePostponed = NULL; win_sparkle_update_dismissed_callback_t ApplicationController::ms_cbUpdateDismissed = NULL; @@ -119,6 +120,17 @@ void ApplicationController::NotifyUpdateCancelled() } } +void ApplicationController::NotifyUpdateClosed() { + { + CriticalSectionLocker lock(ms_csVars); + if (ms_cbUpdateClosed) + { + (*ms_cbUpdateClosed)(); + return; + } + } +} + void ApplicationController::NotifyUpdateSkipped() { { diff --git a/src/appcontroller.h b/src/appcontroller.h index d54bf569..0cf2ede6 100644 --- a/src/appcontroller.h +++ b/src/appcontroller.h @@ -69,6 +69,9 @@ class ApplicationController /// Notify that an update was cancelled. static void NotifyUpdateCancelled(); + /// Notify that an update was close. + static void NotifyUpdateClosed(); + /// Notify that an update was skipped static void NotifyUpdateSkipped(); @@ -130,6 +133,13 @@ class ApplicationController ms_cbUpdateCancelled = callback; } + /// Set the win_sparkle_update_closed_callback_t function + static void SetUpdateClosedCallback(win_sparkle_update_closed_callback_t callback) + { + CriticalSectionLocker lock(ms_csVars); + ms_cbUpdateClosed = callback; + } + /// Set the win_sparkle_update_skipped_callback_t function static void SetUpdateSkippedCallback(win_sparkle_update_skipped_callback_t callback) { @@ -171,6 +181,7 @@ class ApplicationController static win_sparkle_did_find_update_callback_t ms_cbDidFindUpdate; static win_sparkle_did_not_find_update_callback_t ms_cbDidNotFindUpdate; static win_sparkle_update_cancelled_callback_t ms_cbUpdateCancelled; + static win_sparkle_update_closed_callback_t ms_cbUpdateClosed; static win_sparkle_update_skipped_callback_t ms_cbUpdateSkipped; static win_sparkle_update_postponed_callback_t ms_cbUpdatePostponed; static win_sparkle_update_dismissed_callback_t ms_cbUpdateDismissed; diff --git a/src/dll_api.cpp b/src/dll_api.cpp index 65560e71..4d50d35d 100644 --- a/src/dll_api.cpp +++ b/src/dll_api.cpp @@ -342,6 +342,15 @@ WIN_SPARKLE_API void __cdecl win_sparkle_set_update_cancelled_callback(win_spark CATCH_ALL_EXCEPTIONS } +WIN_SPARKLE_API void __cdecl win_sparkle_set_update_closed_callback(win_sparkle_update_closed_callback_t callback) +{ + try + { + ApplicationController::SetUpdateClosedCallback(callback); + } + CATCH_ALL_EXCEPTIONS +} + WIN_SPARKLE_API void __cdecl win_sparkle_set_update_skipped_callback(win_sparkle_update_skipped_callback_t callback) { try diff --git a/src/ui.cpp b/src/ui.cpp index d4b44f8f..0507d6dc 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -618,8 +618,10 @@ void UpdateDialog::OnClose(wxCloseEvent&) // If the update was not downloaded and the appcast is empty and we're closing, // it means that we're about to restart or there was an error, and that the // window-close event wasn't initiated by the user. - if ( m_appcast.IsValid() && m_updateFile.IsEmpty() && !m_errorOccurred ) + if (m_appcast.IsValid() && m_updateFile.IsEmpty() && !m_errorOccurred) ApplicationController::NotifyUpdateCancelled(); + + ApplicationController::NotifyUpdateClosed(); } From 3e97e308d399af2e0c368229b9460c4c3ad5b5c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Bibb=C3=B3?= Date: Fri, 10 May 2024 19:31:05 +0200 Subject: [PATCH 2/2] Leaving whitespaces in if condition --- src/ui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui.cpp b/src/ui.cpp index 0507d6dc..2c73947e 100644 --- a/src/ui.cpp +++ b/src/ui.cpp @@ -618,7 +618,7 @@ void UpdateDialog::OnClose(wxCloseEvent&) // If the update was not downloaded and the appcast is empty and we're closing, // it means that we're about to restart or there was an error, and that the // window-close event wasn't initiated by the user. - if (m_appcast.IsValid() && m_updateFile.IsEmpty() && !m_errorOccurred) + if ( m_appcast.IsValid() && m_updateFile.IsEmpty() && !m_errorOccurred ) ApplicationController::NotifyUpdateCancelled(); ApplicationController::NotifyUpdateClosed();