Skip to content

Commit

Permalink
Add limited support for <sparkle:criticalUpdate> (#244)
Browse files Browse the repository at this point in the history
Parse <sparkle:criticalUpdate> and don't allow skipping updates if
present. The code recognizes <sparkle:criticalUpdate/> both inside
<sparkle:tags> (Sparkle 1 way) and in <item> scope (Sparkle 2).

This does not parse the specific version string embedded in the
criticalUpdate tag.

The UI prevents the user from skipping the update or choosing to be
reminded later, but isn't outright user hostile and doesn't prevent them
from closing the window. That's because we don't know the circumstance -
the user may e.g. be doing something urgent at the moment.

Co-authored-by: Edwin Clement <[email protected]>
  • Loading branch information
vslavik and edwinclement08 committed Jun 9, 2022
1 parent b246977 commit 7ca9b99
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
6 changes: 6 additions & 0 deletions src/appcast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ namespace
#define NODE_LINK "link"
#define NODE_ENCLOSURE "enclosure"
#define NODE_MIN_OS_VERSION NS_SPARKLE_NAME("minimumSystemVersion")
#define NODE_CRITICAL_UPDATE NS_SPARKLE_NAME("criticalUpdate")
#define ATTR_URL "url"
#define ATTR_VERSION NS_SPARKLE_NAME("version")
#define ATTR_SHORTVERSION NS_SPARKLE_NAME("shortVersionString")
Expand Down Expand Up @@ -180,6 +181,11 @@ void XMLCALL OnStartElement(void *data, const char *name, const char **attrs)
ctxt.items[size-1].InstallerArguments = value;
}
}
else if (strcmp(name, NODE_CRITICAL_UPDATE) == 0)
{
if (!ctxt.items.empty())
ctxt.items.back().CriticalUpdate = true;
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/appcast.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ struct Appcast
// Arguments passed on the the updater executable
std::string InstallerArguments;

// CriticalUpdate?
bool CriticalUpdate = false;


/**
Initializes the struct with data from XML appcast feed.
Expand Down
34 changes: 19 additions & 15 deletions src/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,8 @@ class UpdateDialog : public WinSparkleDialog
wxStaticText *m_message;
wxGauge *m_progress;
wxStaticText *m_progressLabel;
wxButton *m_skipVersionButton;
wxButton *m_remindLaterButton;
wxButton *m_closeButton;
wxSizer *m_closeButtonSizer;
wxButton *m_runInstallerButton;
Expand Down Expand Up @@ -533,23 +535,15 @@ UpdateDialog::UpdateDialog()

m_buttonSizer = new wxBoxSizer(wxHORIZONTAL);

m_skipVersionButton = new wxButton(this, ID_SKIP_VERSION, _("Skip this version"));
m_remindLaterButton = new wxButton(this, ID_REMIND_LATER, _("Remind me later"));
m_installButton = new wxButton(this, ID_INSTALL, _("Install update"));

m_updateButtonsSizer = new wxBoxSizer(wxHORIZONTAL);
m_updateButtonsSizer->Add
(
new wxButton(this, ID_SKIP_VERSION, _("Skip this version")),
wxSizerFlags().Border(wxRIGHT, PX(20))
);
m_updateButtonsSizer->Add(m_skipVersionButton, wxSizerFlags().Border(wxRIGHT, PX(20)));
m_updateButtonsSizer->AddStretchSpacer(1);
m_updateButtonsSizer->Add
(
new wxButton(this, ID_REMIND_LATER, _("Remind me later")),
wxSizerFlags().Border(wxRIGHT, PX(10))
);
m_updateButtonsSizer->Add
(
m_installButton = new wxButton(this, ID_INSTALL, _("Install update")),
wxSizerFlags()
);
m_updateButtonsSizer->Add(m_remindLaterButton, wxSizerFlags().Border(wxRIGHT, PX(10)));
m_updateButtonsSizer->Add(m_installButton, wxSizerFlags());
m_buttonSizer->Add(m_updateButtonsSizer, wxSizerFlags(1));

m_closeButtonSizer = new wxBoxSizer(wxHORIZONTAL);
Expand Down Expand Up @@ -895,6 +889,16 @@ void UpdateDialog::StateUpdateAvailable(const Appcast& info, bool installAutomat
HIDE(m_closeButtonSizer);
HIDE(m_runInstallerButtonSizer);
SHOW(m_updateButtonsSizer);
if (info.CriticalUpdate)
{
HIDE(m_skipVersionButton);
HIDE(m_remindLaterButton);
}
else
{
SHOW(m_skipVersionButton);
SHOW(m_remindLaterButton);
}
DoShowElement(m_releaseNotesSizer, showRelnotes);
MakeResizable(showRelnotes);
}
Expand Down

0 comments on commit 7ca9b99

Please sign in to comment.