Skip to content

Commit

Permalink
app_updates for winsparkle
Browse files Browse the repository at this point in the history
  • Loading branch information
vslavik committed Feb 27, 2024
1 parent 6fc5d8f commit 5971a23
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 50 deletions.
2 changes: 2 additions & 0 deletions Poedit.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
</ResourceCompile>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="src\app_updates.cpp" />
<ClCompile Include="src\attentionbar.cpp" />
<ClCompile Include="src\catalog.cpp" />
<ClCompile Include="src\catalog_json.cpp" />
Expand Down Expand Up @@ -177,6 +178,7 @@
<ClCompile Include="src\wx\main_toolbar.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\app_updates.h" />
<ClInclude Include="src\attentionbar.h" />
<ClInclude Include="src\catalog.h" />
<ClInclude Include="src\catalog_json.h" />
Expand Down
6 changes: 6 additions & 0 deletions Poedit.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@
<ClCompile Include="src\catalog_json.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\app_updates.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\attentionbar.h">
Expand Down Expand Up @@ -416,6 +419,9 @@
<ClInclude Include="src\catalog_json.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\app_updates.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="src\poedit.rc">
Expand Down
96 changes: 95 additions & 1 deletion src/app_updates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,21 @@

#ifdef HAS_UPDATES_CHECK

#ifdef __WXOSX__
#include "edapp.h"
#include "edframe.h"

#include <wx/menu.h>

#ifdef __WXOSX__
#import <Sparkle/Sparkle.h>
#endif

#ifdef __WXMSW__
#include <winsparkle.h>
#endif


#ifdef __WXOSX__

@interface PoeditSparkleDelegate : NSObject <SUUpdaterDelegate>
@end
Expand Down Expand Up @@ -129,6 +138,79 @@ class AppUpdates::impl
#endif // __WXOSX__


#ifdef __WXMSW__

class AppUpdates::impl
{
public:
impl() {}

~impl()
{
win_sparkle_cleanup();
}

void Initialize()
{
if (Config::CheckForBetaUpdates())
win_sparkle_set_appcast_url("https://poedit.net/updates_v2/win/appcast/beta");
else
win_sparkle_set_appcast_url("https://poedit.net/updates_v2/win/appcast");

win_sparkle_set_can_shutdown_callback(&impl::WinSparkle_CanShutdown);
win_sparkle_set_shutdown_request_callback(&impl::WinSparkle_Shutdown);
auto buildnum = wxGetApp().GetAppBuildNumber();
if (!buildnum.empty())
win_sparkle_set_app_build_version(buildnum.wc_str());
win_sparkle_init();
}

void SetLanguage(const std::string& lang)
{
win_sparkle_set_lang(lang.c_str());
}

void CheckForUpdatesWithUI()
{
win_sparkle_check_update_with_ui();
}

void EnableAutomaticChecks(bool enable)
{
if (enable)
SetupAppcastURL();
win_sparkle_set_automatic_check_for_updates(enable);
}

bool AutomaticChecksEnabled() const
{
return win_sparkle_get_automatic_check_for_updates();
}

private:
void SetupAppcastURL()
{
if (Config::CheckForBetaUpdates())
win_sparkle_set_appcast_url("https://poedit.net/updates_v2/win/appcast/beta");
else
win_sparkle_set_appcast_url("https://poedit.net/updates_v2/win/appcast");
}

// WinSparkle callbacks:
static int WinSparkle_CanShutdown()
{
return !PoeditFrame::AnyWindowIsModified();
}

static void WinSparkle_Shutdown()
{
wxCommandEvent evt(wxEVT_COMMAND_MENU_SELECTED, wxID_EXIT);
wxGetApp().AddPendingEvent(evt);
}
};

#endif // __WXMSW__


// Boilerplate:

Expand Down Expand Up @@ -173,6 +255,18 @@ bool AppUpdates::AutomaticChecksEnabled() const
return m_impl->AutomaticChecksEnabled();
}

#ifdef __WXMSW__
void AppUpdates::SetLanguage(const std::string& lang)
{
m_impl->SetLanguage(lang);
}

void AppUpdates::CheckForUpdatesWithUI()
{
m_impl->CheckForUpdatesWithUI();
}
#endif // __WXMSW__

#ifdef __WXOSX__
void AppUpdates::AddMenuItem(wxMenu *appleMenu)
{
Expand Down
5 changes: 5 additions & 0 deletions src/app_updates.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ class AppUpdates
void EnableAutomaticChecks(bool enable);
bool AutomaticChecksEnabled() const;

#ifdef __WXMSW__
void SetLanguage(const std::string& lang);
void CheckForUpdatesWithUI();
#endif

#ifdef __WXOSX__
void AddMenuItem(wxMenu *appleMenu);
#endif
Expand Down
34 changes: 2 additions & 32 deletions src/edapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
#ifdef __WXMSW__
#include <wx/msw/wrapwin.h>
#include <Shlwapi.h>
#include <winsparkle.h>
#endif

#ifdef __WXGTK__
Expand Down Expand Up @@ -465,20 +464,6 @@ bool PoeditApp::OnInit()

AppUpdates::Get().Initialize();

#ifdef __WXMSW__
if (CheckForBetaUpdates())
win_sparkle_set_appcast_url("https://poedit.net/updates_v2/win/appcast/beta");
else
win_sparkle_set_appcast_url("https://poedit.net/updates_v2/win/appcast");

win_sparkle_set_can_shutdown_callback(&PoeditApp::WinSparkle_CanShutdown);
win_sparkle_set_shutdown_request_callback(&PoeditApp::WinSparkle_Shutdown);
auto buildnum = GetAppBuildNumber();
if (!buildnum.empty())
win_sparkle_set_app_build_version(buildnum.wc_str());
win_sparkle_init();
#endif

#ifndef __WXOSX__
// NB: opening files or creating empty window is handled differently on
// Macs, using MacOpenFiles() and MacNewFile(), so don't create empty
Expand Down Expand Up @@ -549,10 +534,6 @@ int PoeditApp::OnExit()

dispatch::cleanup();

#ifdef __WXMSW__
win_sparkle_cleanup();
#endif

u_cleanup();

return wxApp::OnExit();
Expand Down Expand Up @@ -635,7 +616,7 @@ void PoeditApp::SetupLanguage()
g_layoutDirection = info ? info->LayoutDirection : wxLayout_Default;

#ifdef __WXMSW__
win_sparkle_set_lang(bestTrans.utf8_str());
AppUpdates::Get().SetLanguage(bestTrans.utf8_string());
#endif

#ifdef SUPPORTS_OTA_UPDATES
Expand Down Expand Up @@ -1395,18 +1376,7 @@ void PoeditApp::OnCloseWindowCommand(wxCommandEvent&)

void PoeditApp::OnWinsparkleCheck(wxCommandEvent& event)
{
win_sparkle_check_update_with_ui();
}

// WinSparkle callbacks:
int PoeditApp::WinSparkle_CanShutdown()
{
return !PoeditFrame::AnyWindowIsModified();
}

void PoeditApp::WinSparkle_Shutdown()
{
wxGetApp().OnQuit(wxCommandEvent());
AppUpdates::Get().CheckForUpdatesWithUI();
}

#endif // __WXMSW__
Expand Down
2 changes: 0 additions & 2 deletions src/edapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ class PoeditApp : public wxApp, public MenusManager

#ifdef __WXMSW__
void OnWinsparkleCheck(wxCommandEvent& event);
static int WinSparkle_CanShutdown();
static void WinSparkle_Shutdown();
#endif

DECLARE_EVENT_TABLE()
Expand Down
15 changes: 0 additions & 15 deletions src/prefsdlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@
#include "customcontrols.h"
#include "unicode_helpers.h"

#ifdef __WXMSW__
#include <winsparkle.h>
#endif

// Handling of different page icons
#ifdef __WXOSX__
Expand Down Expand Up @@ -1113,25 +1110,13 @@ class UpdatesPageWindow : public PrefsPanel
{
m_updates->SetValue(AppUpdates::Get().AutomaticChecksEnabled());
m_beta->SetValue(Config::CheckForBetaUpdates());

#ifdef __WXMSW__
m_updates->SetValue(win_sparkle_get_automatic_check_for_updates() != 0);
#endif
}

void SaveValues(wxConfigBase&) override
{
// NB: Must be done first, before calling AppUpdates methods!
Config::CheckForBetaUpdates(m_beta->GetValue());

#ifdef __WXMSW__
win_sparkle_set_automatic_check_for_updates(m_updates->GetValue());
// FIXME: don't duplicate this code from PoeditApp::OnInit()
if (m_beta->GetValue())
win_sparkle_set_appcast_url("https://poedit.net/updates_v2/win/appcast/beta");
else
win_sparkle_set_appcast_url("https://poedit.net/updates_v2/win/appcast");
#endif
AppUpdates::Get().EnableAutomaticChecks(m_beta->GetValue());
}

Expand Down

0 comments on commit 5971a23

Please sign in to comment.