Skip to content

Commit f7467ee

Browse files
committed
Call cancelled/dismissed callbacks when user closes window
Make sure that the callback function set with win_sparkle_set_update_cancelled_callback() is called even when the user just closes the window without clicking any button. Previously, this wouldn't be done. Do the same for the similar win_sparkle_set_update_dismissed_callback(). Document the difference between the two more clearly. Fixes #127, fixes #271.
1 parent 84bcac5 commit f7467ee

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

include/winsparkle.h

+8-4
Original file line numberDiff line numberDiff line change
@@ -447,15 +447,17 @@ WIN_SPARKLE_API void __cdecl win_sparkle_set_did_not_find_update_callback(win_sp
447447
typedef void (__cdecl *win_sparkle_update_cancelled_callback_t)();
448448

449449
/**
450-
Set callback to be called when the user cancels a download.
450+
Set callback to be called when the user cancels an update, e.g.
451+
by closing the window, skipping an update or cancelling download.
452+
This callback is not called when there's no update to install or an error occurs.
451453
452454
This is useful in combination with
453455
win_sparkle_check_update_with_ui_and_install() as it allows you to perform
454456
some action when the installation is interrupted.
455457
456458
@since 0.5
457459
458-
@see win_sparkle_check_update_with_ui_and_install()
460+
@see win_sparkle_check_update_with_ui_and_install(), win_sparkle_set_update_dismissed_callback()
459461
*/
460462
WIN_SPARKLE_API void __cdecl win_sparkle_set_update_cancelled_callback(win_sparkle_update_cancelled_callback_t callback);
461463

@@ -499,14 +501,16 @@ typedef void(__cdecl* win_sparkle_update_dismissed_callback_t)();
499501

500502
/**
501503
Set callback to be called when the user dismisses
502-
(closes) update dialog.
504+
(closes) update dialog, including when there were no updates or an error occured.
505+
See win_sparkle_set_update_cancelled_callback() for a subtly different callback
506+
that may be more appropriate.
503507
504508
This is useful in combination with
505509
win_sparkle_check_update_with_ui() or similar as it
506510
allows you to perform some action when the update
507511
dialog is closed.
508512
509-
@see win_sparkle_check_update_with_ui()
513+
@see win_sparkle_check_update_with_ui(), win_sparkle_set_update_cancelled_callback()
510514
511515
@since 0.8
512516
*/

src/ui.cpp

+18-6
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,8 @@ class UpdateDialog : public WinSparkleDialog
480480
bool m_installAutomatically;
481481
// whether an error occurred (used to properly call NotifyUpdateCancelled)
482482
bool m_errorOccurred;
483+
// whether window closure was updater-initiated (i.e. not caused by user)
484+
bool m_closeInitiatedByUpdater;
483485

484486
static const int RELNOTES_WIDTH = 460;
485487
static const int RELNOTES_HEIGHT = 200;
@@ -492,6 +494,7 @@ UpdateDialog::UpdateDialog()
492494
{
493495
m_installAutomatically = false;
494496
m_errorOccurred = false;
497+
m_closeInitiatedByUpdater = false;
495498

496499
m_heading = new wxStaticText(this, wxID_ANY, "");
497500
SetHeadingFont(m_heading);
@@ -594,7 +597,7 @@ void UpdateDialog::OnTimer(wxTimerEvent&)
594597

595598
void UpdateDialog::OnCloseButton(wxCommandEvent&)
596599
{
597-
ApplicationController::NotifyUpdateDismissed();
600+
m_closeInitiatedByUpdater = false;
598601
Close();
599602
}
600603

@@ -615,18 +618,23 @@ void UpdateDialog::OnClose(wxCloseEvent&)
615618
// destroy itself in Close().
616619
Destroy();
617620

618-
// If the update was not downloaded and the appcast is empty and we're closing,
619-
// it means that we're about to restart or there was an error, and that the
620-
// window-close event wasn't initiated by the user.
621-
if ( m_appcast.IsValid() && m_updateFile.IsEmpty() && !m_errorOccurred )
622-
ApplicationController::NotifyUpdateCancelled();
621+
// Notify about window being dismissed or update cancelled. We must not notify
622+
// if window closure was initiated by WinSparkle itself e.g. to run the installer.
623+
if (!m_closeInitiatedByUpdater)
624+
{
625+
if (!m_errorOccurred && m_appcast.IsValid())
626+
ApplicationController::NotifyUpdateCancelled();
627+
628+
ApplicationController::NotifyUpdateDismissed();
629+
}
623630
}
624631

625632

626633
void UpdateDialog::OnSkipVersion(wxCommandEvent&)
627634
{
628635
Settings::WriteConfigValue("SkipThisVersion", m_appcast.Version);
629636
ApplicationController::NotifyUpdateSkipped();
637+
m_closeInitiatedByUpdater = false; // skipping is cancellation
630638
Close();
631639
}
632640

@@ -636,6 +644,7 @@ void UpdateDialog::OnRemindLater(wxCommandEvent&)
636644
// Just abort the update. Next time it's scheduled to run,
637645
// the user will be prompted.
638646
ApplicationController::NotifyUpdatePostponed();
647+
m_closeInitiatedByUpdater = false; // skipping is cancellation
639648
Close();
640649
}
641650

@@ -645,6 +654,7 @@ void UpdateDialog::OnInstall(wxCommandEvent&)
645654
if ( !m_appcast.HasDownload() )
646655
{
647656
wxLaunchDefaultBrowser(m_appcast.WebBrowserURL, wxBROWSER_NEW_WINDOW);
657+
m_closeInitiatedByUpdater = true;
648658
Close();
649659
}
650660
else if ( m_downloader == NULL )
@@ -685,6 +695,7 @@ void UpdateDialog::OnRunInstaller(wxCommandEvent&)
685695
}
686696
else
687697
{
698+
m_closeInitiatedByUpdater = true;
688699
Close();
689700
ApplicationController::RequestShutdown();
690701
}
@@ -757,6 +768,7 @@ void UpdateDialog::StateNoUpdateFound(bool installAutomatically)
757768

758769
if ( m_installAutomatically )
759770
{
771+
m_closeInitiatedByUpdater = true;
760772
Close();
761773
return;
762774
}

0 commit comments

Comments
 (0)