Skip to content

Commit

Permalink
Add update closed event
Browse files Browse the repository at this point in the history
  • Loading branch information
BrunoBibboVoicemod committed May 10, 2024
1 parent abc7f80 commit 3a1a23a
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 1 deletion.
17 changes: 17 additions & 0 deletions include/winsparkle.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)();

Expand Down
12 changes: 12 additions & 0 deletions src/appcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -119,6 +120,17 @@ void ApplicationController::NotifyUpdateCancelled()
}
}

void ApplicationController::NotifyUpdateClosed() {
{
CriticalSectionLocker lock(ms_csVars);
if (ms_cbUpdateClosed)
{
(*ms_cbUpdateClosed)();
return;
}
}
}

void ApplicationController::NotifyUpdateSkipped()
{
{
Expand Down
11 changes: 11 additions & 0 deletions src/appcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions src/dll_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}


Expand Down

0 comments on commit 3a1a23a

Please sign in to comment.